Yet I am still puzzled as to what &run would achieve as opposed to run alone...
brianMon 9 Feb 2009
Yet I am still puzzled as to what &run would achieve as opposed to run alone
The expr run invokes the run method. The expr &run evaluates to a Func which when invoked will call the run method. Consider:
Int foo() { echo("foo called"); return 7 }
foo() => calls foo() and evaluates to 7
&foo() => returns foo() as a Func, but doesn't call foo
|->Int| func := &foo
func() => calls foo and evaluates to 7
Typically you use the curry operator to pass a method as a func for callbacks instead of wrapping it in a closure.
alexlamslMon 9 Feb 2009
Ah - so run is a method rather than a variable holding a closure.
Thanks for helping me to get my head round this one!
alexlamsl Mon 9 Feb 2009
Under the section Functions as Interfaces, there is a line of code which seems like a typo to me:
I might just happen not to know that this C/C++ feature is in Fan ;-)
helium Mon 9 Feb 2009
http://www.fandev.org/doc/docLang/Functions.html#currying
alexlamsl Mon 9 Feb 2009
So I have noticed afterwards :-)
Yet I am still puzzled as to what
&run
would achieve as opposed torun
alone...brian Mon 9 Feb 2009
The expr
run
invokes the run method. The expr&run
evaluates to aFunc
which when invoked will call therun
method. Consider:Typically you use the curry operator to pass a method as a func for callbacks instead of wrapping it in a closure.
alexlamsl Mon 9 Feb 2009
Ah - so
run
is a method rather than a variable holding a closure.Thanks for helping me to get my head round this one!