Closed byorgey closed 2 years ago
What should parent return if the parent no longer exists? Should it return a handle to a non-existent robot or should it fail immediately?
I think it would be safe to return a handle to a non-existent robot (but I could be convinced otherwise). We would just have to make sure that robot handles are never reused, but that should be easy.
I don't think it should fail immediately if the parent doesn't exist. That would provide a way to instantly communicate a bit of information over any distance. =)
I would also like to have some function for robots to detect each other in the wild - say meet : cmd (() + robot)
. :robot:
Agreed! meet : cmd (() + robot)
sounds great. I presume if there is more than one robot there, you just get an arbitrary one? Maybe later there could be a meetAll : cmd (list (robot))
.
Currently, all commands which need to identify a robot (e.g.
install
,give
,reprogram
) take astring
identifying the robot by name. We also store robots by name internally in therobotMap
. However, this has several disadvantages: it's not very type safe (for example, are you supposed togive "base" "tree"
orgive "tree" "base"
? And if you misspell the name of a robot, it fails at runtime instead of typechecking time), and necessitates frequent, relatively costly string comparisons.The basic idea is to add a new type
robot
which is opaque to the user but is internally represented byInt
. Here are my current thoughts:robot
.give : robot -> string -> cmd ()
install : robot -> string -> cmd ()
reprogram : robot -> cmd a -> cmd ()
build : cmd a -> cmd robot
view
ed. But the name no longer needs to be unique.build
command doesn't take a name any more; in many cases players are probably fine with giving it a descriptive variable name (e.g.lambda_getter <- build get_lambda
), but never plan toview
it so don't really care what its "display name" is.setname : string -> cmd ()
which lets a robot set its display name.Value
,VRobot :: Int -> Value
. It can pretty-print as something liker105
or<105>
, it doesn't really matter that much.give
something back to, say, the base? How can they get a reference to it? I propose adding a special variableparent : robot
which is always a reference to a robot's parent (i.e. the robot that built it). So the code for building a robot to get you a thing might look like this:While we're at it we could also add a special global variable
base : robot
which is a reference to the base.build
and forgot to bind the result to something, it's not lost forever.