[Date Index]
[Thread Index]
[Author Index]
Re: Bug in Default[] or Bug in My Understanding?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg89225] Re: [mg89201] Bug in Default[] or Bug in My Understanding?
*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>
*Date*: Fri, 30 May 2008 02:55:51 -0400 (EDT)
*References*: <200805291103.HAA27410@smc.vnet.net>
On 29 May 2008, at 20:03, Salvatore Mangano wrote:
> In[208]:= ClearAll[f] ;
> Default[f,2] = 0;
>
> In[210]:= f[a_, b_.] := a + b
>
> In[211]:= f[1]
> Out[211]= 1
>
> In[212]:= (* Now change Default *)
> Default[f,2] = 1;
>
> (* Note that Mathematica seems to recognize change *)
> In[213]:= ?f
> Global`f
> f[a_,b_.]:=a+b
>
> f/:Default[f,2]=1
>
>
> (* But not really! Expected 2 *)
> In[214]:= f[1]
> Out[214]= 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 6.0.2.0 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[1]:= ClearAll[f];
In[2]:= Default[f, 2] = 0;
In[3]:= f[a_, b_.] := a + b
In[4]:= f[1]
Out[4]= 1
In[5]:= Default[f, 2] = 1;
In[6]:= f[a_, b_.] := a + b
In[7]:= f[1]
Out[7]= 2
Andrzej Kozlowski
Prev by Date:
**ContourPlot3D appearance**
Next by Date:
**Re: Deleting parts of notebooks programmatically**
Previous by thread:
**Bug in Default[] or Bug in My Understanding?**
Next by thread:
**NDSolve with arrays**
| |