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

Add a REPL #17

Open
mbrukman opened this issue Sep 19, 2014 · 9 comments
Open

Add a REPL #17

mbrukman opened this issue Sep 19, 2014 · 9 comments

Comments

@mbrukman
Copy link
Member

For exploring Jsonnet, it would be nice to have a REPL, e.g., via jsonnet -i. For inspiration, I would look to Scala's REPL as an example.

@sparkprime
Copy link
Member

Ideally we would use libreadline, but would need an #ifdef for windows, and I'm not sure whether it'd work out-of-the-box on OSX.

On the plus side, this doesn't affect libjsonnet.so.

@sparkprime
Copy link
Member

Thinking more about this, the only thing I know how to provide is the ability to execute complete programs on each line, i.e. the only benefit over using jsonnet -i 'foo' is avoiding typing jsonnet -i ''

Imperative languages like Scala have an easier time because they have this notion of intermediate state.

And in contrast with Haskell, Jsonnet does not have the notion of top-level declarations, it is not possible to parse just "local x = 4";

So given all that, do you still think it's worth it?

@mbrukman
Copy link
Member Author

mbrukman commented Oct 3, 2014

Jsonnet REPL should be more featureful than the standard language itself, because it would make it more useful for experimentation and learning the language. I believe both Scala and Haskell REPLs allow you to do more than what the languages themselves provide.

I agree, however, that it's a non-trivial project. As a first step, providing the same functionality as jsonnet -i would still be useful because not having to retype that (or press "up" and erase the previous command) would be quite useful to get a handle on the syntax.

Later on, allowing the addition of top-level bindings would be an additional useful feature; I suspect as soon as there's a REPL, this will be the first feature request. :-)

@sbarzowski
Copy link
Collaborator

hmm... perhaps instead of REPL for exploration we can recommend that they edit a file and have it automatically executed?

In the simplest version it can be achieved with a one liner:

#!/bin/bash
watch -n 0.5 -- ./jsonnet "$@"`

This is actually better in many ways than a REPL, especially a primitive one, especially for a language like jsonnet.

It can be more fancy of course. You can watch for actual file changes instead of running it every 0.5 second for example (it's a bit tricky: some editors modify a file multiple times (vs code) or actually replace it with a new inode (vim), so there are some special cases). And we could use tmux to provide integrated experience, i.e. open editor pane and result pane for the user.

@sparkprime
Copy link
Member

Since the new website has these interactive Javascript panels, do we think a REPL or watch-based solution is still necessary?

@shaiguitar
Copy link

Upvote this issue. I would like my dev env to have a REPL, just like any other language development environment. I shouldn't need to resort to an external program (browser) if I have the language's environment set up on my device.

@shaiguitar
Copy link

Also consider the case of using the REPL to load local libsonnet files in a given dev project and playing around with an internal objects and so forth.

@sbarzowski
Copy link
Collaborator

The main issue with repl is that, because Jsonnet is a functional, expression-oriented language, so your every entry in repl would basically need to be a separate program.

I think that an editable buffer which is evaluated as you edit it (i.e. "live preview"), is a more suitable approach to experimenting with Jsonnet than a traditional repl. So I imagine a bit more sophisticated version of the watch solution would be the best option. I mean stuff like automatically creating a temporary file and setting up "windows" for evaluation and for the input (maybe using tmux or something) and updating the output whenever the file is saved.

This would allow you to experiment locally and to use any libraries and existing code you have available.

What do you think @shaiguitar?

@shaiguitar
Copy link

Sure, that sounds good. As long as it's possible to load local libsonnet files and play with the REPL and the syntax alongside the project's objects. I would expect this sort of tooling to be part of the development environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants