Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Function with optional default argument cannot cache
Replies: 2   Last Post: May 1, 2013 9:39 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
waku

Posts: 14
Registered: 1/27/11
Re: Function with optional default argument cannot cache
Posted: May 1, 2013 9:39 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Interesting. Looks like you'd need to cover the default value case
manually:

f[x_, y_] := f[x, y] = {Pause[1], x, y}
f[x_] := f[x, 2]

But arguably it should not be necessary.

vQ

On 05/01/2013 09:37 AM, Dan O'Brien wrote:
> Is there a discussion somewhere on why this is?
>
> In[1]:= $Version
> f[x_, y_: 2] := f[x, y] = {Pause[1], x, y}
> f[1, 2] // AbsoluteTiming
> f[1, 2] // AbsoluteTiming
> f[1] // AbsoluteTiming
> f[1] // AbsoluteTiming
>
> Out[1]= "9.0 for Microsoft Windows (64-bit) (January 25, 2013)"
>
> Out[3]= {1.014002, {Null, 1, 2}}
>
> Out[4]= {0., {Null, 1, 2}}
>
> Out[5]= {1.029602, {Null, 1, 2}}
>
> Out[6]= {1.014002, {Null, 1, 2}}
>






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.