I am trying to make a function with an optional argument that may change but mathematica caches the value when the function is defined.
Here is an example where the optional time variable is set when the function is defined.
Remove[CurrentTime]
CurrentTime[time_: DateList[]] := {time, DateList[]};
Pause[1]
CurrentTime[]
The output is split by 1 second
{{2013, 6, 4, 13, 57, 46.149504}, {2013, 6, 4, 13, 57, 47.150726}}
Is there a way to tell it its a delayed set, or to just read the function each time?
{DateList[], DateList[]}
; it stands to reason that some amount of time should have to pass in between the two times you callDateList[]
... $\endgroup$CurrentTime[OptionsPattern[{"Time" :> DateList[]}]] := {OptionValue["Time"], DateList[]}
. One could either doCurrentTime[]
orCurrentTime["Time" -> {2013, 6, 4, 12, 0, 0}]
... $\endgroup$