Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Robot to name or id and back #343

Closed
xsebek opened this issue May 28, 2022 · 13 comments
Closed

Robot to name or id and back #343

xsebek opened this issue May 28, 2022 · 13 comments
Labels
L-Language design Issues relating to the overall design of the Swarm language. Z-Meta This issue is about other Swarm issues or infrastructure.

Comments

@xsebek
Copy link
Member

xsebek commented May 28, 2022

This is a meta issue for discussion of the way we convert between robot, its name and id.

      self
       │
       ▼
   ┌─────────────┐◄───┐
   │current robot│    │setname
   └──────┬──────┴────┘
    whoami│
          └───►┌──────────┐
               │          │
┌─────────────►│robot name│◄───────────┐
│as r {whoami} │          │           ?│
│          ┌───┴──────────┴───┐        │
│          │find             ?│        │
│          ▼                  ▼        │
│ ┌──────────┐◄─────────────┬────────┐ │
└─┤          │      ?       │        ├─┘
  │robot type│              │robot ID│
┌─┤          │      ?       │        │
│ └──────────┴─────────────►└────────┘
│  ▲     ▲   ▲
└──┘     │   │
parent  base └─build

Why the robot ID? Because it is unique, stored in VRobot Int and printed in REPL:

> build {move; move}
<r1> : robot

The problem is that typing <r1> in REPL does not return robot value. What shall we do?

@xsebek xsebek added L-Language design Issues relating to the overall design of the Swarm language. Z-Meta This issue is about other Swarm issues or infrastructure. labels May 28, 2022
@xsebek
Copy link
Member Author

xsebek commented May 28, 2022

Also, since #303 each robot gets a random name, like Fermi or Gagarin. 😄 This funny detail is sadly not shown to users.

To kick off the discussion, my idea would be to add two functions:

robotNamed : string -> cmd robot // current 'find'
robot      : int    -> cmd robot // currently missing

Then the VRobot 1 could be shown as robot 1.

@xsebek
Copy link
Member Author

xsebek commented May 28, 2022

@byorgey what do you think? I can still rename find in #339. 🙂

@byorgey
Copy link
Member

byorgey commented Jun 1, 2022

@xsebek I am fine with find/robotNamed and robot as long as they require 'God' capability, they could be useful for authoring challenges etc. But I do not think either one should be available more generally. If you do not have a reference to a given robot (i.e. you do not "know about" that robot) then you should not be able to manufacture a reference to it out of thin air by making up a name or number.

I agree the <r1> thing is problematic. If you want to be able to refer to it, you have to do something like r <- build {move; move} (and if you forget to do that, eventually we will have #304 to be able to retrieve the value). But it is still unclear what we should print to represent a value of type robot. At the very least, if they are supposed to be opaque I suppose we should not actually print the robot ID at all. e.g. perhaps we should just print something like <robot> to indicate that it is an opaque value of type robot.

@xsebek
Copy link
Member Author

xsebek commented Jun 2, 2022

Btw. when viewing the robot, we do show its name in the inventory panel:

┌──────────────────────────────────┐
│    trusting_euclid  (2, 0)  >    │
│                                  │
│ ────────Installed devices─────── │

So I would argue for just printing robotNamed "trusting_euclid" : robot for consistency and fun.
I almost want to have that power in a regular game, could robot registry be a thing? 😄

If we wanted to make it really opaque, we could print undefined : robot or make unnamed constant so it reads better and provides some nice error message.

EDIT: the name also shows up in uploaded logs, which is another good reason to show it in REPL

@byorgey
Copy link
Member

byorgey commented Jun 2, 2022

One problem is that names are not guaranteed to be unique. So printing out robotNamed "foo" as the value of the robot doesn't seem like a good option to me, since it might not actually evaluate to the same robot.

The names are supposed to provide a convenient way for you to tell which robot you are viewing, or distinguish different robots in a log, but they don't actually correspond to the robot's identity. They used to, but #303 changed that.

@byorgey
Copy link
Member

byorgey commented Jun 2, 2022

I guess in general I don't see the need to be able to look up robots by name. If you are just dealing with a few robots directly at the REPL, you can just put them in memorably named variables. If you are writing a program to deal with many robots, then you will have them in some sort of data structure, and it really doesn't make a difference whether you're dealing with strings or robot values.

@xsebek
Copy link
Member Author

xsebek commented Jun 3, 2022

robotNamed "foo" might not actually evaluate to the same robot

Sure, but robotNamed "foo#1" will. I tried it and passing the name along with id in VRobot and TRobot is not a big change.
Alternatively, we could make the function giving names unique.

Pairing the REPL command to the robot that logged some error seems quite important.

For debugging, I need the robot numbers. Even if I occasionally do error "---" to mark the current time in the log, seeing the number of the robot helps to alert me to how many build commands actually worked or did not work. But this use case could be limited to some --debug flag.

@byorgey
Copy link
Member

byorgey commented Jun 14, 2022

I was frustrated today when I forgot to bind the result of build to a variable name and it got me thinking about some related things again. What if every robot has a "registry" of robots that it has built, accessible by "child id"? In particular, I propose:

  • adding a primitive child : int -> robot
  • child n evaluates to the nth child built by the robot evaluating it
  • when printing a robot value, print it in the form child n when possible (this will be most of the time)
  • maybe there could also be friend : int -> robot which is a registry of other robots you know about
  • evaluating some robot which is not a child will cause it to get added to the friend index, so it can be printed as friend k
  • note friend and child indices will be specific to each robot; they will have nothing to do with internal (globally unique) robot ids, which will be completely hidden

This should be quite doable with some clever data structures. Is it worth it? Is it too complex?

@xsebek
Copy link
Member Author

xsebek commented Jun 14, 2022

@byorgey I like it, sounds very user friendly 🙂

Maybe if you have a spare counter you could make an indexed log of robots:

  • counter + log -> robots index
Indexes the robots created and met.

————— Index ——————

// built mad_max
child 0
// built crazy_ed
child 1
// met weird_al
friend 0 // or 3?

This would be so helpful for debugging, maybe we could add that to cheating:

  • —cheating [log,index] to always add those devices

@byorgey
Copy link
Member

byorgey commented Jun 14, 2022

Ah, I like the idea of making it a device! I don't know if it needs to be a separate cheating option; if you turn on --cheat and you want a robot index it seems easy enough to do Ctrl+K, create "robot index"; install self "robot index", Ctrl+K or something like that.

@xsebek
Copy link
Member Author

xsebek commented Jun 15, 2022

@byorgey I can do something like that, but until we get multiline REPL (#134) it would eat a lot of my visible line.
I guess require (#201) would help with that.

@byorgey
Copy link
Member

byorgey commented Jun 16, 2022

I'm not sure I understand what you mean. But in any case I don't really care, if you think adding a special command-line flag would be much more convenient, then feel free to add it.

mergify bot pushed a commit that referenced this issue Jun 16, 2022
Sometimes I need a dirty and direct way to get the n-th robot in the world quickly.

The name of the command is longer by design so that it does not get confused with the proposed `child` command or custom user definitions.

- part of #343
@xsebek
Copy link
Member Author

xsebek commented Jun 30, 2022

The diagram above is filled now with robotNamed and robotNumbered, let's discuss better ways for mortals to do it in other issues.

@xsebek xsebek closed this as completed Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L-Language design Issues relating to the overall design of the Swarm language. Z-Meta This issue is about other Swarm issues or infrastructure.
Projects
None yet
Development

No branches or pull requests

2 participants