Skip to content

Instantly share code, notes, and snippets.

@xieyuheng
Created January 22, 2015 03:30
Show Gist options
  • Save xieyuheng/f22e1a53653acf761c9c to your computer and use it in GitHub Desktop.
Save xieyuheng/f22e1a53653acf761c9c to your computer and use it in GitHub Desktop.
a cute CAT ^-^ in common lisp
(defmacro cat
((&key (to nil)
(trim '())
prefix
postfix)
&body form#list-of-list)
(let* ((form#list-of-list#2
(apply (function append)
(mapcar (lambda (list)
(list prefix
(list 'string-trim trim
(append '(format nil) list))
postfix))
form#list-of-list)))
(form#final (append '(concatenate (quote string))
form#list-of-list#2)))
`(let ((string-for-return ,form#final))
(format ,to "~A" string-for-return)
string-for-return)))
(cat (:to *standard-output*
:trim '(#\Space)
:prefix "* "
:postfix (cat () ("~%")))
("~A" " 123 ")
("~A" " 456 "))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment