Skip to main content
22 events
when toggle format what by license comment
Feb 16, 2018 at 6:17 vote accept Eric
Jul 5, 2014 at 11:44 comment added Eric Also I noticed that a={g,h,j}; a[[1]]=6 is OK, whereas a[1]=6 is error.
Jul 5, 2014 at 11:35 comment added Eric er.. so what can we Set in general? It seemed setting a={g,h,j}; a[[0]]=6 is ok. So set something to expr and expr[i] and expr[[i]] is ok, what else?
Jul 4, 2014 at 22:28 answer added Richard Fateman timeline score: 5
Jul 4, 2014 at 21:19 answer added m_goldberg timeline score: 3
Jul 4, 2014 at 19:06 comment added Eric but Clear[f, g];f = g;f[x_] = x^4 the lhs of the last statement evaluated(f->g, g[x_]=x^4, by checking ?g) before assignment, so I guess {g,h,j}[[1]] will first evaluted to g, then do the assignment g=6
Jul 4, 2014 at 18:43 comment added acl @Eric because it tries to set Part[List[g, h, j], 1] to 6. Do FullForm[Hold[{g, h, j}[[1]] = 6]] to see that. This happens because Set has attribute HolfFirst, as nikie said.
Jul 4, 2014 at 18:36 comment added Niki Estner @Eric: You can use Attributes[Set] to find out which arguments are evaluated: It has the HoldFirst attribute, so the first argument isn't evaluated. You could write Evaluate[{g, h, j}[[1]]] = 6, though.
Jul 4, 2014 at 16:46 comment added Eric I understand part 1 of my question now. One more question. Clear[f, g];f = g;f[x_] = x^4, I can understand the result of ?g. However, why {g,h,j}[[1]]=6 causes error? When using =(Set), MMA first evaluate the first part f and {g,h,j}[[1]] to g and g right?(i.e. always evaluating lhs before assignment) Why is f[x_] = x^4 ok, but not {g,h,j}[[1]]=6? I think the internal form of them are equivalent.
Jul 4, 2014 at 14:34 comment added Albert Retey I think that this statement might have had in mind "pure functions" like (#^2)& or Function[x,(1+x)^3]. These quite obviously are normal expressions and functions. "function definitions" like f[x_]:=... in Mathematica are actually definitions for global rewrite rules (as others have explained in more detail) which just happen to have an intuitive interpretation as functions but conceptually are not different from rules which e.g. define variable values.
Jul 4, 2014 at 11:58 answer added Niki Estner timeline score: 18
Jul 4, 2014 at 11:31 review Close votes
Jul 5, 2014 at 20:49
Jul 4, 2014 at 11:12 comment added m_goldberg You have an urgent need to read this question and its answers -- all its answers. You also have an urgent need to read Chapter 7 of Wagner's book.
Jul 4, 2014 at 11:10 history edited m_goldberg CC BY-SA 3.0
Major clean-up
Jul 4, 2014 at 10:47 comment added Niki Estner Try to parse the expression x=(Sin + Cos)[a] - are Sin/Cos values or functions here? They're added like values, after all. Is Plus a function? Since it is "called" with [a]. Now call Through[x], and you'll get a perfectly sensible mathematical expression. Being able to manipulate expression trees like that is extremely useful.
Jul 4, 2014 at 10:44 comment added acl @Kuba I think first one needs to realise that everything is an expression (a tree), then that mma does rewriting (in some possibly hard to understand way) with these expressions, and only then those answers will be useful. Otherwise it's like explaining contour integrals to someone who doesn't understand the abstract notion of a derivative (but can find the gradient using a ruler, for instance).
Jul 4, 2014 at 10:30 comment added Kuba imo related: DownValues, UpValues, SubValues, and OwnValues
Jul 4, 2014 at 10:24 comment added acl The first part of your question may be answered by reading this
Jul 4, 2014 at 10:22 comment added acl In case 2, why should it erase anything? 9[2] is a perfectly valid expression with head 9. Case 1 results in a message for the same reason 9[2] = 3 does, ie, because Integer is protected. Try Unprotect[Integer]; 9[2] = 3.
Jul 4, 2014 at 10:18 comment added Nasser The f = 9; f[x_]:=x^2 error since now the second line reads as 9[x_]:=x^2
Jul 4, 2014 at 10:12 history edited Eric CC BY-SA 3.0
deleted 2 characters in body
Jul 4, 2014 at 10:07 history asked Eric CC BY-SA 3.0