a summary of "Switch and List" (or anything you can do one way with M, you can do 50 other ways)

To: mathgroup at yoda.physics.unc.edu

Subject: a summary of "Switch and List" (or anything you can do one way with M, you can do 50 other ways)

From: gaylord at ux1.cso.uiuc.edu

Date: Wed, 29 Jan 1992 02:35:53 -0600

a summary:
Allen Hay of the UK sent in the following question:
how do I eliminate the braces in Switch[expr, {form1, val1, form2, val2,
form3, val3}]
I suggested using
Switch[expr, {form1, val1, form2, val2, form3, val3}]/.List->Sequence
this works but it also produces (as a side effect) the (non-error) message
Switch::argct: Switch called with 2 arguments.
i suggested just turning the message off
Off[Switch::argct]
Switch[expr, {form1, val1, form2, val2, form3, val3}]/.List->Sequence
one person (name lost, sorry) responded to my response as follows:
try Apply[Switch, Prepend[{form1, val1, form2, val2, form3, val3}, expr]]
which is based on M working from right to left.
another person (Jerry Keiper of WRI) sent in the following response:
You don't need to turn off any messages. Just don't evaluate it until
it has the right number of arguments:
In[1]:= Release[Hold[Switch[expr, {form1, val1, form2,
val2}]]/.List->Sequence]
Out[1]= Switch[expr, form1, val1, form2, val2]
these all work.