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

Switch and List

  • To: mathgroup at
  • Subject: Switch and List
  • From: HAY at
  • Date: Thu, 30 JAN 92 12:02:54 GMT

There are problems with using  ReplaceAll: it can replace to much -

In[]	Release[Hold[Switch[a,{a,{va}}]]/.List->Sequence] 
Out[]	va
Wrong: we wanted {va}

In[]	Release[Hold[Switch[{a},{a,va}]]/.List->Sequence] 
Out[]	va
Wrong: a does not match {a}.

Using ReplacePart instead of ReplaceAll corrects these and maybe faster:

In[] 	Release[
	    Sequence, {1,2,0}
Out[]	{va}

In[]	Release[
	    Sequence, {1,2,0}
Out[]	Switch[{a}, a, va, b, vb]

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

  • Prev by Date: Re: Pattern matching question
  • Next by Date: PDE's, the wave equation, and separation of variables
  • Previous by thread: Switch and List
  • Next by thread: PDE's, the wave equation, and separation of variables