MathGroup Archive 1992

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

Search the Archive

Switch and List

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: Switch and List
  • From: HAY at leicester.ac.uk
  • 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[
		  ReplacePart[
		    Hold[Switch[a,{a,{va}}]],
	    Sequence, {1,2,0}
	  ]
	] 
Out[]	{va}

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



From
Allan Hayes
Department of Mathematics
The University
Leicester LE1 7RH
U.K.
hay at leicester.ac.uk





  • 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