#451 JavaFFI docs

alexlamsl Mon 9 Feb 2009

Under the section Functions as Interfaces, there is a line of code which seems like a typo to me:

execute(&run)

I might just happen not to know that this C/C++ feature is in Fan ;-)

alexlamsl Mon 9 Feb 2009

So I have noticed afterwards :-)

Yet I am still puzzled as to what &run would achieve as opposed to run alone...

brian Mon 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.

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!

Login or Signup to reply.