"logo.gif"  
Main
Read Online
Download PDF
Additional resources
Revision history
Known typos/bugs
Report a bug
License terms
About the author
"node301_1.gif" "node301_2.gif" "node301_3.gif"

3.6.6.1     Simple uses of Part

If it is necessary to replace some element of the list with a known address with some new expression or value (say, symbol <a>), this can be done directly. Here are our lists:

"node301_4.gif"

"node301_5.gif"

"node301_6.gif"

Say, we now want to replace the element with the address {5} with <a>:

"node301_7.gif"

"node301_8.gif"

Now, let us now in our list <complextestlist> replace a random element in every sublist with <a>:

"node301_9.gif"

"node301_10.gif"

"node301_11.gif"

Notice that such modifications as described above are only possible if lists are stored in some variable (in C we would say, that it is an L-value). In particular, this input is a mistake:    

"node301_12.gif"

"node301_13.gif"

"node301_14.gif"

Essentially, in all the above examples the Part command ([[ ]] ) was used for modification of expressions.

Note also that the modification of lists with Part introduces side effect, since it is the original variable where the list is stored that is modified, not the copy of the list.

"node301_15.gif" "node301_16.gif" "node301_17.gif"

Created by Wolfram Mathematica 6.0  (05 February 2009) Valid XHTML 1.1!