Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!rutgers!mit-eddie!barmar
From: barmar@mit-eddie.MIT.EDU (Barry Margolin)
Newsgroups: comp.lang.lisp
Subject: Re: Macros for the elementary lithp programmer
Message-ID: <4483@mit-eddie.MIT.EDU>
Date: Fri, 9-Jan-87 00:43:26 EST
Article-I.D.: mit-eddi.4483
Posted: Fri Jan  9 00:43:26 1987
Date-Received: Fri, 9-Jan-87 02:48:31 EST
References: <4455@mit-eddie.MIT.EDU>
Reply-To: barmar@eddie.MIT.EDU (Barry Margolin
Organization: MIT, EE/CS Computer Facilities, Cambridge, MA
Lines: 29

In article <4455@mit-eddie.MIT.EDU> glenn@mit-eddie.MIT.EDU (Glenn Meader) writes:
>Example: (defmacro foo(&rest body))
>
>I want this form to translate to (/ body) if (oddp (car body))
>and to (* body) if	(evenp (car body)). This example is only
>to demonstrate a principle. My LISP, when given (foo 2 3 4), complains
>that '2 is a bad function.  Also is  there a more appropriate group for
>this type of elementary question? Thanks. 

It would have helped if you had included the rest of your macro in your
example, but I think I can guess what it looked like:
	(defmacro foo (&rest body)
	  (if (oddp (car body))
	      `(/ ,body)
	    `(* ,body)))
The problem is not in the way you do the test, it is in the expansions.
Since the value of BODY is a list, the expansion of (foo 2 3 4) is
	(* (2 3 4))
Now it should be obvious why it complained that 2 is a bad function.
The fix is to use ". ,body" in the macro instead of ",body".

One way to learn these things by yourself is to make use of the
MACROEXPAND function to see what the expansion is.  If you're lucky,
your implementation will have an interactive macroexpander, like the
Lisp Machine's MEXP.
-- 
    Barry Margolin
    ARPA: barmar@MIT-Multics
    UUCP: ..!genrad!mit-eddie!barmar