From: Duane Smith
Subject: difference between &rest and &body
Date: 
Message-ID: <AE8DOcygJ5rNiaxXLovZpqQ2T8XR@4ax.com>
Hi-

I am new to Lisp and am wondering what is the difference between using
&rest and &body in a macro definition.  They appear to do the same
thing.

Thanks in advance, 
········@ptcstudios.com

From: Tor Henrik Hanken
Subject: Re: difference between &rest and &body
Date: 
Message-ID: <m3g0scoa1h.fsf@wooster.localdomain>
[Duane Smith]

| I am new to Lisp and am wondering what is the difference between using
| &rest and &body in a macro definition.  They appear to do the same
| thing.

&body gives smart editors and code formatters a hint about how to
indent the code.  apart from that, they do exactly the same thing.
-- 
mvh 

Tor Henrik Hanken
From: Tim Bradshaw
Subject: Re: difference between &rest and &body
Date: 
Message-ID: <ey3n1mk8rxh.fsf@cley.com>
* Duane Smith wrote:
> Hi-
> I am new to Lisp and am wondering what is the difference between using
> &rest and &body in a macro definition.  They appear to do the same
> thing.

I think the idea is that &BODY is a hint to the system and the human
reader of the code that the remaining arguments are something like a
function body (I forget if there is a formal name for that), and thus
is should, for instance, be indented like a function body. Since this
is quite a common form for macros, it seemed like a worthwhile thing
to do.

Unfortunately none of the emacs-based lisp environments I'm familiar
with look closely enough at things like macro definitions to spot this
case.  However, here is what Genera does with two otherwise-identical
definitions:

    ;;; -*- Mode: LISP; Base: 10; Syntax: Ansi-common-lisp; Package: CL-USER -*-

    (defmacro with-grible ((x) &rest body)
      `(let ((grible ,x)) ,@body))

    (with-grible (1)
		 grible)

    (defmacro with-better-grible ((x) &body body)
      `(let ((grible ,x)) ,@body))

    (with-better-grible (1)
      grible) 

-- so one of the environments that was very influential when CL was
first being formalised did this.

(I wish some heroic emacs person would get emacs to spot this, and
also allow it to scan the buffer looking for something like the
zwei:defindentation macro / zwei:indentation declaration, or at least
its simple case).

--tim
From: Will Mengarini
Subject: Re: difference between &rest and &body
Date: 
Message-ID: <8fm20k$n4a$1@eskinews.eskimo.com>
Tim Bradshaw <···@cley.com> 23 Apr 2000 21:48:26 +0100:

> [...] &BODY is a hint to the system and the human reader of the
> code that the remaining arguments are something like a function
> body [...].  Unfortunately none of the emacs-based lisp
> environments I'm familiar with look closely enough at things
> like macro definitions to spot this case.  [...]  (I wish some
> heroic emacs person would get emacs to spot this [...])

Emacs Lisp built-in #'defmacro etc don't even recognize &body, but
cl-macs.el defines #'defmacro* etc that do recognize it (along with
almost all the rest of Common Lisp's lambda list capabilities), so you
have to use the splatted versions.  Even those, however, don't
recognize the prettyprint significance of &body, and this fixes that:

(defadvice cl-transform-lambda (after wm-cl-&body act)
  "Recognize &body as changing the prettyprint."
  (when (and (memq '&body (car form))
             ;; The argument list for the lambda form contained
             ;; '&body, so the symbol being bound should be
             ;; given defun-like indentation.  Such actions are
             ;; carried out in a block of code returned by
             ;; `cl-transform-lambda' as the car of its returned
             ;; value; the cdr is the emacsified lambda.
             ;;   In order for this to be possible, the
             ;; lambda being transformed needs to be being
             ;; bound to a name.  If it is, the symbol was
             ;; passed in as the arg named `bind-block':
             (not (eq bind-block 'cl-none)))
    (let ((additional-action `(put ',bind-block
                                   'lisp-indent-function
                                   'defun)))
      (if (car ad-return-value)
          ;; There's already an actions block there.  Require it to be
          ;; of recognizable form; if it's not, degrade gracefully by
          ;; (message)ing a warning but then doing nothing.
          (if (and (eq (caar ad-return-value) 'eval-when)
                   (equal (cadar ad-return-value) '(compile load eval)))
              (push additional-action (cddar ad-return-value))
            (message "wm-cl-&body: does not compute: %S"
                     (car ad-return-value)))
        ;; There's no actions block yet, so just replace the nil.
        (setf (car ad-return-value)
              `(eval-when (compile load eval)
                 ,additional-action))))))

> ([...] and also allow it to scan the buffer looking for
> something like the zwei:defindentation macro / zwei:indentation
> declaration, or at least its simple case.)

What are these?  Deja only found your post to which I'm replying,
and Google mostly came up dry, except for
http://www.google.com/search?q=zwei:indentation&sa=Google+Search
which found 2 pages in Sweden that render as line noise.

                 Will Mengarini  <······@eskimo.com>
         Free software: the Source will be with you, always.
From: Barry Margolin
Subject: Re: difference between &rest and &body
Date: 
Message-ID: <9vMT4.32$ej7.391@burlma1-snr2>
In article <············@eskinews.eskimo.com>,
Will Mengarini <······@eskimo.com> wrote:
>Tim Bradshaw <···@cley.com> 23 Apr 2000 21:48:26 +0100:
>> ([...] and also allow it to scan the buffer looking for
>> something like the zwei:defindentation macro / zwei:indentation
>> declaration, or at least its simple case.)
>
>What are these?  Deja only found your post to which I'm replying,
>and Google mostly came up dry, except for
>http://www.google.com/search?q=zwei:indentation&sa=Google+Search
>which found 2 pages in Sweden that render as line noise.

ZWEI is the Emacs-style editor on Lisp Machines, and those are the
functions/macros that are used to tell ZWEI how it should indent various
forms.

-- 
Barry Margolin, ······@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Tom Breton
Subject: Re: difference between &rest and &body
Date: 
Message-ID: <m3zoqkjik3.fsf@world.std.com>
Duane Smith <········@ptcstudios.com> writes:

> Hi-
> 
> I am new to Lisp and am wondering what is the difference between using
> &rest and &body in a macro definition.  They appear to do the same
> thing.

Yes, functionally, they do exactly the same thing.  &body is a sort of
hint to editors that the arguments after it are in an implicit progn,
for formatting purposes mostly.

-- 
Tom Breton, http://world.std.com/~tob
Not using "gh" since 1997. http://world.std.com/~tob/ugh-free.html
Rethink some Lisp features, http://world.std.com/~tob/rethink-lisp/index.html
Some vocal people in cll make frequent, hasty personal attacks, but if
you killfile them cll becomes usable.
From: Erik Naggum
Subject: Re: difference between &rest and &body
Date: 
Message-ID: <3165559961204128@naggum.no>
* Duane Smith <········@ptcstudios.com>
| I am new to Lisp and am wondering what is the difference between using
| &rest and &body in a macro definition.  They appear to do the same thing.

  yes, they _do_ the same thing, but they _mean_ different things.  the
  same is true of car and first, for instance.  remember that software is
  not written for the computer, but for programmers, including yourself.
  the more precise you are in communicating your _intent_ when writing, the
  less you have to worry about reconstructing your intent when you read it
  later.  &rest mainly communicates "a list of objects, mostly of similar
  type", while &body mainly communicates "forms to be evaluated in the
  context set up by the macro".  there are lots of variations on this
  theme, of course, but you get the idea.

#:Erik