2 ms·
Do you mean like this? In [1]: def foo(f, a): ...: return f(foo, a) ...: In [2]: foo(lambda f, a: f(lambda f, a: a, a-1) if a > 0 else a, 1
by Sean1708 9y ago
Do you mean like this?
In [1]: def foo(f, a):
...: return f(foo, a)
...:
In [2]: foo(lambda f, a: f(lambda f, a: a, a-1) if a > 0 else a, 10)
Out[2]: 9
Obviously that's a completely useless and convoluted example, but I'm fairly sure the concept of a lambda calling the function it was passed to just works in most languages.
- jfoutz 9y agoit was a stupid joke about the y combinator. you can arrange a version with more function arguments that'll call all of the parts with their lambda friends. so they can all call each other. so something vaguely like (define local-state) (super-y (lambda (inc get set v) (set inc get set (+ 1(get inc get set v))))) ;this one is inc (lambda (inc get set v) local-state) ;this one is get (lambda (inc get set v) (set! local-state v)) ; this one is set you don't really even need local state, just pass around an accumulator. Once you have lambdas and a system that allows infinite types, mutual visibility is pretty easy to come by, mutual anonymous recursion is something i think is super nifty. you can save yourself some pain by sticking the functions in a map, of course and passing that around instead.