MathGroup Archive 2007

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

Search the Archive

Re: How to manipulate globals in a function?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73715] Re: [mg73665] How to manipulate globals in a function?
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sun, 25 Feb 2007 04:39:35 -0500 (EST)
  • Reply-to: hanlonr at cox.net

Use HoldFirst to make the first argument to Moo a Symbol vice a List.

ClearAll[Moo];
SetAttributes[Moo,{HoldFirst}];
Moo[A_Symbol,i_Integer?Positive]:=A[[i]]=7;

A=Table[Random[],{5}];

Moo[A,1];

Verifying that A has been modified:

A

{7,0.359118,0.568554,0.0996048,0.856377}


Bob Hanlon

---- davisjf at gmail.com wrote: 
> I am trying to write code to manipulate a global array in a function.
> How do something like this:
> 
> Moo [A_List, i_Integer] :=
> 
>       A[[i]] = 7;
> 
> Moo[A, 1]
> 
> This fails.  But, if I do this without a funciton it works.
> 
> i=1
> A[[i]] = 7
> 
> JD



  • Prev by Date: Re: reliability function drawing
  • Next by Date: Re: How to manipulate globals in a function?
  • Previous by thread: How to manipulate globals in a function?
  • Next by thread: Re: How to manipulate globals in a function?