REPL: definition support
See original GitHub issueSupport definitions in REPL, to aid exploration of TLA by new users. Requested already in #586; here is a proposed design.
The REPL should maintain a sequence of operator definitions and (optionally named) module instantiations, which, when evaluating an expression, are emitted in order as part of the tlarepl
module. (Supporting module instantiations also allows the REPL to be used to explore existing constant-level modules.)
New definitions and instantiations are input by the user using the same syntax as in a TLA module. If the definition or instantiation results in a parse error, it should be rejected with the error shared to the user.
Since the REPL now maintains state, it is helpful for users to see and record that state. A new LIST
command should display (in order) all existing definitions and instantiations. A new SAVE <filename>
command should write out a module containing the definitions and instantiations to a file. (Probably <filename>
can be either a proper filename, or just a bare module name.)
Additionally, it should be possible to modify or remove existing definitions. Prefixing a definition or instantiation with the word REDEFINE
should replace the named definition or instantiation of the named module from the sequence with the new definition or instantiation, without changing the relative position of the item in the sequence. As with new definitions, if the replacement results in an error, it should be rejected.
Finally, it should be possible to remove existing definitions. The new commands FORGET DEFINITION <name>
and FORGET INSTANCE <name>
should remove the named operator or instance from the sequence, again rejecting the operation if it results in an invalid module. (Is OPERATOR
a better word to use here than DEFINITION
?) To permit easily returning to a clean slate, FORGET ALL
simply wipes all recorded operators and instances.
Optional: Leverage TLC to detect incomplete operator definitions, and prompt the user to complete the definition on one or more subsequent lines. This is similar behavior to Python’s REPL, and especially helps when pasting a multiline definition.
Issue Analytics
- State:
- Created 2 years ago
- Comments:35 (35 by maintainers)
Apologies, I haven’t had time to dedicate to this the past few months (as you can tell). I am actually about to introduce a few colleagues to TLA next week and plan to point them at the CLI for exploratory purposes, so I will have my head space back in TLA-land at least. But until things slow down a bit with my current project (at least another few months) I can’t promise I’ll have time to dedicate to CLI improvements – please housekeep accordingly.
I hope you did not interpret my request as a suggestion for what to spend your time on; I did not mean it that way. I thought I expressed my intention to do the legwork for this in my initial e-mail to the list, but maybe it got lost in translation.
(I do recognize that long-term maintenance ultimately rests on your shoulders; I am trying to keep the proposed behavior simple and self-contained to minimize coupling and future maintenance but I know it’s not perfect.)
This is actually what I started doing (writing my own, linking to tlatools) when I discovered that a REPL had been added since last I updated tlatools. My goal in opening this discussion was to make sure I would not be stepping on toes or duplicating work, if you or @will62794 already had design plans or code in progress.
I appreciate the feedback given on my design; I think the latest iteration I proposed, having jettisoned all new keywords while maintaining most functionality, is much better than what I came in with.
I’ll proceed with implementing this design in a separate branch in my own repo, and keep fixes for any bugs I find in error reporting on the main branch to submit back to the official repo.
I’ll be interested to hear your findings after running the training, thanks. I have two colleagues who are independently learning TLA right now; I will make sure to get their feedback on whatever changes I make to the REPL.