The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Function with optional default argument cannot cache results
Replies: 1   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 ]
Dan O'Brien

Posts: 11
Registered: 4/10/10
Function with optional default argument cannot cache results
Posted: May 1, 2013 3:36 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.