Hi, Am 01.03.2009 um 15:23 schrieb glow:
1) Why is cond and condp syntax inconsistent (necessity of :else)?
The syntax of cond is
(cond
test1 clause1
test2 clause2
...)
That is the first argument will be evaluated. If it is logically true,
the second argument is evaluated and its result returned. If the
test is logically false, cond goes on with test2 and clause2 etc.
:else is simply a trick to provide an always true test. You could
also write true, 5 or "Hello World!" instead of :else. This is the
same eg. in Scheme.
The syntax of condp is
(condp test-fn thing
candidate1 clause1
candidate2 clause2
...)
Here the first and second arguments are a test function and the
thing to test. condp takes the third argument and checks, whether
(test-fn candidate1 thing) returns logically true. If so clause1 is
evaluated and its result returned. Otherwise it goes on with
candidate2 and clause2. How do you specify here the :else?
So the convention is an odd clause at the end, which is then
interpreted at as else-clause if no candidate yields logically
true.
Every syntax by itself is consistent. Although the :else could
be considered a hack. Maybe cond should be adjusted to
allow an odd else-clause?
Note also, that condp throws if no candidate yields true and
no else-clause is provided. And it supports a form, where the
test-fn result is passed to the clause which is expected to be
a function.
(condp some coll
set1 :>> (fn [hit] ...)
set2 :>> (fn [hit] ...)
...)
2) On page 1 of introduction to Lisp I read "(+ 1 2) but also (+ 1 2 3)". Wow prefix notation is cool. But imagine for a moment that in an new exciting language you can write (* 1 2) but not (* 1 2 3)! You must use (cond* 1 2 3 4) and what is worse (cond* 1 2 3 4 :else 5)! Moreover since :else is necessary in cond why not (if a b :else c)?! That looks sooo bad.
The reasons why it is like that are outlined above. And for the case file: In almost all languages you cannot say (* 1 2 3). You have to say (* (* 1 2) 3) aka 1 * 2 * 3. Sincerely Meikel
smime.p7s
Description: S/MIME cryptographic signature
