Skip to content
scrambled
Programming Language Theory Flashcard

How to allow methods to reference each other using lexical scoping?

Books Deckgeneral

Question

How to allow methods to reference each other using lexical scoping?

Answer

With mutation:

racket
(define (mk-obj args)
	(let ([self 'dummy])
		(begin
			(set! self
				(lambda (m)
					(case (m)
						[(first) (lambda (x) (self 'second x))]
						[(second) (lambda (x) x)])))
			self)))