From: ··········@bbs.ee.ncu.edu.tw
Subject: Behaviors between Macro's 2 Times
Date: 
Message-ID: <1130218661.418192.131960@g47g2000cwa.googlegroups.com>
For investigations of the behaviors between macro's 2 times ,
I wrote a macro as the follwoings:
================================================================
(defmacro test ( x y z)
    (format t "this is compiling time  ~%" )

    `(format t "this line is in vain because it is not retured by macro
 ~%" )

      `( progn ,(format t "compiling: ~a ~%" x)
             (format t " running time ~a ~%" ,Y)
             ,(format t "another compiling: ~a ~%" z)))
=================================================================
These codes run well in ARC x-lisp.
Just see the results :
> (test 1 2 3)
this is compiling time
compiling: 1
another compiling: 3
 running time 2
NIL
>
It shows that the line `(format t "this line is in vain bec...
gets no effects . Although it might create the form of "(format t "this
line is in vain because it is not retured by macro  ~%" )",this form
just doesn't take any effect for it is not returned by the macro
"test".
We also can see that the comma'ed forms were executed before the
un-comma'ed form.

See another result these code gave:
> (test A B C)
this is compiling time
compiling: A
another compiling: C
Error: The variable B is unbound.
Happened in: #<Subr-TOP-LEVEL-LOOP: #c623f0>
>
Error only happened in the runtime line for unbound variable.
But it doesn't happened in the compile time lines.
It means that the "macro machine" thinkns that the variables were
bound (in facts they were bound to A and C),but the "function machine"
thinks that the variable is not bound .

OK, that's what I see . Have good fun !
From: Barry Margolin
Subject: Re: Behaviors between Macro's 2 Times
Date: 
Message-ID: <barmar-4F7ECA.21540725102005@comcast.dca.giganews.com>
In article <························@g47g2000cwa.googlegroups.com>,
 ··········@bbs.ee.ncu.edu.tw wrote:

> For investigations of the behaviors between macro's 2 times ,
> I wrote a macro as the follwoings:
> ================================================================
> (defmacro test ( x y z)
>     (format t "this is compiling time  ~%" )
> 
>     `(format t "this line is in vain because it is not retured by macro
>  ~%" )
> 
>       `( progn ,(format t "compiling: ~a ~%" x)
>              (format t " running time ~a ~%" ,Y)
>              ,(format t "another compiling: ~a ~%" z)))
> =================================================================
> These codes run well in ARC x-lisp.
> Just see the results :
> > (test 1 2 3)
> this is compiling time
> compiling: 1
> another compiling: 3
>  running time 2
> NIL
> >
> It shows that the line `(format t "this line is in vain bec...
> gets no effects . Although it might create the form of "(format t "this
> line is in vain because it is not retured by macro  ~%" )",this form
> just doesn't take any effect for it is not returned by the macro
> "test".
> We also can see that the comma'ed forms were executed before the
> un-comma'ed form.
> 
> See another result these code gave:
> > (test A B C)
> this is compiling time
> compiling: A
> another compiling: C
> Error: The variable B is unbound.
> Happened in: #<Subr-TOP-LEVEL-LOOP: #c623f0>
> >
> Error only happened in the runtime line for unbound variable.
> But it doesn't happened in the compile time lines.
> It means that the "macro machine" thinkns that the variables were
> bound (in facts they were bound to A and C),but the "function machine"
> thinks that the variable is not bound .

Because you used comma to unquote Y.  So it expanded to

(format t " running time ~a ~%" B)

which tries to evaluate B when the expansion was executed.  What you 
probably wanted was:

(format t " running time ~a ~%" ',Y)

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***