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

historical question about CASE



    Date: Fri, 5 Jun 87 11:19:20 MDT
    From: sandra%orion@cs.utah.edu (Sandra J Loosemore)

    While porting some code between CL implementations, I got bit by the fine
    print in the manual about how NIL was not allowed as a singleton key in
    CASE, as it could be confused with an empty key list.  It's easy enough
    to wrap a pair of parentheses around the NIL, but I got to thinking that
    an empty key list is not very interesting anyway.  Does anyone remember why
    it was decided to treat NIL as a list instead of a symbol in this context?

    Just curious,

    -Sandra
    -------

I don't remember specifically, but I would guess that it is for the
benefit of macros that take a lists of things and turn them into case
clauses.  For example:

(defmacro do-something (thing &key allow-list ignore-list complain-list)
  `(case ,thing
     (,allow-list (frob-thing ,thing))
     (,ignore-list nil)
     (,complain-list (error "I won't frob ~S!" ,thing))))

By the way, this is probably a good time to remind people that if they
write macros that make a case clause out of each element of a list, they
should always make them be lists of one element, not singleton keys.
Here's a trivial example:

(defmacro my-case (object &rest clauses)
  "Like CASE, but only takes singleton keys."
  `(case .,(loop for (key . consequent) in clauses	;I know it isn't CL LOOP
		 collect `((,key) .,consequent))))

						barmar