Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1992
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1992

[Date Index] [Thread Index] [Author Index]

Search the Archive

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.









  • Prev by Date: Re:Wordwrapping in matrices
  • Next by Date: Re: Pattern matching question
  • Previous by thread: Re: Pattern matching question
  • Next by thread: Mouse Input on X-Windows