Re: Please Help Eliminate My Ignorance
- To: mathgroup at smc.vnet.net
- Subject: [mg118558] Re: Please Help Eliminate My Ignorance
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Tue, 3 May 2011 05:44:10 -0400 (EDT)
In the first cell, test is defined using SetDelayed, so Append isn't evaluated, yet. It won't be evaluated until you evaluate test[someArgument]. For clarity, the second cell should look like this: Clear[x, testp, p]; test[p_] := x = 1 Append[p, p[[4]]]; In the second cell, Append is not part of the "test" definition. It's a statement all by itself, evaluated immediately. p has just been cleared, so it has no fourth part, and it's not a List, so you can't append to it. Bobby On Mon, 02 May 2011 05:52:02 -0500, Michael Mandelberg <mmandelberg at comcast.net> 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]]]. >> > -- DrMajorBob at yahoo.com