3 ms·
Also, you might find this slow little utility for converting a bunch of stuff into strings. It will do the job nicely, and it accepts every Lisp type. (defun
by mahmud 16y ago
Also, you might find this slow little utility for converting a bunch of stuff into strings. It will do the job nicely, and it accepts every Lisp type.
(defun str (&rest strings)
(apply 'concatenate 'string
(loop for x in strings
collecting (format nil "~a" x))))
You can use it like this:
(shell (str "dot -Tpng -O " fname))
You might also find that WITH-OPEN-FILE arguments can get a little unwieldy to type in the repl, specially if you want to overwrite files, so you can use this WITH-TEXT-FILE macro. For binary files you will just need to add (:element-type '(unsigned-byte 8))
(defmacro with-text-file ((stream path) &body body)
`(with-open-file (,stream ,path
:direction :io
:if-exists :supersede
:if-does-not-exist :create)
,@body))
- ScottBurson 16y agoHow about simply this? (defun str (&rest strings) (format nil "~{~A~}" strings))
- mahmud 16y agoI consciously avoided that because FORMAT and LOOP mastery is something that should wait until one knows Lisp well. Introduced too early, they can either scare someone (in the case of format) or tempt one to start writing Pascal (in the case of loop; which is why deliberately used it for its collected result, and not its side-effect, as more common.) FWIW, my first Lisp programs where board-games and I learned quite a bit about recursion trying to format ASCII art in curses. If I knew FORMAT had control, I wouldn't have learned much lisp so quickly, since quirky little DSLs are fascinating.
- gibsonf1 16y agoI use: (defmacro str (string &rest strings) `(concatenate 'string ,string ,@strings))