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 1999

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

Search the Archive

Re: List manipulation question

  • To: mathgroup at
  • Subject: [mg15944] Re: List manipulation question
  • From: Eckhard Hennig <hennig at>
  • Date: Wed, 17 Feb 1999 23:34:07 -0500
  • Organization: ITWM
  • References: <7a2b7v$>
  • Sender: owner-wri-mathgroup at

Maarten.vanderBurgt at schrieb in Nachricht
<7a2b7v$1t6 at>...
>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]?

Dear Marten,

you get error message because Mathematica replaces the parameter L in your
function by the value of mylist. This causes Swap23 to make an invalid
assignment of the form

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

To prevent Mathematica from evaluating L prematurely, use the attribute

SetAttributes[Swap23, HoldAll]

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



Dipl.-Ing. Eckhard Hennig      mailto:hennig at
Institut fuer Techno- und Wirtschaftsmathematik e.V. (ITWM)
Erwin-Schroedinger-Strasse,  67663 Kaiserslautern,  Germany
  Voice: +49-(0)631-205-3126    Fax: +49-(0)631-205-4139

     ITWM - Makers of Analog Insydes for Mathematica

  • Prev by Date: Win 98 Printing Problems
  • Next by Date: Outgoing wave boundary conditions with NDSolve
  • Previous by thread: Re: List manipulation question
  • Next by thread: Re: List manipulation question