[comp.lang.lisp] declarations

eliot@phoenix.Princeton.EDU (Eliot Handelman) (03/23/89)

Question about IGNORE:

(defun foo (x)
  (declare (ignore x))
  :ignored)

After compiling the function in KCl, I then do this:

>(foo)
:IGNORED

>(foo 1 2 3 4 5 6)
:IGNORED

Is this the right behavior? Should FOO complain about too many or too few
arguments, or can I count on this happening in all CL's? Steele doesn't
seem to have anything to say about it.

andreasg@boulder.Colorado.EDU (Andreas Girgensohn) (03/24/89)

In article <7325@phoenix.Princeton.EDU> eliot@phoenix.Princeton.EDU (Eliot Handelman) writes:
>Question about IGNORE:
>
>(defun foo (x)
>  (declare (ignore x))
>  :ignored)
>
>After compiling the function in KCl, I then do this:
>
>>(foo)
>:IGNORED
>
>>(foo 1 2 3 4 5 6)
>:IGNORED
>
>Is this the right behavior? Should FOO complain about too many or too few
>arguments, or can I count on this happening in all CL's? Steele doesn't
>seem to have anything to say about it.

As far as I know checks KCL the number of arguments only if you
declare (optimize (safety 2)) or (optimize (safety 3)).  You can
declare that local with declare or global with proclaim.  The default
is (safety 0).  I don't think that the (declare (ignore x)) has
anything to do with the behavior.

Andreas Girgensohn
andreasg@boulder.colorado.edu

sandra%defun.utah.edu@wasatch.UUCP (Sandra J Loosemore) (03/24/89)

In article <7325@phoenix.Princeton.EDU> eliot@phoenix.Princeton.EDU (Eliot Handelman) writes:
>Question about IGNORE:
>
>(defun foo (x)
>  (declare (ignore x))
>  :ignored)
>
>Should FOO complain about too many or too few
>arguments, or can I count on this happening in all CL's? Steele doesn't
>seem to have anything to say about it.

The IGNORE declaration doesn't have anything to do with checking for the
right number of arguments.  See CltL page 61:  "there must be exactly
as many arguments as there are parameters".  In other words, "it is
an error" if there aren't.  Sometimes an error is signalled, sometimes
it's harmless, and sometimes Bad Things will happen.  Some implementations
use OPTIMIZE declarations to decide whether to check for this error
in compiled code.

If you really want FOO to take any number of arguments and ignore them all,
try using:

(defun foo (&rest x)
  (declare (ignore x))
  :ignored)

-Sandra Loosemore (sandra@cs.utah.edu)

mkent@dewey.soe.berkeley.edu (Marty Kent) (03/24/89)

In article <7325@phoenix.Princeton.EDU> eliot@phoenix.Princeton.EDU (Eliot Handelman) writes:
>(defun foo (x) >  (declare (ignore x)) >  :ignored)
(foo)
>:IGNORED
Allegro Lisp says "Too few arguments to FOO"
>(foo 1 2 3 4 5 6)
>:IGNORED
Allegro says "Too many arguments to FOO"
>Is this the right behavior? Should FOO complain about too many or too few
>arguments, or can I count on this happening in all CL's? Steele doesn't
>seem to have anything to say about it.
Perhaps the "right" or "wrong" behavior in this situation is yet another
little loophole in the CL spec, though I certainly believe the ACL
responses are more -helpful- than the ones you quote...



Marty Kent  	Sixth Sense Research and Development
		415/642 0288	415/548 9129
		MKent@dewey.soe.berkeley.edu
		{uwvax, decvax, inhp4}!ucbvax!mkent%dewey.soe.berkeley.edu
Kent's heuristic: Look for it first where you'd most like to find it.

faustus@yew.Berkeley.EDU (Wayne Christopher) (03/30/90)

I'm trying to write Common Lisp code that compiles well, so I've
been putting (declare (type ...)) in all my functions, and it's a pain.
Are there any guidelines on when this will speed up the compiled code,
and when it won't help?  I'd guess that declaring numbers and lists
would be useful, but declaring other things like specific CLOS types
isn't necessary.

	Wayne