This is a truly beautiful example:
Not only are objects a generalization of recursive functions, but they could serve as a much more accessible explanation of the Y combinator and "tying the knot" than the usual approaches.(define math-object
(vector
(lambda (this n)
(if (zero? n) #t ((vector-ref this 1) this (sub1 n))))
(lambda (this n)
(if (zero? n) #f ((vector-ref this 0) this (sub1 n))))))
> ((vector-ref math-object 0) math-object 5)
#f
No comments:
Post a Comment