MathGroup Archive 1995

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

Search the Archive

Re: A simple swap function

  • To: mathgroup at
  • Subject: [mg2165] Re: A simple swap function
  • From: ianc (Ian Collier)
  • Date: Wed, 11 Oct 1995 01:58:41 -0400
  • Organization: Wolfram Research, Inc.

In article <44qj8g$s22 at>, valentin at (William F.
Campbell) wrote:

>   I think I must be missing something straightforward.  I want a function
> to swap the values of 2 lists.  I defined ab={a,b}, and ba={b,a}, and
> swap[v1_,v2_]:=Module[{temp=v1},v1=v2;v2=temp;], and I get an Iteration
> limit exceeded error.  When I look at ab, it looks like {Hold[a],Hold[b]}
> (or maybe {Hold[b],Hold[a], I don't remember), and ba looks opposite.  When
> I tried to use the same function on numbers, it didn't work either.  What's
> wrong with what I'm doing, and how can I do what I want to do?

Well, in this example you can simply use the Reverse function to
swap your values:

    ab = {a,b}
    {a, b}
    ba = Reverse[ ab ]
    {b, a}

I hope this helps.


Ian Collier
Technical Sales Support
Wolfram Research, Inc.
tel:(217)-398-0700     fax:(217)-398-0747      ianc at
Wolfram Research Home Page:   

  • Prev by Date: Re: Simplifying vector expressions
  • Next by Date: What am I doing wrong?
  • Previous by thread: Re: A simple swap function
  • Next by thread: Re: Re: A simple swap function