[Issue Solved]Practical Common LISP Chapter 9: Gensyms Issue
Posted: Wed Apr 13, 2011 6:46 am
I wasn't able to find anything similar to my question through the search, so sorry if this has come up before.
I'm a complete beginner to LISP, and have been following Practical Common LISP to learn it, using the recommended LISPBox with Allegro. There weren't any issues until I get to the part in Chapter 9 where the macro (combine-results) is written. My question relates specifically to the use of getsyms. This is the code I end up with following the book:
When I compile it, I get the following warnings, which turn into errors when I run (test-+):
I can't find any differences between my code and that of the book, so I did some more research into gensyms, and saw the following syntax used:
I tried this syntax in my code to come up with this for the (combine-results) macro:
Which, for some reason, wasn't working before but has started working as soon as I input it to get some warnings to post here.
So, I suppose my question now is to do with (with-gensyms). Is it actually a function in LISP? And, if so, what is wrong with my use of it?
Thank you in advance.
I'm a complete beginner to LISP, and have been following Practical Common LISP to learn it, using the recommended LISPBox with Allegro. There weren't any issues until I get to the part in Chapter 9 where the macro (combine-results) is written. My question relates specifically to the use of getsyms. This is the code I end up with following the book:
Code: Select all
(defun test-+ ()
(check
(= (+ 1 2) 3)
(= (+ 1 2 3) 6)
(= (+ -1 -3) -4)))
(defun report-result (result form)
(format t "~:[FAIL~;pass~] ... ~a~%" result form)
result)
(defmacro check (&body forms)
`(combine-results
,@(loop for f in forms collect `(report-result ,f ',f))))
(defmacro combine-results (&body forms)
(with-gensyms (result)
`(let ((,result t))
,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
,result)))
Code: Select all
Warning: While compiling these undefined functions were referenced:
WITH-GENSYMS from position 265 in test.lisp;298
RESULT from position 265 in test.lisp;298
Code: Select all
(let ((variable (gensym)))
...)
Code: Select all
(defmacro combine-results (&body forms)
(let ((result (gensym)))
`(let ((,result t))
,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
,result)))
So, I suppose my question now is to do with (with-gensyms). Is it actually a function in LISP? And, if so, what is wrong with my use of it?
Thank you in advance.