Re: Dont Understand
- To: mathgroup at smc.vnet.net
- Subject: [mg15903] Re: Dont Understand
- From: Martin Kraus <mkraus at theorie3.physik.uni-erlangen.de>
- Date: Wed, 17 Feb 1999 23:33:45 -0500
- Organization: Regionales Rechenzentrum Erlangen, Germany
- References: <7a2bm8$1ts@smc.vnet.net>
- 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} > ] > > -- > > Prof. Don McKenzie Paul tel. (1203) 523603 Department of > Physics fax. (1203) 692016 University of Warwick > email phrje at csv.warwick.ac.uk COVENTRY CV4 7AL > UK I think you just forgot to set s to its new value in init: s=s/.{0->-1} (instead of s/.{0->-1}), because if you do not set s, the replacement will have no effect in init. On the other hand in init1 the new value of s is returned as this is the last instruction in this module; thus, there is no need to set s to this value in this case. Hope that helps Martin Kraus