[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Limitation with lambda
There seems to be a gross omission in the lambda primitive. It seems like
there is no way to create a recursive function on the fly! I'm reading
the Abelson and Sussman book but they seem to avoid this issue.
For example, how would someone write a function generator that generates the
sum of all squares or cubes or fourths, etc., based on an exponent?
Bear with me, as I'm not a Scheme expert.
My specific problem arises from trying to write a simple object-oriented
mini-adventure in Scheme. There are two types of objects: players and rooms.
Rooms have four exits. Given a direction and a player, the room will move the
player to the new room in that direction.
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!
One possible solution is to change the communication method so that
players merely ask the room where the exit goes and move THEMSELVES. But
that's not the way I wanted to do it.
Help! What can I do?
-Jonathan Dubman