Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #8308
| From | Louis Talman <talmanl@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Funny Behavior of Module |
| Date | 2012-02-03 07:10 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jgg195$bnb$1@smc.vnet.net> (permalink) |
I know that Module exhibits some funny behavior, but this behavior is
something I've never seen before. It seems wrong to me.
In a new kernel session enter
f[x_] := Module[{a},a = x^2; x = y; a]
f[z]
z
Mathematica returns y for z, as it ought to. (In fact, the purpose of
the code was to demonstrate to students what can happen when a Module
monkeys with its formal parameters.)
But f[z] returns y^2. It seems to me that it should return z^2, but that
for some reason it's interpreting the first Set instruction in the body
of the Module as a SetDelayed instruction. (We get exactly the same
behavior if we replace that Set with SetDelayed in the code.)
Can anyone explain what's going on here? ITABOAF?
--Lou Talman
Department of Mathematical & Computer Sciences
Metropolitan State College of Denver
<http://rowdy.mscd.edu/%7Etalmanl>
Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread
Funny Behavior of Module Louis Talman <talmanl@gmail.com> - 2012-02-03 07:10 +0000 Re: Funny Behavior of Module "Oleksandr Rasputinov" <oleksandr_rasputinov@ymail.com> - 2012-02-04 11:28 +0000 Re: Funny Behavior of Module Roger Wilson <rogerhw999@gmail.com> - 2012-02-04 11:39 +0000 Re: Funny Behavior of Module "Nasser M. Abbasi" <nma@12000.org> - 2012-02-04 11:40 +0000
csiph-web