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

case using other equality-testing predicates



    Date: Tue, 20 May 86 08:25:15 pdt
    From: fateman%dim@BERKELEY.EDU (Richard Fateman)

    If case used equalp or had a keyword :test with the usual meaning,
    I could use case instead of redefining it..
      I include the explanation below for those who might choose to try to
    satisfy my perceived need by another programming construct..

For those familiar with the Lisp Machine Lisp-derived dialects,
	SELECTQ is pretty much CASE
	SELECT is sort-of selectq without the quoting of the items, e.g.,
	  (select foo
	    (bar 1)
	    (baz 2))
	  ==> (COND ((EQL FOO BAR) 1) ((EQL FOO BAZ) 2)) ; BAR and BAZ aren't quoted
	SELECTOR is like SELECT (doesn't quote) and gives you the predicate:
	  (selector foo <
	    (1 "small")
	    (q "less than q")
	    (100 "moderate")
	    (1000 "big")
	    (otherwise "huge"))
	  ==> (COND ((< FOO 1) "small")
		    ((< FOO Q) "less than q")
		    ((< FOO 100) "moderate")
		    ((< FOO 1000) "big")
		    (T "huge"))
Since CLtL doesn't have this functionality, Symbolics has included it in
their extensions.  I also note CLtL doesn't have the functionality of
SELECT (which is SELECTOR using EQL), so Symbolics provides that too.

    In an application I had hoped to put in a package, I used
    a construction analogous to 

    (in-package 'commandpackage)
    .....
       (case  com ;; com is a command, an atom read in by Lisp reader
	    (p <some stuff>)
	    ((1 first) <more stuff>)
	    (cos  <yet more stuff>)
       ... etc)

    Now when you read in the atom  p, it is not the same as the item
    in the case table, which is commandpackage::p.  Exporting and then
    shadowing-importing p, first, cos, .. is not a good idea, (in general), but
    specifically because the symbols first, cos, etc  would cover up the 
    functions of the same name.

    What it seems I need is another macro in the case-family that
    tests using equalp rather than eql, so I can use strings.. e.g.
    (string-case (string com)
	    ("p" <some stuff>)
	    (("1" "first") <more stuff>)
	    ... etc..