Skip to content

Instantly share code, notes, and snippets.

@yosun
Last active July 1, 2024 08:33
Show Gist options
  • Save yosun/0fa4ecf992513f6a22448c0dcd882425 to your computer and use it in GitHub Desktop.
Save yosun/0fa4ecf992513f6a22448c0dcd882425 to your computer and use it in GitHub Desktop.
Another Ycombinator and LOVE - in reminiscing an old blog post from my late friend Chieu Nguyen (the scheme and postscript versions are also @ ) https://minimonimania.wordpress.com/2008/12/03/yajima-combinator/
# (printing “LOVE” an infinite number of times using named recursion in Python)
def FOREVER(x):
print x,
FOREVER(x)
FOREVER("LOVE")
#(the Y combinator in Python)
(lambda f: \
(lambda x: f(lambda y: (x(x))(y))) \
(lambda x: f(lambda y: (x(x))(y))))
#(printing “LOVE” an infinite number of times using the Y combinator to do anonymous recursion in Python, theoretically)
(lambda f: \
(lambda x: f(lambda y: (x(x))(y))) \
(lambda x: f(lambda y: (x(x))(y)))) \
(lambda p: (lambda s:(s + p(s)))) \
('LOVE ')
#Of course, you won’t be able to see anything from running that last one. But you can use the Y combinator to print out “LOVE” a finite number of times:
#(printing “LOVE” 17 times using the Y combinator to do anonymous recursion in Python)
(lambda f: \
(lambda x: f(lambda y: (x(x))(y))) \
(lambda x: f(lambda y: (x(x))(y)))) \
(lambda p: (lambda s: (s==0 and ' ') or ('LOVE ' + p(s-1)))) \
(17)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment