A long time ago, in a galaxy far far away, during a Scheme course, we were given this example of lambda games:
(define (foo x)
(lambda (y) (x (x (x y)))))
Now, obviously ((foo 1+) 0)
will print 3. (1+
is the standard Scheme increment operator)
But the fun is that you can apply foo
over itself, and then you can do fun stuff like:
(((foo foo) 1+) 0)
which of course prints 27. And then there is the really funny:
(define a (foo foo))
(((a foo) 1+) 0)
I did this trick in CommonLisp, Clojure, Ruby, Python, Haskell, Erlang and Julia...
So the question arises, can you do it in Swift? I know you can do higher order functions, but can you create such functions which will be as 'reflexive' as in pure functional languages?
Tx!