Services & Resources / Wolfram Forums
MathGroup Archive
*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

Re: Switch and List: How to combine?

  • To: mathgroup at
  • Subject: Re: Switch and List: How to combine?
  • From: HAY at
  • Date: Mon, 27 JAN 92 22:17:36 GMT

I've had problems with the mail so I'm repeating this.

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.  

The following extended version of Switch deals with this problem and retains the
HoldAll attribute of Switch; so does not force evaluation of all arguments. It
may therefore be quicker for some applications.

SetAttributes[SwitchList, HoldAll]
SwitchList[expr_, {x___}] := Switch[expr,x]
SwitchList[expr_,x___] := Switch[expr,x]

If you don't mind altering Switch itself then you can extend it by

Switch[expr_, {x___}] := Switch[expr,x]

Allan Hayes
Department of Mathematics
The University
Leicester LE1 7RH
hay at

  • Prev by Date: Re: tex-mma
  • Next by Date: Re: Limit of Bessel functions
  • Previous by thread: Re: tex-mma
  • Next by thread: Switch and List