MathGroup Archive 1999

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

Search the Archive

RE: List manipulation question

  • To: mathgroup at
  • Subject: [mg15907] RE: [mg15852] List manipulation question
  • From: "ELLIS, Luci" <EllisL at>
  • Date: Wed, 17 Feb 1999 23:33:47 -0500
  • Sender: owner-wri-mathgroup at

Try using a pair of replacement rules:
	Swap23[list_?VectorQ]:= list /.

The only problem you might have with this is if there are other elements in
the list with exactly the same values as the second and third parts (but
this is unlikely with real numbers).

Luci Ellis                         ph:61-2-9551-8881
Acting Senior Economist            fx:61-2-9551-8833
Financial & Monetary Conditions    ellisl at
Economic Analysis Department       GPO Box 3947
Reserve Bank of Australia          Sydney NSW 2001

-----Original Message-----
From: Maarten.vanderBurgt at [mailto:Maarten.vanderBurgt at]
To: mathgroup at
Subject: [mg15907] [mg15852] List manipulation question

*** This E-Mail has been checked by MAILsweeper ***

Dear all,

In the following piece of code I define a function Swap23 which is ment
to swap elements 2 and 3 in a list.
Executing the function on a simple list I get an error. Why do I get
this error? Why do I not get this error when I execute the commnad from
Swap23 "by hand" as is shown in In[4]?

Thanks for any help

Maarten van der Burgt
Icos Vision Systems

           temp = L[[2]];
          L[[3]] =temp;

In[2]:= mylist = {1,2,3};

In[3]:= Swap23[mylist]

Set::"setps": "\!\({1, 2, 3}\) in assignment of part is not a symbol."
Set::"setps": "\!\({1, 2, 3}\) in assignment of part is not a symbol."

Out[3]= {1,2,3}

In[4]:=   temp = mylist[[2]];
          mylist[[3]] =temp;

Out[4]= {1,3,2}

  • Prev by Date: Re: Dont Understand
  • Next by Date: Re: interpolatingfunction
  • Previous by thread: Re: List manipulation question
  • Next by thread: Re: List manipulation question