From: -L
Subject: Newb Trouble with Macros
Date: 
Message-ID: <Pine.GSO.4.64.0608192235120.22794@cpu02.student.cs.uwaterloo.ca>
Im new to Lisp and Im learning it out of "Practical Common Lisp". Im 
having trouble compiling the example on page 107. I write the code exactly 
as given in the book and I get the following warning three times

WARNING in COMBINE-RESULTS :
RESULT is neither declared nor bound,
it will be treated as if it were declared SPECIAL.

Here is the code.

(defmacro combine-results (&body forms)
   (with-gensyms (result)
     `(let ((,result t))
       ,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
       ,result)))

Since these were only warnings I ignored them and tried to run my code but 
it complained a function wasnt defined that should have been compiled 
along with the function above.

Im running SLIME and I followed the instructions in the book for setting 
it up.

What the heck is going on here?

Thanks

From: howard yeh
Subject: Re: Newb Trouble with Macros
Date: 
Message-ID: <1156043112.982156.156960@m73g2000cwd.googlegroups.com>
-L wrote:
> Im new to Lisp and Im learning it out of "Practical Common Lisp". Im
> having trouble compiling the example on page 107. I write the code exactly
> as given in the book and I get the following warning three times
>
> WARNING in COMBINE-RESULTS :
> RESULT is neither declared nor bound,
> it will be treated as if it were declared SPECIAL.
>
> Here is the code.
>
> (defmacro combine-results (&body forms)
>    (with-gensyms (result)
>      `(let ((,result t))
>        ,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
>        ,result)))
>

Maybe with-gensyms is not defined (or comes after the above macro)?
Compiler needs to see with-gensyms before other macros can use it.
From: Ari Johnson
Subject: Re: Newb Trouble with Macros
Date: 
Message-ID: <m2lkpkkpai.fsf@hermes.theari.com>
-L <······@student.cs.uwaterloo.ca> writes:

> Im new to Lisp and Im learning it out of "Practical Common Lisp". Im
> having trouble compiling the example on page 107. I write the code
> exactly as given in the book and I get the following warning three
> times
>
> WARNING in COMBINE-RESULTS :
> RESULT is neither declared nor bound,
> it will be treated as if it were declared SPECIAL.
>
> Here is the code.
>
> (defmacro combine-results (&body forms)
>   (with-gensyms (result)
>     `(let ((,result t))
>       ,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
>       ,result)))
>
> Since these were only warnings I ignored them and tried to run my code
> but it complained a function wasnt defined that should have been
> compiled along with the function above.
>
> Im running SLIME and I followed the instructions in the book for
> setting it up.
>
> What the heck is going on here?

Try (describe 'with-gensyms) and see what you get.  My guess is that
you either have no such macro at all or that it is just not available
in the package you are working in.  WITH-GENSYMS is not in ANSI CL,
although it's a popular utility.

At any rate, if you did not have WITH-GENSYMS bound as a macro when
you defined COMBINE-RESULTS, the compiler would assume that it's a
regular function call.  The compiler therefore generates the following
code:

1. (result) => (funcall (function result)) => undefined function
warning

2. `(let ...) => backquote-expanded-form, with undefined variable
warnings for all three uses of RESULT

3. (with-genyms (result) `(let ...))
  => (funcall (function with-gensyms)
              result-from-step-1
              result-from-step-2)

Does that make sense?
From: Pascal Bourguignon
Subject: Re: Newb Trouble with Macros
Date: 
Message-ID: <87ac60f648.fsf@thalassa.informatimago.com>
-L <······@student.cs.uwaterloo.ca> writes:

> Im new to Lisp and Im learning it out of "Practical Common Lisp". Im
> having trouble compiling the example on page 107. I write the code
> exactly as given in the book and I get the following warning three
> times
>
> WARNING in COMBINE-RESULTS :
> RESULT is neither declared nor bound,
> it will be treated as if it were declared SPECIAL.
>
> Here is the code.
>
> (defmacro combine-results (&body forms)
>   (with-gensyms (result)
>     `(let ((,result t))
>       ,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
>       ,result)))

I don't get this warning.

Try:  (macroexpand '(combine-results (+ 1 2) (* 3 4)))


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

In a World without Walls and Fences, 
who needs Windows and Gates?
From: funkyj
Subject: Re: Newb Trouble with Macros
Date: 
Message-ID: <1156218889.297746.273610@75g2000cwc.googlegroups.com>
-L wrote:
> Im new to Lisp and Im learning it out of "Practical Common Lisp". Im
> having trouble compiling the example on page 107. I write the code exactly
> as given in the book and I get the following warning three times

Which Common Lisp implementation are you using?

I seem to recall that CLisp has a "with-gensym" but the syntax may be
different than other implementations of with-gensym.

No doubt following Pascal B's suggestion to do macro expand will make
things more clear.

  --fj
From: ·······@gmail.com
Subject: Re: Newb Trouble with Macros
Date: 
Message-ID: <1156656455.896424.135130@i3g2000cwc.googlegroups.com>
-L wrote:
> Im new to Lisp and Im learning it out of "Practical Common Lisp". Im
> having trouble compiling the example on page 107. I write the code exactly
> as given in the book and I get the following warning three times
>
> WARNING in COMBINE-RESULTS :
> RESULT is neither declared nor bound,
> it will be treated as if it were declared SPECIAL.
>
> Here is the code.
>
> (defmacro combine-results (&body forms)
>    (with-gensyms (result)
>      `(let ((,result t))
>        ,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
>        ,result)))
>
> Since these were only warnings I ignored them and tried to run my code but
> it complained a function wasnt defined that should have been compiled
> along with the function above.
>
> Im running SLIME and I followed the instructions in the book for setting
> it up.
>
> What the heck is going on here?
>
> Thanks

Page 101 defines with-gensyms

(defmacro with-gensyms ((&rest names) &body body)
  `(let ,(loop for n in names collect `(,n (gensym)))
  ,@body))