MathGroup Archive 1991

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

Search the Archive

Re: Switch and List: How to combine?

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

fink at acf5.nyu.edu (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 geom.umn.edu (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 spot.colorado.edu



  • Prev by Date: Re: Extracting variables nested in functions
  • Next by Date: Re: Extracting variables nested in functions
  • Previous by thread: Re: Switch and List: How to combine?
  • Next by thread: accuracy