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


Groups > comp.soft-sys.math.mathematica > #2063 > unrolled thread

Re: Please Help Eliminate My Ignorance

Started bySseziwa Mukasa <mukasa@gmail.com>
First post2011-05-03 09:48 +0000
Last post2011-05-03 09:48 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: Please Help Eliminate My Ignorance Sseziwa Mukasa <mukasa@gmail.com> - 2011-05-03 09:48 +0000

#2063 — Re: Please Help Eliminate My Ignorance

FromSseziwa Mukasa <mukasa@gmail.com>
Date2011-05-03 09:48 +0000
SubjectRe: Please Help Eliminate My Ignorance
Message-ID<ipoj1c$g9d$1@smc.vnet.net>
On May 2, 2011, at 6:52 AM, Michael Mandelberg wrote:

> Why does Mathematica like the first, but not the second?
>
> 1.
> Clear[x, testp, p];
> test[p_] :=  Append[p, p[[4]]];
>
>
> 2.
> Clear[x, testp, p];
> test[p_] := x = 1; Append[p, p[[4]]];
>
> Part::partd: Part specification p[[4]] is longer than depth of object.
>>>
>
> Append::normal: Nonatomic expression expected at position 1 in
> Append[p,p[[4]]]. >>

Your second case is a compound statement and the parts are evaluated independently.  If you want to assign 1 to x in test wrap it in a scoping construct:

test[p_]:=Block[{},x=1;Append[p,p[[4]]]]

Regards,
	Ssezi

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web