From: Josef Eschgfaeller
Subject: defvar
Date: 
Message-ID: <379DADFE.137FDB40@felix.unife.it>
I tried the following macro for doing defvar simultaneously for
several variables:

  (defmacro variables (a)
    `(dolist (x ,a) (defvar x)))

Then I call (variables '(x y z)).

And for a shorter (declare (ignore ... )):

  (defmacro ignore-shorter (&rest a)
    `(declare (ignore ,@a)))

Are these correct? In particular, in cases as the first one,
is there another better technique if one wants to define a macro
for iterating something over a list?

je

From: Marco Antoniotti
Subject: Re: defvar
Date: 
Message-ID: <lwr9luz2fc.fsf@copernico.parades.rm.cnr.it>
Josef Eschgfaeller <···@felix.unife.it> writes:

> I tried the following macro for doing defvar simultaneously for
> several variables:
> 
>   (defmacro variables (a)
>     `(dolist (x ,a) (defvar x)))

The above does not seem coorect, since DEFVAR does not evaluate its
first argument.

(macroexpand '(VARIABLES '(A B C)))   ; On CMUCL.
=>
(BLOCK NIL
  (LET ((#:G874 '(A B C)))
    (TAGBODY
      (GO #:G876)
     #:G875
      (LET ((X (CAR #:G874)))
        (DEFVAR X))
      (PSETQ #:G874 (CDR #:G874))
     #:G876
      (UNLESS (ENDP #:G874) (GO #:G875))
      (RETURN-FROM NIL (PROGN NIL)))))

OTOH

(defmacro define-variables (&rest var-names)
  `(progn
     ,@(mapcar (lambda (var-name)
                  `(defvar ,var-name))
               var-names)))

Kind of looks better.

(macroexpand '(define-VARIABLES A B C))
=>
(PROGN (DEFVAR A) (DEFVAR B) (DEFVAR C))

Cheers

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - 06 68 10 03 17, fax. +39 - 06 68 80 79 26
http://www.parades.rm.cnr.it/~marcoxa
From: Kent M Pitman
Subject: Re: defvar
Date: 
Message-ID: <sfwg12anovu.fsf@world.std.com>
Josef Eschgfaeller <···@felix.unife.it> writes:

> Then I call (variables '(x y z)).
> 
> And for a shorter (declare (ignore ... )):
> 
>   (defmacro ignore-shorter (&rest a)
>     `(declare (ignore ,@a)))
> 
> Are these correct? In particular, in cases as the first one,
> is there another better technique if one wants to define a macro
> for iterating something over a list?

The second one is not correct.  Macros may not expand into declarations.
(They could in CLTL1 but ANSI CL flushed this capability.  Many old
compilers still accept macros expanding into declarations, but they
are not required to.  I don't think any ill comes from their doing so,
other than confusion on the part of people writing portable code, who
don't have their unportabilities flagged at a proper time.)
The right thing to use instead of the above is:

(defmacro just-ignore (&rest things-to-ignore)
  `(progn ,@things-to-ignore
          nil))

The last NIL is important so you don't accidentally not ignore them by
using the return value of one of them.

You may also want to consider

(declaim '(inline please-ignore))
(defun please-ignore (&rest things-to-ignore)
  (declare (ignore things-to-ignore))
  nil)

This has the virtue that you can not only put it in bodies of code
but you can also map and apply it.  Yes, there are situations where
that comes up.  [Often people substitute #'identity in that situation,
but in some such cases, the identity is not consequential.]

The Lisp Machine just had a function IGNORE that was predefined like
PLEASE-IGNORE above.  It's a source of annoyance to me that we don't
have such a function in CL, since any user who tries to define it gets
[rightly] grumbled at for trying to add a definition to a symbol in the 
CL package.