Multiple distinct objects: Difference between revisions

Content deleted Content added
Line 349: Line 349:


=={{header|Mathematica}}==
=={{header|Mathematica}}==
<lang Mathematica>The mistake is often written as:
The mistake is often written as:
<lang Mathematica>{x, x, x, x} /. x -> Random[]</lang>


{x, x, x, x} /. x -> Random[] # here Random[] can be any expression that returns a new value
Here Random[] can be any expression that returns a new value which is incorrect since Random[] is only evaluated once. e.g.

which is incorrect since Random[] is only evaluated once. e.g.
{0.175125, 0.175125, 0.175125, 0.175125}
{0.175125, 0.175125, 0.175125, 0.175125}


A correct version is:
A correct version is:


{x, x, x, x} /. x :> Random[]</lang>
<lang Mathematica>{x, x, x, x} /. x :> Random[]</lang>
which evaluates Random[] each time e.g.
which evaluates Random[] each time e.g.