pierce@lanai.cs.ucla.edu (10/18/88)
**Players have a current room. They accept two messages: 'move direction and
**'hop new-room. Say you tell a player to go north. He knows his current
room
**and asks that room to send him north. But how can that happen, if the
player
**doesn't know his own name? Make-player, which is a call to a lambda, can't
**tell the current room to move the player in the given direction because the
**player isn't defined until after the lambda is finished!
;; Such things are easy to do with lambdas. In fact, an object which couldn't
;; know about itself wouldn't really be very recursive.
;; Here's an elementary example of an object that knows about itself.
(define (make-self-knowledge-object)
(let ((state-variable 0) (myself 'any))
((lambda (object) (set! myself object) object)
(case-lambda
((int)
(set! state-variable (+ state-variable int))
state-variable)
(() myself)))))
;; Don't be worried about asking "dumb questions", after all the goal of
;; many people that read this group is to get people to love scheme.
;; -- Brad
P.S.
> (define x (make-self-knowledge-object))
x
> (eq? x (x))
#t
> (x 1)
1
> ((x) 1)
2
> (x 1)
3
>