Re: delegate support in euphoria?
- Posted by mattlewis (admin) Apr 20, 2012
- 1452 views
hello, I'm a beginner, I would like to know if Euphoria supports the delegate concept, also known as: callbacks, anonymous functions.
for example, a 'retain' function filters a sequence based on a predicate (a func that returns a boolean). retain would take the sequence and the predicate as its two parameters.
now the programmer can use this construct, as an abstraction for later work that only differs by the arguments. (no need to write the same code when the "block" can be passed from outside)
Yes. The function routine_id() can be used to get an handle to any procedure or function and then that handle can be passed as an argument to a routine, which would call the handle's routine using either the call_func() or call_proc() as appropriate.
There was a related thread a little while ago, talking about function composition in euphoria, which you might find interesting:
http://openeuphoria.org/forum/114817.wc
Matt