Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx01.iad01.newshosting.com!newshosting.com!novia!newspump.sol.net!posts.news.twtelecom.net!nnrp2.twtelecom.net!not-for-mail From: "Sjoerd C. de Vries" Newsgroups: comp.soft-sys.math.mathematica Subject: Re: Please Help Eliminate My Ignorance Date: Tue, 3 May 2011 09:46:38 +0000 (UTC) Organization: Steven M. Christensen and Associates, Inc and MathTensor, Inc. Sender: steve@smc.vnet.net Approved: Steven M. Christensen , Moderator Message-ID: References: Lines: 33 NNTP-Posting-Date: 03 May 2011 08:47:26 GMT NNTP-Posting-Host: 44dd737d.news.twtelecom.net X-Trace: DXC=M3ji\BW=eLZSW6MMT7Gj0ZC_A=>8kQj6];[h;PUXBgbTe6cLf4b_YJSEFiONJ7[GoVf2TnHTJ6[hQ X-Complaints-To: abuse@twtelecom.net Xref: x330-a1.tempe.blueboxinc.net comp.soft-sys.math.mathematica:2053 In 1. because of SetDelayed (:=) the Part ([[ ]]) statement is not executed directly. It lays dormant until test is called. In 2. Append and the Part contained in it are executed immediately. Here the problem with p being not a List that can be indexed directly leads to an error message. If you call test in 1. with a argument that is not a list you get the same error message. Cheers -- Sjoerd Mathematica questions also answered at Stackoverflow: http://stackoverflow.com/questions/tagged/mathematica May 2, 12:52 pm, 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]]]. >>