MathGroup Archive 1999

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

Search the Archive

Re: Working in Modules

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15878] Re: Working in Modules
  • From: dreissBLOOP at bloop.earthlink.net (David Reiss)
  • Date: Wed, 17 Feb 1999 23:33:32 -0500
  • Organization: EarthLink Network, Inc.
  • References: <7a2c0d$1ul@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <7a2c0d$1ul at smc.vnet.net>, phrje at mimosa.csv.warwick.ac.uk (Dr D
McK Paul) wrote:

> This is my third attempt to post this question. No idea why it doesnt
> work. 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
> -- 
> ****************************************************** 
> Professor Don McKenzie Paul
> Department of Physics
> University of Warwick


In the case of init the command s/.{0->-1};  replaces the 
0's in s by -1's but does not change s.  Thus, when 
Partition[s,n] is called, it returns a value based on the
unchanged s.

This would work:

init[n_Integer]:=Module[
                     {s=Table[Random[Integer],{n n}], s1},
                     s1=s/.{0->-1};
                     Partition[s1,n]
                     ]


--David
with no substitutions for

-- 


   
----------------------------------------
 
Scientific Arts:
Creative Services and Consultation 
for the Applied and Pure Sciences 

David Reiss 
Email: dreiss at !SPAMscientificarts.com 

----------------------------------------
 


Remove the !SPAM to send email


  • Prev by Date: Re: Working in Modules
  • Next by Date: Re: Notebook -> Kernel
  • Previous by thread: Re: Working in Modules
  • Next by thread: Re: Working in Modules