Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #14382
| From | Waclaw Kusnierczyk <waku@idi.ntnu.no> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Function with optional default argument cannot cache |
| Date | 2013-05-02 01:39 +0000 |
| Message-ID | <klsg4n$t86$1@smc.vnet.net> (permalink) |
| References | <20130501073754.8ADA36A27@smc.vnet.net> |
| Organization | Time-Warner Telecom |
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}}
>
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Function with optional default argument cannot cache Waclaw Kusnierczyk <waku@idi.ntnu.no> - 2013-05-02 01:39 +0000
csiph-web