MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Why do I need this unused default value?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg62713] Why do I need this unused default value?
  • From: "Steven T. Hatton" <hattons at globalsymmetry.com>
  • Date: Fri, 2 Dec 2005 05:53:11 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

This is based on an example from _The Mathematica GuideBook for
Programming_, section 5.2.

In[n]:= Remove[f, p];
SetAttributes[p, {OneIdentity}];
f[p[x_:"bogus"]] := {"yes",x};
f[d]

Out[n+3]:= {yes, d}

In[n]:= f[]

Out[n]:= f[]

It appears to me that the default value for x_ will never be applied.
Nonetheless, if it is absent, the pattern is not matched. 

In[n]:= Remove[f, p];
SetAttributes[p, {OneIdentity}];
f[p[x_]] := {"yes", x};
f[d]

Out[n+3]:= f[d]

I really don't know how to explain what's happening with this.  Can someone
else explain this behavior?

-- 
The Mathematica Wiki: http://www.mathematica-users.org/
Math for Comp Sci http://www.ifi.unizh.ch/math/bmwcs/master.html
Math for the WWW: http://www.w3.org/Math/


  • Prev by Date: Re: solving simultaneous coupled differential equations
  • Next by Date: Using ConversionRules to generate labels in TeX
  • Previous by thread: Re: solving simultaneous coupled differential equations
  • Next by thread: Using ConversionRules to generate labels in TeX