-
Notifications
You must be signed in to change notification settings - Fork 52
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
Ability to save definitions typed at the REPL to a .sw
file
#7
Comments
I actually don't really like the idea of special REPL commands like Hmm, so why not just add a |
It seems like the |
Hah, yes, good point. |
@TristanCacqueray I agree that it should not be possible for robots to escape the game with saving definitions, but that Why not restrict the functionality to the base robot and have a UI list of current definition saves with an extra item to create a new file? Something like this:
We could tab complete If we wanted to be fancy, we could also have dialog to select which definitions in scope (and their transitive dependencies) to export. 🙂 |
I meant it might be interesting to support loading arbitrary robot, and in that situation, it would be nice to ensure a definition can't escape the game. Returning a random file location may not be very user friendly, perhaps the filename could be static, e.g. |
@TristanCacqueray I think robots can only use |
Eventually I would like to remove the restrictions on |
Reading this again, I think I no longer understand exactly what the threat is here. A robot might use the Loading definitions is discussed a lot elsewhere (e.g. #495) so I am changing this issue to focus just on saving definitions. I'm downgrading this to |
I tend to agree with @TristanCacqueray - if I give you a Swarm code that does something cool, you will probably not expect a game to write to any location on the host system the current user has access to. 🤯 If we were to add Also, I think it would be bad design to let you easily bypass fun challenges like wireless communication by simply writing to a file and then reading from it in another robot. You can do that outside the game with the Web API if you want, but building such a thing in the game as @byorgey if we limit the functionality to base (either in UI or |
Ohhh, I finally understand the specific threat model we're talking about. I honestly didn't understand it before. To make sure I really understand it, and for the benefit of anyone else reading this later, the scenario goes something like this: Eve crafts a malicious I agree we should not allow this. How about just adding a UI command (Ctrl+S?) that pops up a dialog prompting you for a filename in which to save?
I don't think so, but we will probably have to save the original AST for function definitions along with their values, just so we can pretty-print them later. Once we evaluate a definition to a value it may end up with unrepresentable stuff that would be hard to reverse-engineer back into valid top-level swarm code. |
.sw
file
Just to summarize the current state of this issue:
This would still definitely be nice --- when attempting a new challenge scenario, I often start by playing around at the REPL, and then later create a solution in a |
I think we ought to get rid of the
run
command and just make some kind of REPL commands for saving and loading the current set of definitions. For example,might create a file
myDefs.sw
which contains the code definingx
andm2
. Similarly:load myDefs.sw
might load the definitions (replacing any currently in scope --- perhaps with some kind of warning and opportunity to cancel).This seems rather critical to actual gameplay since people will develop various useful definitions and want to edit them, reuse them in later sessions, and so on.
I don't think this should be too hard once #8 (and any other pretty printing bugs) is addressed. To save, just get the
robotEnv
from thebase
robot, and pretty-print the definitions it contains (possibly adding some type annotations from therobotCtx
). It may be necessary to add something to keep track of the order of the definitions (something therobotEnv
does not care about) so that we can pretty-print them to a file in the same order the user entered them.The text was updated successfully, but these errors were encountered: