svg function

154 views
Skip to first unread message

michael

unread,
Jan 1, 2015, 6:40:12 AM1/1/15
to land-o...@googlegroups.com
Hi Land of Lispers

I'm having trouble with the SVG function at the bottom of p. 363.

This is my code and this is what the compiler spits out:

I'm running SBCL in SLIME and I did see a post in here earlier about tweaking some functions for SBCL, and I made sure ASDF was loaded, but seeing as how the compiler is talking about code being unreachable and syntax being wack, I thought it was probably not that.

Thanks for your help



;; in .lisp:

187  (with-open-file (*standard-output* "random_walk.svg"
188				   :direction :output
189				   :if-exists :supersede)
190  (svg 400 200
191    (loop repeat 10
192       do (polygon (append '((0 . 200))
193			  (loop for x
194			      for y in (random-walk 100 400)
195			     collect (cons x y))
196			  '((400 . 200)))
197	 (loop repeat 3
198	      collect (random 256))))))


;; repl output:


3 compiler notes:

dsl.lisp:192:11:
  note: deleting unreachable code

dsl.lisp:192:20:
  note: The second argument never returns a value.

dsl.lisp:193:28:
  error: 
    during macroexpansion of (LOOP FOR X ...). Use *BREAK-ON-SIGNALS* to intercept.
    
     FOR is an unknown keyword in FOR or AS clause in LOOP.
    current LOOP context: FOR X FOR Y IN.

dsl.lisp:196:28:
  note: deleting unreachable code

dsl.lisp:198:23:
  note: deleting unreachable code

Compilation failed.


Pasted here: http://paste.lisp.org/display/145028

Thank you and Happy New Year!

michael

unread,
Jan 1, 2015, 7:31:34 AM1/1/15
to land-o...@googlegroups.com
Update: I hoped out of emacs/slime and ran clisp straight from terminal and it outputted my random_walk.svg file.

So a bug in SLIME?

Wesley Ellis

unread,
Mar 4, 2015, 8:44:43 AM3/4/15
to land-o...@googlegroups.com
I also ran into this in sbcl. Took some playing around to figure out a fix. Here is my solution:

(with-open-file (*standard-output* "random_walk.svg"
                                   :direction :output
                                   :if-exists :supersede)
  (svg 400 200
    (loop repeat 10
         do (polygon (append '((0 . 200))
                             (let ((walk (random-walk 100 400)))
                               (loop 
                                    for y in walk
                                    for x below (length walk)
                                  collect (cons x y)))               
                             '((400 . 200)))
                     (loop repeat 3
                          collect (random 256))))))

I realized that we want y to be the values from the random-walk function, but x should be each point along the x axis from 0 to 400. Then we cons the x and y to get the points list.

With the default code from the book, sbcl was generating a list of points from the list returned by (random-walk 100 400), but it wasn't moving across the list in the expected manner. Each x and y were the same, so you would have a points list like '((100 . 100) (99 . 99) (98 . 98)(99 . 99)) etc. 

Then I tried makeing x be items in (random-walk 100 400) and y be (cdr (random-walk 400)), but I didn't want to call random-walk twice and get different lists, so I used let to create the local variable walk and: loop for x in walk for y in (cdr walk). This generated a points list with different numbers, but the polygon cam out to be a trianlge. This is because the points list was like so '((100 . 99) (99 . 98) (98 . 99) (99 . 98)) etc. Still not right.

Rethinking what the points list should be I cam up with the solution of having each x be a number between 0 and 400 and y be the value of the symbol at the position x in (random-walk 100 400). I could probably go back and remove the local variable now. Hope this helps others.
Message has been deleted

julio

unread,
Sep 27, 2016, 3:57:05 PM9/27/16
to Land of Lisp
I had this issue on cmucl, an old version.

I (think I) have fixed it by adding " from 0" after "(loop for x" on the 7th line

cheers!

Raul Alvarez Torrico

unread,
Sep 11, 2018, 11:10:34 AM9/11/18
to Land of Lisp
Thanks, this worked for me in CCL and SBCL, too.
Reply all
Reply to author
Forward
0 new messages