usethesource / rascal

The implementation of the Rascal meta-programming language (including interpreter, type checker, parser generator, compiler and JVM based run-time system)
http://www.rascal-mpl.org
Other
399 stars 77 forks source link

Allow redeclaring values in REPL and give temporary names to expressions that are not assigned #1651

Open afroozeh opened 2 years ago

afroozeh commented 2 years ago

I've been working a bit with the Rascal REPL in the last weeks, and compared to Scala/Node.JS REPLs, I miss two features:

jurgenvinju commented 2 years ago

This makes total sense. Toplevel behavior should be different in the REPL. The same holds for functions. Sometimes you just want to replace a function definition with a new version rather than adding a new (non-deterministic) alternative.

jurgenvinju commented 2 years ago

the implicit variable name feature is also cool. maybe we could solve this by binding it with the latest result, just like $? in bash?

afroozeh commented 2 years ago

I think in other REPLs the implicit variable names all stay in the scope when the REPL session is valid, so they should go to the top-level environment. As far as I know, $? will refer to the last executed one, so it will be rewritten. Maybe you can just bind it to an implicit auto-incremented name that is put in the env?

afroozeh commented 1 year ago

Also would be good to drop semicolon requirement for statements as well. It's particularly noticeable when importing modules. This screenshot is from the Java REPL (JShell in Java 11).

Screen Shot 2022-09-14 at 13 18 03
jurgenvinju commented 1 year ago

agreed; we locked the grammar while working on the compiler, but this is a possible and useful feature.