Closed
Description
Currently, all commands which need to identify a robot (e.g. install
, give
, reprogram
) take a string
identifying the robot by name. We also store robots by name internally in the robotMap
. However, this has several disadvantages: it's not very type safe (for example, are you supposed to give "base" "tree"
or give "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 by Int
. Here are my current thoughts:
- Add a new base type
robot
. - Change the type of any commands that currently take or return the name of a robot:
give : robot -> string -> cmd ()
install : robot -> string -> cmd ()
reprogram : robot -> cmd a -> cmd ()
build : cmd a -> cmd robot
- Note that robots can still have a name, which is displayed when they are
view
ed. But the name no longer needs to be unique. - However, note that the
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. - However, we can add a command
setname : string -> cmd ()
which lets a robot set its display name. - Internally, we can add a new type of
Value
,VRobot :: Int -> Value
. It can pretty-print as something liker105
or<105>
, it doesn't really matter that much. - What about robots that want to e.g.
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 variablechild <- build {move; thing <- grab; turn back; move; give parent thing}
base : robot
which is a reference to the base. - We might also want to add a way to get the results of previous commands entered at the REPL, so if you did
build
and forgot to bind the result to something, it's not lost forever.
Metadata
Assignees
Labels
Should take a moderate amount of time to address.An issue having to do with robots.Issues relating to the overall design of the Swarm language.The bug fix or feature would be nice but doesn't currently have much negative impact.A new feature to be added to the game.This issue is about restructuring the code without changing the behaviour to improve code quality.