
Land Of Lisp chapter 7 - Using SBCL - ciaranbradley
http://blog.ciaranbradley.com/land-of-lisp-chapter-7-using-sbcl
======
gibsonf1
Here's a function to create svg (default) or jpg for both sbcl and lispworks
from graphviz:

(defun make-svg (file-name &key jpg)

    
    
        #+lispworks (sys:call-system-showing-output
                     (string+ cl-user::*organontech-graphviz* (if jpg " -Tjpg " " -Tsvg ")
                              cl-user::*fcgaa-lean-mapping-path*
                              "/" file-name ".dot"
                              " -o "
                              cl-user::*fcgaa-lean-mapping-path*
                              "/" file-name (if jpg ".jpg" ".svg")))
        #+sbcl (sb-ext:run-program cl-user::*organontech-graphviz*
                                     (list (if jpg "-Tjpg" "-Tsvg")
                                           (string+ cl-user::*fcgaa-lean-mapping-path* "/" file-name ".dot")
                                           "-o"
                                           (string+ cl-user::*fcgaa-lean-mapping-path* "/" file-name (if jpg ".jpg" ".svg")))
                                     :output (weblog-stream)
                                     )
        )
    

(defun weblog-stream ()

    
    
      (or (net.aserve:vhost-log-stream (net.aserve:wserver-default-vhost net.aserve:*wserver*))
          t)) ;;sends output directly to html stream on portable allegroserve
    

(defmacro string+ (string &rest strings) `(concatenate 'string ,string
,@strings))

------
ciaranbradley
I bought the book the other day after it was posted here:
<http://news.ycombinator.com/item?id=1836935> and have been working through
the chapters. The book contains some CLISP specific code but I'm running SBCL.
So this is my SBCL hack for the first stumbling block I found.

disclaimer: I'm a LISP noob, so this is a beginners hack, but it may help
others (like me) who have had difficulty installing CLISP.

------
mahmud
Instead of using implementation dependent functions, use a library like
trivial-shell, which is also available via QuickLisp. It has the SHELL-COMMAND
function you need.

<http://common-lisp.net/project/trivial-shell/>

~~~
mahmud
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
How about simply this?

    
    
      (defun str (&rest strings)
        (format nil "~{~A~}" strings))

~~~
mahmud
I 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.

------
waterhouse
I use this. This makes the "shell" command work in SBCL, and does nothing in
CLISP or any other implementation.

    
    
      #+sbcl
      (defun shell (x)
        (run-program "/bin/sh" (list "-c" x) :output t))
    

Tell me if you want it to work in an implementation other than CLISP or SBCL,
and if I can install it on my computer, then I'll figure it out.

------
flavoie
A page dedicated to landoflisp on sbcl would great. clisp looks like more
trouble to install on my mac than the sbcl package.

~~~
KC8ZKF
You should look at the Rudix package of Clisp.

<http://rudix.org/packages-abc.html#clisp>

