[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How's that again?



   From: hall@research.att.com (Bob Hall)
   
   On the face of it, a variable is either ignored or not.  I see your point,
   but I believe the first error message should have said something like
   "variable x is written but not read" or the like.
   
       The following removes the error message:
       ? (defun foo (l)
   	(dolist (x l)
   	  (declare (ignorable x))
   	  (print "Hi")))
       FOO
   
   Thanks.  Is "IGNORABLE" as portable as "IGNORE"?  What about IGNORE-IF-UNUSED?
   (see below).  My code has to compile in three different common lisps.
   (MCL, Franz, Harlequin).  

The letter of the law: The dpANS2 is explicit that any iteration
variable binding established by an iteration form is always
automatically considered used, and that an IGNORE declaration on one
is incorrect.  However, this was a very late clarification in the
language spec and it will take time for implementations to catch up.

IGNORE and IGNORABLE are standard symbols in the COMMON-LISP package.
IGNORE-IF-UNUSED is not.

The tradiitonal way to achieve the effect of IGNORABLE was to mention
the variable in the body of the form:

      (defun foo (l)
   	(dolist (x l)
          x
   	  (print "Hi")))

You might or might not consider this stylistically ugly, but it's no
more so than lots of other lisp styles, and everyone has seen it lots
of times, so it's unlikely to cause confusion.  Most compilers will
not generate any code for such a variable reference, and the code is
certainly portable.