Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #14371 > unrolled thread

Function with optional default argument cannot cache results

Started byDan O'Brien <danobrie@gmail.com>
First post2013-05-01 07:36 +0000
Last post2013-05-02 01:39 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Function with optional default argument cannot cache results Dan O'Brien <danobrie@gmail.com> - 2013-05-01 07:36 +0000
    Re: Function with optional default argument cannot cache results Roland Franzius <roland.franzius@uos.de> - 2013-05-02 01:39 +0000

#14371 — Function with optional default argument cannot cache results

FromDan O'Brien <danobrie@gmail.com>
Date2013-05-01 07:36 +0000
SubjectFunction with optional default argument cannot cache results
Message-ID<klqgl9$na4$1@smc.vnet.net>
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}}

[toc] | [next] | [standalone]


#14379

FromRoland Franzius <roland.franzius@uos.de>
Date2013-05-02 01:39 +0000
Message-ID<klsg47$t7q$1@smc.vnet.net>
In reply to#14371
Am 01.05.2013 09:36, schrieb Dan O'Brien:
> 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}}
>


?f

Global`f

f[1,2]={Null,1,2}

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

The value of expression input "f[1]" will not be compiled.

In contrast, "f[1,2]" has been set to it's value by the Set (=) 
statement on the right side of the definition (:=) during the first 
execution.

-- 

Roland Franzius

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web