Thursday, June 02, 2005

Deep ideas lurking in Object-Oriented Style, part II

The other important Deep Idea in Object-Oriented Style is the connection between object-oriented programming and recursion. He's not the first to notice this by any stretch of the imagination. This was the central idea in Cook and Palsberg's denotational semantics of inheritance. But it's an important idea that isn't well-enough understood, especially since recursion is so poorly understood in the OOP community.

This is a truly beautiful example:
(define math-object
(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)
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.

No comments: