From: Nicolas Edel
Subject: macro arguments type
Date: 
Message-ID: <121a78fb-f2d4-4b0e-a893-7bc89262be88@x16g2000prn.googlegroups.com>
Hi,

consider the following:

CL-USER> (defmacro bar (x)
           (print (type-of x))
           `(type-of ,x))
BAR
CL-USER> (bar 'a)

CONS
SYMBOL

I don't understand why the type-of operator returns CONS while the
same operator with the same argument returns SYMBOL at the REPL or in
a defun.

-Nicolas

From: Rainer Joswig
Subject: Re: macro arguments type
Date: 
Message-ID: <joswig-0916B5.18431608112008@news-europe.giganews.com>
In article 
<····································@x16g2000prn.googlegroups.com>,
 Nicolas Edel <············@gmail.com> wrote:

> Hi,
> 
> consider the following:
> 
> CL-USER> (defmacro bar (x)
>            (print (type-of x))
>            `(type-of ,x))
> BAR
> CL-USER> (bar 'a)
> 
> CONS
> SYMBOL
> 
> I don't understand why the type-of operator returns CONS while the
> same operator with the same argument returns SYMBOL at the REPL or in
> a defun.
> 
> -Nicolas

(bar 'a)   =   (bar (quote a))

Now the macro executes similar to this:

  (let ((x '(quote a)))
    (type-of x))

    -> CONS
   
   (quote a) is the source and it is a CONS.
  
and expands (bar 'a) into  (type-of 'a)


Executing:   (type-of (quote a))   -> symbol

   (quote a) will be evaluated into the symbol A
   and this symbol will be passed to TYPE-OF.
   TYPE-OF then thinks that the symbol A is a symbol.

Remember, during macro expansion the s-expression SOURCE is bound to
the macro parameters. Not values. SOURCE. The
macro then generates new source. This new source will
be executed.

-- 
http://lispm.dyndns.org/
From: Nicolas Edel
Subject: Re: macro arguments type
Date: 
Message-ID: <01a88cc0-d73c-41c3-ad0e-5f2d925a6996@e38g2000prn.googlegroups.com>
Rainer Joswig wrote:
> In article
> <····································@x16g2000prn.googlegroups.com>,
>  Nicolas Edel <············@gmail.com> wrote:
>
> > Hi,
> >
> > consider the following:
> >
> > CL-USER> (defmacro bar (x)
> >            (print (type-of x))
> >            `(type-of ,x))
> > BAR
> > CL-USER> (bar 'a)
> >
> > CONS
> > SYMBOL
> >
> > I don't understand why the type-of operator returns CONS while the
> > same operator with the same argument returns SYMBOL at the REPL or in
> > a defun.
> >
> > -Nicolas
>
> (bar 'a)   =   (bar (quote a))
>
> Now the macro executes similar to this:
>
>   (let ((x '(quote a)))
>     (type-of x))
>
>     -> CONS
>
>    (quote a) is the source and it is a CONS.
>
> and expands (bar 'a) into  (type-of 'a)
>
>
> Executing:   (type-of (quote a))   -> symbol
>
>    (quote a) will be evaluated into the symbol A
>    and this symbol will be passed to TYPE-OF.
>    TYPE-OF then thinks that the symbol A is a symbol.
>
> Remember, during macro expansion the s-expression SOURCE is bound to
> the macro parameters. Not values. SOURCE. The
> macro then generates new source. This new source will
> be executed.
>

Crystal clear. Thanks.

-Nicolas
From: Kenny
Subject: Re: macro arguments type
Date: 
Message-ID: <491a9ee8$0$20287$607ed4bc@cv.net>
Nicolas Edel wrote:
> Hi,
> 
> consider the following:
> 
> CL-USER> (defmacro bar (x)
>            (print (type-of x))
>            `(type-of ,x))
> BAR
> CL-USER> (bar 'a)
> 
> CONS
> SYMBOL
> 
> I don't understand why the type-of operator returns CONS while the
> same operator with the same argument returns SYMBOL at the REPL or in
> a defun.

You were close, so very very close. All you had to do was:

   (print (list (type-of x) x))

Quite a rush I recall when I got launched off this bit of the learning 
curve, one of those instant enlightenment Zen deals.

kt