Forum Discussion
EnTerr
10 years agoRoku Guru
"RokuMarkn" wrote:
I've expanded the description of default parameter values in the doc.
Thanks Mark!
As an addendum, there are some caveats to the way default params work, as demonstrated by this:
BrightScript Debugger> f = function(x=upTime(0)): return x: end function: ? f()
1060.72
BrightScript Debugger> ? f()
1063.5
BrightScript Debugger> f = function(x=main): return x: end function: ? f()
<Function: main>
BrightScript Debugger> y = 7: f = function(x=1/y): return x: end function: ? f(8): ? f()
8
Use of uninitialized variable. (runtime error &he9)
In other words: if needed, the default value expression is evaluated at call time (i.e. every time a call is made - not at all obvious since say in Python defaults are calculated at definition-execution time; has some... schmonsequences). And the expression does not "see" the locals but sees the globals (user or system).