[Date Index] [Thread Index] [Author Index]
Re: Bug in Default or Bug in My Understanding?
On 29 May 2008, at 20:03, Salvatore Mangano wrote: > In:= ClearAll[f] ; > Default[f,2] = 0; > > In:= f[a_, b_.] := a + b > > In:= f > Out= 1 > > In:= (* Now change Default *) > Default[f,2] = 1; > > (* Note that Mathematica seems to recognize change *) > In:= ?f > Global`f > f[a_,b_.]:=a+b > > f/:Default[f,2]=1 > > > (* But not really! Expected 2 *) > In:= f > Out= 1 > > Even if it is a rule that you can't change the Default after the > function is defined it is certainly not nice of Mathematica to allow > such a change and advertise the change in the output of Definition > and Information. > > I am using 220.127.116.11 on Windows XP. > I agree that this is confusing, but note that the documentation states pretty clearly: The necessary values for Default[f] must always be defined before _. is used as an argument of f. I think the implication is quite clear: if you change Default you will have to evaluate the defintion of f again. Note that this works as expected: In:= ClearAll[f]; In:= Default[f, 2] = 0; In:= f[a_, b_.] := a + b In:= f Out= 1 In:= Default[f, 2] = 1; In:= f[a_, b_.] := a + b In:= f Out= 2 Andrzej Kozlowski