Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

Re: Working in Modules

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

In article <7a2c0d$1ul at>, phrje at (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 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:

                     {s=Table[Random[Integer],{n n}], s1},

with no substitutions for


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

David Reiss 
Email: dreiss at ! 


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