From: Kurt J Hausler
Subject: why cant I use a macro like this
Date: 
Message-ID: <7pdbjq$h5k$1@cantuc.canterbury.ac.nz>
Hi, thanks for answering my ffi question so quickly, you guys are amazing.  I have another one, 
You experienced lisp coder will find it easy, I actually think it should work and don't know why it cant.  I got this while macro out of Paul Graham

(defmacro while (test &rest body)
  `(do ()
    ((not ,test))
    ,@body))

And trying to use it gives me an error:

(while (= result -1)
	   (increment-level (peval-database (find-student user)))
	   (setf result (optimal-problem (peval-database (find-student user)))))

Gives this error:

Attempt to call SQL-TUTOR::WHILE which is defined as a macro.

I thought macros were callable?  Everything in the book suggests there is nothing wrong with what I am trying to do

Thanks

Kurt

From: Vassil Nikolov
Subject: Re: why cant I use a macro like this
Date: 
Message-ID: <l03130302b3e0223a6e5c@195.138.129.118>
Kurt J Hausler wrote:                [1999-08-18 04:08 +0000]

  [...]
  > this while macro out of Paul Graham
  [definition which is fine]
  > And trying to use it gives me an error:
  > 
  > (while (= result -1)
  > 	   (increment-level (peval-database (find-student user)))
  > 	   (setf result (optimal-problem (peval-database (find-student user)))))
  > 
  > Gives this error:
  > 
  > Attempt to call SQL-TUTOR::WHILE which is defined as a macro.
  > 
  > I thought macros were callable?  Everything in the book suggests there is nothing wrong with what I am trying to do

Are you sure that SQL-TUTOR::WHILE wasn't previously a function
that you have redefined as a macro but some piece of code still
thinks it is a function?

It would be helpful if you provided a transcript of your session *including
a backtrace* on the error, because what you posted does not contain any
use of WHILE as a function.

By the way, it would be nice if you get your newsreader to wrap lines
(around 60 or 72 characters or so).

Good luck,
Vassil.


Vassil Nikolov
Permanent forwarding e-mail: ········@poboxes.com
For more: http://www.poboxes.com/vnikolov
  Abaci lignei --- programmatici ferrei.





 Sent via Deja.com http://www.deja.com/
 Share what you know. Learn what you don't.
From: Howard R. Stearns
Subject: Re: why cant I use a macro like this
Date: 
Message-ID: <37BC3F4C.B4CFC9AA@elwood.com>
My guess is that transcript won't help unless it somehow shows the order
that individual definitions are compiled.

I suspect that Kurt compiled the calling code first, and the compiler
arranged to funcall the not-yet-known WHILE function.  Then he compiled
the 
WHILE macro without recompiling the caller.

If I'm right, what you need to know, Kurt, is that the compiler
processes macros at compile-time.  The function that forms the guts of
the macro definition is called on the CODE by the compiler.  This
function produces new code that is processed in its place by the
compiler.  By contrast, anything that looks like a function or macro
call, but for which no macro definition is yet available, while be
processed by the compiler as a FUNCTION CALL (to a possibly not-yet
defined function.)  Whenever you define or redefine a macro, you also
need to recompile all its callers so that they can generate the new
code.

Vassil Nikolov wrote:
> 
> Kurt J Hausler wrote:                [1999-08-18 04:08 +0000]
> 
>   [...]
>   > this while macro out of Paul Graham
>   [definition which is fine]
>   > And trying to use it gives me an error:
>   >
>   > (while (= result -1)
>   >        (increment-level (peval-database (find-student user)))
>   >        (setf result (optimal-problem (peval-database (find-student user)))))
>   >
>   > Gives this error:
>   >
>   > Attempt to call SQL-TUTOR::WHILE which is defined as a macro.
>   >
>   > I thought macros were callable?  Everything in the book suggests there is nothing wrong with what I am trying to do
> 
> Are you sure that SQL-TUTOR::WHILE wasn't previously a function
> that you have redefined as a macro but some piece of code still
> thinks it is a function?
> 
> It would be helpful if you provided a transcript of your session *including
> a backtrace* on the error, because what you posted does not contain any
> use of WHILE as a function.
> 
> By the way, it would be nice if you get your newsreader to wrap lines
> (around 60 or 72 characters or so).
> 
> Good luck,
> Vassil.
> 
> Vassil Nikolov
> Permanent forwarding e-mail: ········@poboxes.com
> For more: http://www.poboxes.com/vnikolov
>   Abaci lignei --- programmatici ferrei.
> 
>  Sent via Deja.com http://www.deja.com/
>  Share what you know. Learn what you don't.
From: Vassil Nikolov
Subject: Re: why cant I use a macro like this
Date: 
Message-ID: <l03130305b3e2041f4a4c@195.138.129.84>
Howard R. Stearns wrote:                [1999-08-19 12:30 -0500]

  > My guess is that transcript won't help unless it somehow shows the order
  > that individual definitions are compiled.

Yes, but it would be better than nothing (at least would show the
actual error message and hopefully some information about the
location in the program where the error occurred).  But essentially
you are right.

  > I suspect that Kurt compiled the calling code first, and the compiler
  > arranged to funcall the not-yet-known WHILE function.  Then he compiled
  > the 
  > WHILE macro without recompiling the caller.
  [...]

This indeed sounds like the most appropriate specific explanation.
I should have thought about it (rather than be more general).

By the way, (good) compilers print warnings about undefined functions
calls to which they have seen (i.e. symbols occurring in the car of
forms to be evaluated that were assumed by the compiler to name
functions).  Such warnings should not be disregarded.


Vassil Nikolov
Permanent forwarding e-mail: ········@poboxes.com
For more: http://www.poboxes.com/vnikolov
  Abaci lignei --- programmatici ferrei.





 Sent via Deja.com http://www.deja.com/
 Share what you know. Learn what you don't.