Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

Re: List manipulation question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15898] Re: [mg15852] List manipulation question
  • From: BobHanlon at aol.com
  • Date: Wed, 17 Feb 1999 23:33:43 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 2/12/99 8:48:03 PM, Maarten.vanderBurgt at icos.be writes:

>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]?
>
 Maarten,

Use the following:

Swap23[L_List]:=Module
[
          {a = L, temp},
           temp = a[[2]];
          a[[2]]=a[[3]];
          a[[3]] =temp;
          a
]/; Length[L] > 2

myList = {1,2, 3};
Swap23[myList]

{1,3,2}


Bob hanlon


  • Prev by Date: Smarter 3D listplot clipping
  • Next by Date: RE: Re: accessing large files
  • Previous by thread: Re: List manipulation question
  • Next by thread: Re: List manipulation question