From: [Invalid-From-Line]
Subject: (newbie) help with 'with-gensyms' required
Date: 
Message-ID: <458dc491@quokka.wn.com.au>
OK, so I'm a newbie.    But I don't think I'm particularly stupid.  I'm 
working through Practical common lisp.  Everything working OK until I start 
on the test framework.

What I've typed looks like

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

(defmacro check (&body forms)
  `(combine-results
    ,@(loop for f in forms collect `(report-result ,f ',f))))

(defun report-result (result form)
  (format t "~:[FAIL~;pass~] ... ~a~%" result form)
  result)

(defun test-+ ()
    (check
      (= (+ 1 2) 3)
      (= (+ 1 2 3) 6)
      (= (+ -1 -3) -4)))
---------------------

Which I'm pretty sure is correct, upto the point I've reached.

I'm using Cormon lisp, because I've found I 'get it' and emacs/slime doesn't 
work for me (which isn't to say I can't get it to work, it does work just 
fine, I just prefer corman lisp, so far).

Cormon lisp jacks up about the 'with-gensysms' call.  Which results in 
'result' being unbound and then of course, nothing works.  A quick google 
shows that maybe 'with-unique-names' might be a better choice, but that did 
the same thing.  So, what am I doing wrong here? 

From: Zach Beane
Subject: Re: (newbie) help with 'with-gensyms' required
Date: 
Message-ID: <m3irg26tk7.fsf@unnamed.xach.com>
<SnowGhost> writes:

> What I've typed looks like
> 
> ----------------
> (defmacro combine-results (&body forms)
>   (with-gensyms (result)
>     `(let ((,result t))
>       ,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
>       ,result)))
[snip]
> 
> Which I'm pretty sure is correct, upto the point I've reached.

Not quite.
 
> Cormon lisp jacks up about the 'with-gensysms' call.  

WITH-GENSYMS isn't standard, but is defined in PCL chapter 8 (among
other places). 

> So, what am I doing wrong here? 

Define WITH-GENSYMS before trying to use it. Here's the definition
from PCL:

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

Zach
From: Kaz Kylheku
Subject: Re: (newbie) help with 'with-gensyms' required
Date: 
Message-ID: <1166952498.271930.245160@f1g2000cwa.googlegroups.com>
SnowGhost wrote:
> OK, so I'm a newbie.    But I don't think I'm particularly stupid.  I'm
> working through Practical common lisp.  Everything working OK until I start
> on the test framework.
>
> What I've typed looks like
>
> ----------------
> (defmacro combine-results (&body forms)
>   (with-gensyms (result)
>     `(let ((,result t))
>       ,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
>       ,result)))

This COMBINE-RESULTS is basically a non-short-circuiting boolean AND.
That is to say, it evaluates the forms from left to right, and does not
stop evaluating the forms when it encounters one which yields false. It
returns T if, and only if, all of the forms yield non-NIL values,
otherwise NIL. Precisely because it's non short-circuiting, it can be
implemented as a function. And in fact, this function can be a thin
wrapper for the EVERY function, which takes a predicate to be applied
to every element, and a sequence. We just want to test the elements
themselves, so the predicate we use is IDENTITY:

(defun combine-results (&rest values)
  (every #'identity values))

Now we are closer to what might be legitimately called practical Common
Lisp: not wasting time on writing unnecessary macros. However it can't
go unmentioned that this version of COMBINE-RESULTS is subject to the
implementation's limits on the number of arguments that a function may
take.

> Cormon lisp jacks up about the 'with-gensysms' call.  Which results in
> 'result' being unbound and then of course, nothing works.  A quick google
> shows that maybe 'with-unique-names' might be a better choice, but that did
> the same thing.  So, what am I doing wrong here?

Reporting a problem with a macro, without showing the actual definition
of it that you are using.

Based on what I know about WITH-GENSYMS, you're using it correctly.

It's just a trivial keystroke saver which saves you from typing:

  (let ((result (gensym))) ...)

or (if the symbol is to be meaningfully named):

  (let ((result (gensym "RESULT-"))) ...)

So try these, or get a working WITH-GENSYMS from somewhere.
From: Bill Atkins
Subject: Re: (newbie) help with 'with-gensyms' required
Date: 
Message-ID: <m2zm9dcpxj.fsf@bertrand.local>
"Kaz Kylheku" <········@gmail.com> writes:

> This COMBINE-RESULTS is basically a non-short-circuiting boolean AND.
> That is to say, it evaluates the forms from left to right, and does not
> stop evaluating the forms when it encounters one which yields false. It
> returns T if, and only if, all of the forms yield non-NIL values,
> otherwise NIL. Precisely because it's non short-circuiting, it can be
> implemented as a function. And in fact, this function can be a thin
> wrapper for the EVERY function, which takes a predicate to be applied
> to every element, and a sequence. We just want to test the elements
> themselves, so the predicate we use is IDENTITY:
>
> (defun combine-results (&rest values)
>   (every #'identity values))
>
> Now we are closer to what might be legitimately called practical Common
> Lisp: not wasting time on writing unnecessary macros. However it can't
> go unmentioned that this version of COMBINE-RESULTS is subject to the
> implementation's limits on the number of arguments that a function may
> take.

But doesn't EVERY short-circuit, too?

CL-USER 1 > (every #'print '(1 2 nil 3 4))

1 
2 
NIL 
NIL
From: Alex Mizrahi
Subject: Re: (newbie) help with 'with-gensyms' required
Date: 
Message-ID: <458e933d$0$49205$14726298@news.sunsite.dk>
(message (Hello 'Bill)
(you :wrote  :on '(Sun, 24 Dec 2006 09:46:16 -0500))
(

 BA> But doesn't EVERY short-circuit, too?

every does,  but arguments of a function are always evaluated. so forms will 
be evaluated before every will be called

)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
"People who lust for the Feel of keys on their fingertips (c) Inity") 
From: Bill Atkins
Subject: Re: (newbie) help with 'with-gensyms' required
Date: 
Message-ID: <m2fyb5qiu4.fsf@bertrand.local>
"Alex Mizrahi" <········@users.sourceforge.net> writes:

>  BA> But doesn't EVERY short-circuit, too?
>
> every does,  but arguments of a function are always evaluated. so forms will 
> be evaluated before every will be called

Ah, gotcha.
From: Richard
Subject: Re: (newbie) help with 'with-gensyms' required
Date: 
Message-ID: <zjqzi.178720$dA7.160069@newsfe16.lga>
Kaz Kylheku wrote:
> SnowGhost wrote:
>> OK, so I'm a newbie.    But I don't think I'm particularly stupid.  I'm
>> working through Practical common lisp.  Everything working OK until I start
>> on the test framework.
>>
>> What I've typed looks like
>>
>> ----------------
>> (defmacro combine-results (&body forms)
>>   (with-gensyms (result)
>>     `(let ((,result t))
>>       ,@(loop for f in forms collect `(unless ,f (setf ,result nil)))
>>       ,result)))
> 
> This COMBINE-RESULTS is basically a non-short-circuiting boolean AND.
> That is to say, it evaluates the forms from left to right, and does not
> stop evaluating the forms when it encounters one which yields false. It
> returns T if, and only if, all of the forms yield non-NIL values,
> otherwise NIL. Precisely because it's non short-circuiting, it can be
> implemented as a function. And in fact, this function can be a thin
> wrapper for the EVERY function, which takes a predicate to be applied
> to every element, and a sequence. We just want to test the elements
> themselves, so the predicate we use is IDENTITY:
> 
> (defun combine-results (&rest values)
>   (every #'identity values))
> 
> Now we are closer to what might be legitimately called practical Common
> Lisp: not wasting time on writing unnecessary macros. However it can't
> go unmentioned that this version of COMBINE-RESULTS is subject to the
> implementation's limits on the number of arguments that a function may
> take.
> 
>> Cormon lisp jacks up about the 'with-gensysms' call.  Which results in
>> 'result' being unbound and then of course, nothing works.  A quick google
>> shows that maybe 'with-unique-names' might be a better choice, but that did
>> the same thing.  So, what am I doing wrong here?
> 
> Reporting a problem with a macro, without showing the actual definition
> of it that you are using.
> 
> Based on what I know about WITH-GENSYMS, you're using it correctly.
> 
> It's just a trivial keystroke saver which saves you from typing:
> 
>   (let ((result (gensym))) ...)
> 
> or (if the symbol is to be meaningfully named):
> 
>   (let ((result (gensym "RESULT-"))) ...)
> 
> So try these, or get a working WITH-GENSYMS from somewhere.
> 
Thank you so much for the reply to the question.  I too was having 
trouble with the WITH-GENSYMS in "Practical Common Lisp"