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

historical question about CASE

    Date: Fri, 5 Jun 1987  16:11 EDT
    From: SOLEY@xx.lcs.mit.edu

	Date: Friday, 5 June 1987  14:41-EDT
	From: Barry Margolin <barmar at Think.COM>
	To:   Sandra J Loosemore <sandra%orion at cs.utah.edu>

	    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 . . .
	    Does anyone remember why it was decided to treat NIL as a list
	    instead of a symbol in this context?

	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))))

    Silly Programmer, hacks are for kids.  That's no reason.

    (defmacro do-something (thing &key allow-list ignore-list complain-list)
      (append `(case ,thing)
	      (if allow-list `((,allow-list (frob-thing ,thing))))

	      .. etc ..

	    -- Richard

Why APPEND?  What's wrong with this:

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

I use the idiom ",@(when foo `(...baz...))" a LOT.

But indeed, perhaps () as a case item should not have been made
to mean an empty list.  But it's probably too late now.