Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #4762

Re: Visibility of value of variable bindings in module

From "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Visibility of value of variable bindings in module
Date 2011-09-05 11:23 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j42bf2$ru4$1@smc.vnet.net> (permalink)
References <j40spg$l13$1@smc.vnet.net>

Show all headers | View raw


On Sun, 04 Sep 2011 23:06:40 +0100, caw <cawright.99@gmail.com> wrote:

> Hi
>
> Module[{x = Sum[i, {i, Length[{1, 2, 3}]}], y = x + 1}, Print[y];
> Print[x]]
>
> prints out:
>
> 1 + x
> 6
>
> So, in the variable declaration section of the Module statement, the
> binding of x to 6 isn't visible to y.
> (It's a bit like let and let*, but not)
>
> Is there a form which will allow the bindings to be visible within the
> variable declaration section?
>
> thanks very much
>
> chris
>

No, there is not. Instead you must do:

Module[{x, y},
  x = Sum[i, {i, Length[{1, 2, 3}]}];
  y = x + 1;
  Print[y];
  Print[x]
]

or something logically equivalent. If you require these semantics  
frequently, you could easily write a function that takes a Module as an  
(unevaluated) argument and rewrites it into the required form before  
evaluating it.

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Visibility of value of variable bindings in module caw <cawright.99@gmail.com> - 2011-09-04 22:06 +0000
  Re: Visibility of value of variable bindings in module "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-09-05 11:23 +0000

csiph-web