Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Land of lisp and sbcl
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Robert Taylor  
View profile  
 More options Jun 6 2012, 6:22 pm
From: Robert Taylor <linuxhooli...@gmail.com>
Date: Wed, 6 Jun 2012 15:22:57 -0700
Local: Wed, Jun 6 2012 6:22 pm
Subject: Re: Land of lisp and sbcl
Sweet!

Thank you kindly!

Have not had time to finish it but was hoping to complete the book.
This helps, I want to complete the book via SBCL.

Robert

On Wed, Jun 6, 2012 at 3:21 PM, Harven <har...@free.fr> wrote:
> I just finished reading Land of Lisp, which I enjoyed a lot.
> I used sbcl to run the code, so I had to modify
> a few functions in order to get everything working.
> I want to report these changes, in case somebody is interested in
> using sbcl instead of clisp.

> First make sure that the libraries asdf and usocket are loaded.
> asdf is bundled by default with sbcl, usocket is easily installed
> with quicklisp.

> ch 7:   dot->png
> ch 13:  serve hello-request-handler
> ch 19:  dod-request-handler
> ch 20:  web-handle-human

> chapter 7

> ;; assuming asdf is loaded.
> (defun dot->png (fname thunk)
>   (with-open-file (*standard-output*
>                    fname
>                    :direction :output
>                    :if-exists :supersede)
>     (funcall thunk))
>   (asdf:run-shell-command
>    (format nil "dot -Tpng -O ~A" fname)))

> chapter 13

> ;; assuming usocket is loaded.
> (defun serve (request-handler)
>   (let ((socket (usocket:socket-listen "127.0.0.1" 8080 :reuse-address t)))
>     (unwind-protect
>          (loop (with-open-stream (stream
>                     (usocket:socket-stream (usocket:socket-accept socket)))
>                  (let* ((url (parse-url (read-line stream nil)))
>                         (path (car url))
>                         (header (get-header stream))
>                         (params (append (cdr url)
>                                         (get-content-params stream header)))
>                         (*standard-output* stream))
>                    (funcall request-handler path header params))))
>       (usocket:socket-close socket))))

> (defun hello-request-handler (path header params)
>   (if (equal path "greeting")
>       (let ((name (assoc 'name params)))
>         (format t "HTTP/1.1 200 OK~%~%")
>         (if (not name)
>             (princ "<html><form>What is your name?<input name='name'
> /></form></html>")
>             (format t "<html>Nice to meet you, ~a!</html>" (cdr name))))
>       (princ "Sorry... I don't know that page.")))

> chapter 19

> (defun dod-request-handler (path header params)
>   (format t "HTTP/1.1 200 OK~%~%")
>   (if (equal path "game.html")
>       (progn (princ "<!doctype html>")
>              (tag center ()
>                (princ "Welcome to DICE OF DOOM!")
>                (tag br ())
>                (let ((chosen (assoc 'chosen params)))
>                  (when (or (not *cur-game-tree*) (not chosen))
>                    (setf chosen nil)
>                    (web-initialize))
>                  (cond ((lazy-null (caddr *cur-game-tree*))
>                         (web-announce-winner (cadr *cur-game-tree*)))
>                        ((zerop (car *cur-game-tree*))
>                         (web-handle-human
>                          (when chosen
>                            (read-from-string (cdr chosen)))))
>                        (t (web-handle-computer))))
>                (tag br())
>                (draw-dod-page *cur-game-tree* *from-tile*)))
>       (princ "Sorry... I don't know that page.")))

> chapter 20

> ;; the function web-handle-human must also be modified as follows.
> (defun web-handle-human (pos)
>   (cond ((not pos) (princ "Please choose a hex to move from:"))
>         ((eq pos 'pass) (setf *cur-game-tree*
>                               (cadr (lazy-car (caddr *cur-game-tree*))))
>          (princ "Your reinforcements have been placed.")
>          (tag a (href (make-game-link nil))
>            (princ "continue")))
>         ((not *from-tile*) (setf *from-tile* pos)
>          (princ "Now choose a destination:"))
>         ((eq pos *from-tile*) (setf *from-tile* nil)
>          (princ" Move cancelled."))
>         (t (setf *cur-game-tree*
>              (pick-chance-branch
>                 (cadr *cur-game-tree*)
>                  (lazy-find-if (lambda (move)
>                                  (equal (car move)
>                                         (list *from-tile* pos)))
>                                (caddr *cur-game-tree*))))
>            (setf *from-tile* nil)
>            (princ "You may now ")
>            (tag a (href (make-game-link 'pass))
>              (princ "pass"))
>            (princ " or make another move:"))))

> That's it.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.