<div class="gmail_quote"><br>2010/4/5 Pascal J. Bourguignon <span dir="ltr"><<a href="mailto:pjb@informatimago.com">pjb@informatimago.com</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">[...]<br><br></div>
I don't like adding such "syntax" when a pair of parentheses would just do, or even better, if we can come out with a regular syntax that doesn't need special treatments.<br></blockquote><div><br>Ok, it would be ok by me if I have to use one more parenthesis to evaluate forms. If others prefer more parenthesis than more keywords, more parenthesis it is.<br>
<br>Regarding to not have special treatments, I think this only benefits the macro implementation, not the users, so I vote for having special treatments.<br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

<br>
[...]<br>
<br>
If we choose run-time evaluation, there is the question of the order of evaluation.  Of course, the keys would be evaluated in sequence to stay with CL evaluation principles. But do we want short-cut evaluation, or can we imagine an algorithm where evaluating all the keys at once, and then finding the branch would be more efficient? (eg. if we could evaluate and select in parallel).  In which case we would also have to deal with duplicate values for the keys, possibly in different branches.   Currently, I don't see that we could provide anything better than testing sequentially, and therefore, short-cut evaluating the keys would be expected. (This is the current COND-like behavior).<br>
</blockquote><div><br>I believe that run-time evaluation sequentially and short-cutting whenever the key matches some value. About evaluating and selecting keys in parallel, you mean using multiple threads? Unless the evaluation of the keys take a really long time, that would only slow down the process. If the evaluation takes a long time, the user could use multiple threads if he or she finds pertinent.<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

<br>
<br>
Given a sensible default for :test, I find it unexpected to expect to surround the expression in parentheses.  Since all the clauses are lists, I would propose to leave the keyword options at the same level:<br>
<br>
   (<switch-operator>  <expression> [ :test <test-expression> ]<br>
      <clauses>)<br></blockquote><div> </div><div>The problem is it would be bad for automatic indentation.<br><br>A alternative would to use the model given in the link provided by Nikodemus:<br>
<a href="http://common-lisp.net/project/bknr/static/lmman/fd-flo.xml#select" target="_blank">http://common-lisp.net/project/bknr/static/lmman/fd-flo.xml#select</a><br><br>but, instead of <i><span style="font-family: courier new,monospace;">select</span></i> and <i><span style="font-family: courier new,monospace;">selector</span></i>, I vote for <i><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">switch</span></i><i><span style="font-family: courier new,monospace;"></span></i> and <i><span style="font-family: courier new,monospace;">switch*</span></i>:<br>
<br><span style="font-family: courier new,monospace;">(switch <expression></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  <clauses>)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(switch* <expression> <test-expression></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  <clauses>)</span><br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><br>[...]<br>

<br>
Finally, concerning the list of keys per clauses, by the same reasoning as for :key, and given the choice fo run-time evaluation of the clause keys, I'd tend to think that we can restrict ourselves to a single value. If the user wants to check against a list of keys, she can do it with a specific :test funtion:<br>

<br>
(switch item :test (function member)<br>
   ('(1 2 3)  ...)<br>
   ((list (get-one) (get-another)) ...)<br>
   ((list *a-single-one*) ...)<br>
   (otherwise ...))<br></blockquote><div><br>To be honest, if I had to write such a test, I would rather find another way to do what I want (e.g. using cond). This looks ugly.<br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

<br>
<br>
Also, given run-time evaluation, I'd accept only OTHERWISE for the default clause, and leave T as a normal constant symbol to be evaluated and tested against, because T is a common value in lisp programs, while OTHERWISE is not.<br>
</blockquote><div><br>This would make <i style="font-family: courier new,monospace;">switch</i> inconsistent with <i><span style="font-family: courier new,monospace;">case</span></i>, but I will not object if T is treated as a normal constant symbol.<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br><br>
At first I wouldn't make it an error to include an OTHERWISE clause in ESWITCH or CSWITCH, just a warning.  For me, ESWITCH means "I cover all the cases", and if I use OTHERWISE to do so, good for me!  On the other hand, I would understand the choice of making it an error. In this case, please add a mention to use SWITCH instead of ESWITCH/CSWITCH in the error message.<br>
</blockquote><div><br>I have no objections here.<br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br><br>I put 'function designator', but it could be 'funcallable'.  I don't know if funcallable CLOS objects are designators of functions.  But my point is that the function forms are evaluated.  I would reject: (switch x :test string= ...).<br>
</blockquote><div><br>
I also vote for the test function to be evaluated. In my opinion, anything funcallable should be usable, unless someone finds a specific reason why it shouldn't be so.<br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

<br><br>

SCASE could be written:<br>
<br>
(switch <string-expression> :test (function string=)<br>
  ("abc" ...)<br>
  ("def" ...)<br>
  ...<br>
  (otherwise ...))<br>
<br>
Note that when all the strings and the test function are literals (known at compilation-time), special run-time optimizations may apply.<br><font color="#888888">
<br>
<br>
-- <br>
__Pascal Bourguignon__<br>
<a href="http://www.informatimago.com" target="_blank">http://www.informatimago.com</a><br>
<br>
<br>
<br>
</font></blockquote></div><br>