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

How do you say "ignore"?

    Date: Mon, 11 Dec 89 20:01 PST
    From: Robert D. Pfeiffer <RDP@ALAN.LAAC-AI.Dialnet.Symbolics.COM>

    Does anyone have a standard idiom that they use when ignoring variables
    in a destructuring pattern in LOOP?

    For example:

      (LOOP FOR (X IGNORE) IN '((A B) (C D))
	    COLLECT X))

    The way this is currently written the compiler will complain:

    For Function IGNORE-TEST
      While compiling (SETQ IGNORE (CAR #:TEMP)):
	The variable IGNORE is unknown and has been assumed SPECIAL

For this particular case, you can say

	(loop for (x) in ...)

since you don't care about the CDR of the list.  In general, LOOP is a
lot more generous about destructuring than destructuring-bind, and will
ignore NIL as a binding.  So, the above that I wrote is actually

	(loop for (x . NIL) in ...)

and the CDRs of the elements in the list will be ignored because you say
you want to bind NIL to them.

If you wanted, say, the first and third elements of a list you might say

	(loop for (x NIL y) in ...)

The second element of the list (and any CDDDR) would be ignored.