[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: case using other equality-testing predicates
Date: 21 May 86 16:03 PDT
From: Gregor.pa@Xerox.COM
From: David A. Moon <Moon@SCRC-STONY-BROOK.ARPA>
Subject: case using other equality-testing predicates
So where would additional options, such as :KEY and an option that
controls whether or not the keys at the heads of the clauses are
evaluated, go in your syntax?
Do we really need additional options? Its easy to get the behavior of
a :key option in the obvious way, after all:
(ncase (car item) #'eq
(a (do-a))
(b (do-b))
(otherwise (lose)))
is at least as clear as:
(ncase item
(:test #'eq :key #'car)
(a (do-a))
(b (do-b))
(otherwise (lose)))
or something, and since none of the other case macros make it possible
to evaluate the "keys at the heads of the clauses" I am not sure why
this one should.
[I'm not wedded to the name selector.]
Symbols (the normal thing case gets used for) aren't evaluated because
that is the normal thing for case. Consider my original example again:
(selector foo <
(1 "small")
(10 "moderate")
(q "less than q")
(1000 "big")
(otherwise "huge"))
This can't be done unless Q gets evaluated because the test isn't EQL
but something arbitrary.
I'll warn the community of some rather strange looking code this can
sometimes produce:
- If you want to use EQUAL on a list, you need to do something like
(selector foo equal
(('(1 2 3) ...whatever...)))
because
(selector foo equal
('(1 2 3) ...whatever...))
is realy
(selector foo equal
((quote (1 2 3)) ...whatever...))
=> (cond ((or (equal foo quote)
(equal foo (1 2 3)))
...whatever...))
which is not what was intended. Maybe the implicit OR clause shouldn't
be included?