From: David R. McIntyre
Subject: Lisp Macro Capability Question
Date: 
Message-ID: <362511CF.34737EF2@cis.csuohio.edu>
I am just getting into LISP and understand the basics of macros.
However it appears difficult to define a macro:
(defmacro h (x)    ....  )
which when called with (h a) returns the list (a) where a can be any
symbol or list (using all the standard comma, backquote, quote etc).

Similarly I could not see a way to write a macro:
(defmacro my-cons (a l)
  ...
)
which would accept unquoted input like:
(my-cons u (v w))
(U V W)

Can anyone give me any help on this? Is there a good web site for
learning LISP with lots of detailed examples?

Thanks,
Dave (········@cis.csuohio.edu)

From: Barry Margolin
Subject: Re: Lisp Macro Capability Question
Date: 
Message-ID: <JS8V1.30$eJ2.452604@burlma1-snr1.gtei.net>
In article <·················@cis.csuohio.edu>,
David R. McIntyre <········@cis.csuohio.edu> wrote:
>I am just getting into LISP and understand the basics of macros.
>However it appears difficult to define a macro:
>(defmacro h (x)    ....  )
>which when called with (h a) returns the list (a) where a can be any
>symbol or list (using all the standard comma, backquote, quote etc).

(defmacro h (x)
  `(list ',x))

>Similarly I could not see a way to write a macro:
>(defmacro my-cons (a l)
>  ...
>)
>which would accept unquoted input like:
>(my-cons u (v w))
>(U V W)

(defmacro my-cons (a l)
  `(cons ',a ',l))

The way to figure out macros is to work backwards from the expansion.  To
get (U V W) from U and (V W) you would use

(cons 'u '(v w))

That tells you that your macro expansion should look like:

(cons '... '...)

This then becomes the backquoted body of your macro, and you replace the
...'s with the expressions that provide the parameters.  The commas
indicate that they should be evaluated in the expansion.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
From: Steve Gonedes
Subject: Re: Lisp Macro Capability Question
Date: 
Message-ID: <m2sogqd80r.fsf@KludgeUnix.com>
"David R. McIntyre" <········@cis.csuohio.edu> writes:

< I am just getting into LISP and understand the basics of macros.
...
< Can anyone give me any help on this? Is there a good web site for
< learning LISP with lots of detailed examples?

Here are some pages you may find interersting.

http://www.apl.jhu.edu/~hall/lisp.html
http://www.apl.jhu.edu/~hall/Lisp-Notes/Macros.html

Have fun...
From: Raymond Toy
Subject: Re: Lisp Macro Capability Question
Date: 
Message-ID: <4naf2yhrpp.fsf@rtp.ericsson.se>
>>>>> "David" == David R McIntyre <········@cis.csuohio.edu> writes:
[questions already answered by barmar]
    David> Can anyone give me any help on this? Is there a good web site for
    David> learning LISP with lots of detailed examples?

After looking at the web sites, try to get a copy of "On Lisp" by Paul 
Graham.  An excellent book on macros.   Unfortunately, it appears to
be out of print, but I still seem them once in a while in bookstores.

Ray
From: Paul Dietz
Subject: Re: Lisp Macro Capability Question
Date: 
Message-ID: <3626B07D.73B3D025@interaccess.com>
> After looking at the web sites, try to get a copy of "On Lisp" by Paul 
> Graham.  An excellent book on macros.   Unfortunately, it appears to
> be out of print, but I still seem them once in a while in bookstores.

I recently obtained a copy of ACL 5.0; a copy of "On Lisp"
was in the box.  Maybe it only comes with the commercial
(not the personal trial) version, but talk to Franz.

	Paul