Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

That's pretty neat, but imagine how cool it would be if there was some sort of function that would take a lambda as an argument, and then call that lambda with itself as the first argument! sort of split the lambda into a Y and combine it with itself.

I have a pretty good idea of what a scheme implementation is, but i'll leave the details as an exercise for the reader.



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.


it 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: