[alexandria-devel] Review cycle 2: SWITCH, ESCWITCH, and CSWITCH

Nikodemus Siivola nikodemus at random-state.net
Mon Apr 5 11:51:28 UTC 2010


Never one to give up, I note that review cycle 2 is still on, and
SWITCH &co are still on the operating table...

Aside from the docstrings -- which are quick to fix once the semantics
are settled-- I think the main questions are:

* Should they evaluate clause keys or not?

* If they evaluate keys, can one specify multiple keys per clause?

* :KEY argument currently makes no sense, IMO, since (switch ((foo-bar
foo)) ...) is more convenient than (switch (foo :key #'foo-bar) ...).

* :TEST and :KEY meaning. What does (defun feh (equal) (switch (*foo*
:test equal) ...)) mean?

My current thinking is that evaluating keyforms is OK, as it makes it
easier to write stuff like

  (switch (foo :test #'equal)
    (constant1 ...)
    (constant2 ...))

I'd be happy to live with non-evaluating keys as well, though.

However, I was thinking that the convenience of multiple keyforms per
clause is worth something, so, perhaps the rule could be that a
keyform is either (1) an atom to be evaluated (2) a list of forms to
be evaluated. So:

 (switch ...
  (foo        ; compares against the variable FOO
   ...)
  ((quux bar) ; compares against the variables QUUX and BAR
   ...))

However, as stated, I don't care very deeply about the evaluation vs.
non-evaluation issue, and I'm happy to live with just a single keyform
as well.

:KEY I don't like. I think :KEY should apply to the clause keys, and
not the original object as it does now. (Or alternatively it could be
dropped.)

:TEST and :KEY semantics I don't like. Currently :TEST #'FOO :TEST
'FOO and :TEST FOO all mean the same thing. This is just wrong, IMO.

I'm thinking that either it's :TEST <FUNCTION-NAME-OR-LAMBDA> like in
standard macros that have keyword arguments for function, or it's
:TEST <FORM-THAT-EVALUATES-TO-SOMETHING-FUNCALLABLE> like in standard
functions.

Again, I'm happy with either -- but if #'FOO, 'FOO, and FOO are all
acceptable, then the first means the lexically visible function FOO,
second means the global function called through the symbol, and third
means the function that is the value of the variable FOO.

My minimum-change proposal is to change :KEY to apply to clause keys,
and not the original object, and to change :TEST and :KEY to either of
the above behaviours. I'm willing to change the key evaluation
semantics as well, but I don't consider that as crucial.

Comments?

Cheers,

 -- Nikodemus




More information about the alexandria-devel mailing list