MathGroup Archive 2010

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

Search the Archive

Re: How to Explain This Behavior of Simple Procedures?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109634] Re: How to Explain This Behavior of Simple Procedures?
  • From: schochet123 <schochet123 at gmail.com>
  • Date: Sun, 9 May 2010 07:49:59 -0400 (EDT)
  • References: <hs3gjn$ru6$1@smc.vnet.net>

Set ( = ) does not evaluate its first argument (the lhs) by default,
so you need to use Evaluate to tell it to do so. Just replace
 lhs[[1]] = rhs by Evaluate[lhs[[1]]]=rhs

Steve

On May 8, 2:06 pm, James Stein <mathgr... at stein.org> wrote:
>
> But this method, where f receives the variable differently, fails:
>
> *Input:*
>
> ClearAll [f, g];
> f [lhs_List, rhs_] := lhs[[1]] = rhs;
> g[rhs_] := Module[{localVar},
>    f [{localVar}, rhs];
>    Print["g: localVar=", localVar];
>    ];
> g[44];
>
> *(printed) Output:*
>
> g: localVar=localVar$313085
>
> In addition, there is an error message:
>
> Set::setps :
>
>   (localVar$313085} in the part assignment is not a symbol.
>
> which is curious because:
>
> Head[localVar$313085] returns Symbol.



  • Prev by Date: Re: How to write reports and books in Mathematica
  • Next by Date: Re: Variables in Iterator limits?
  • Previous by thread: Re: How to Explain This Behavior of Simple Procedures?
  • Next by thread: Re: How to Explain This Behavior of Simple Procedures?