From: lama
Subject: question about compiling and macros
Date: 
Message-ID: <bgt053$jpj$1@news-int.gatech.edu>
I am getting a weird error. For simplicity lets say I have two files: 
test1.lisp and test2.lisp.

----------------------------------------------------
test1.lisp looks like the following:

(load "test2.lisp")
(defmacro temp (x) (foo x))

-----------------------------------------------------

-----------------------------------------------------
test2.lisp look like this:

(defmacro foo (x) `(atom ,x))

-----------------------------------------------------

I tried compiling+loading test1.lisp in allegro lisp using ":cl 
test1.lisp". However when i call (temp 3) it complains like this: 
"Error: Attempt to call FOO which is defined as a macro."

However if i just load the file without compiling using ":ld test1.lisp"
i don't get any error while evaluating (temp 3).

This seems weird to me. Can anyone explain why the heck it works in the 
second case and not the first?

Thanx for any help.

From: Paul F. Dietz
Subject: Re: question about compiling and macros
Date: 
Message-ID: <jZqcnVTKVriSo6-iXTWJhQ@dls.net>
lama wrote:
> I am getting a weird error. For simplicity lets say I have two files: 
> test1.lisp and test2.lisp.
> 
> ----------------------------------------------------
> test1.lisp looks like the following:
> 
> (load "test2.lisp")
> (defmacro temp (x) (foo x))
> 
> -----------------------------------------------------
> 
> -----------------------------------------------------
> test2.lisp look like this:
> 
> (defmacro foo (x) `(atom ,x))
> 
> -----------------------------------------------------
> 
> I tried compiling+loading test1.lisp in allegro lisp using ":cl 
> test1.lisp". However when i call (temp 3) it complains like this: 
> "Error: Attempt to call FOO which is defined as a macro."
> 
> However if i just load the file without compiling using ":ld test1.lisp"
> i don't get any error while evaluating (temp 3).
> 
> This seems weird to me. Can anyone explain why the heck it works in the 
> second case and not the first?


When you compile test1.lsp, it doesn't execute (load "test2.lisp") at compile
time, so foo hasn't yet been defined as a macro and is treated as an
undefined function.

Put your calls to load in a separate file that is itself loaded first.
Or, use some flavor of defsystem.

Also, see EVAL-WHEN.

	Paul
From: Kaz Kylheku
Subject: Re: question about compiling and macros
Date: 
Message-ID: <cf333042.0308070830.40642914@posting.google.com>
lama <····@yahoo.com> wrote in message news:<············@news-int.gatech.edu>...
> I am getting a weird error. For simplicity lets say I have two files: 
> test1.lisp and test2.lisp.
> 
> ----------------------------------------------------
> test1.lisp looks like the following:
> 
> (load "test2.lisp")
> (defmacro temp (x) (foo x))

Regardless of the error from ACL, this probably isn't what you want.
Since FOO is a macro, you are passing it the symbol X, not the value
of the variable named X.

To do it right, you either have to turn FOO into a function, or else
have TEMP generate the code which calls FOO:

  (defmacro temp (x) `(foo ,x))

So now (temp 3) macroexpands to (foo 3) which macroexpands to (atom
3).

If you turn FOO into a function, you can do it in one step:

  (defun foo-expander (expression-form)
    `(atom ,expression-form))

  (defmacro temp (x)
    (foo-expander x))

So now for instance (temp (a b c)) causes, effectively, (foo-expander
'(a b c)) to be called to produce (atom (a b c)) which is the
macroexpansion.