Re: Dont Understand
- To: mathgroup at smc.vnet.net
- Subject: [mg15936] Re: [mg15857] Dont Understand
- From: "Tomas Garza" <tgarza at mail.internet.com.mx>
- Date: Wed, 17 Feb 1999 23:34:03 -0500
- Sender: owner-wri-mathgroup at wolfram.com
Don McKenzie Paul wrote:
>I'm not an expert in Mathematica and would appreciate comments on why
>init1 returns a list with all zeros replaced by -1, but init does not.
>Its probably very simple but its confused me.
>Don
>init[n_Integer]:=Module[
{s=Table[Random[Integer],{n n}]},
s/.{0->-1};
Partition[s,n]
]
>init1[n_Integer]:=Module[
{s=Table[Random[Integer],{n n}]},
s/.{0->-1}
]
Don,
In init you use a transformation rule on s, but never assign the result to
something. Hence the Partition is applied to the original s. Try something
like
init[n_Integer]:=Module[
{s=Table[Random[Integer],{n n}]},
z=s/.{0->-1};
Partition[z,n]
]
However, in init1 you perform the transformation without a semicolon at the
end, hence the result is simply displayed on the screen -- you can do
nothing with it until you assign it to a symbol.
Good luck,
Tomas Garza
Mexico City