MathGroup Archive 1991

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

Search the Archive

Re: Switch and List: How to combine?

  • To: mathgroup at
  • Subject: Re: Switch and List: How to combine?
  • From: PERKINS TYLER R <perkins at>
  • Date: Tue, 15 Oct 91 17:58:43 -0600

fink at (Howard Fink) writes:
> Switch[expr,form1,val1,form2,val2,...] evaluates expr, matches it to form i,
> and returns val i, if there's a match, Null otherwise.  When I put in a list
> {form1,val1,form2,val2,...} Mathematica treats it as a single object, and
> for the life of me I can't strip off the curly brackets.  The closest I came
> was with Sequence, which replaced the curly brackets with parentheses.

levy at (Silvio Levy) writes:
> Switch @@ Prepend[{form1,val1,form2,val2,...}, expr] ought to work.

Yeah!  How about:
Switch @@ Join[{expr}, {form1,val1,form2,val2,...}]

or my favorite:
Switch[ expr, Release[Sequence @@ {form1,val1,form2,val2,...}] ]

The Release in the latter is necessary because Switch has attribute HoldAll.
This may be why your (Howard's) attempt at using Sequence failed.

	Tyler Perkins
	perkins at

  • Prev by Date: Mathematica class
  • Next by Date: Bug report: Graphics`ArgColors`
  • Previous by thread: Switch and List: How to combine?
  • Next by thread: Re: Switch and List: How to combine?