rascal icon indicating copy to clipboard operation
rascal copied to clipboard

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

Open afroozeh opened this issue 3 years ago • 5 comments
trafficstars

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:

  • Redefining values: Rascal throws an error that the variable is already declared. I can imagine that because of immutability this is desired in the language, but for REPL, I'd consider it a bit of restriction. Especially when experimenting, it's hard to restart the REPL or choose a different variable name each time. Screen Shot 2022-09-12 at 20 49 37 Screen Shot 2022-09-12 at 20 49 43

  • Giving names to expressions that are not assigned. Another handy feature that I miss is giving a temporary name to expressions. This is also useful for experimentation. Screen Shot 2022-09-12 at 20 50 08 Screen Shot 2022-09-12 at 20 50 13

afroozeh avatar Sep 12 '22 18:09 afroozeh

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 avatar Sep 13 '22 09:09 jurgenvinju

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

jurgenvinju avatar Sep 13 '22 09:09 jurgenvinju

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 avatar Sep 13 '22 18:09 afroozeh

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

afroozeh avatar Sep 14 '22 11:09 afroozeh

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

jurgenvinju avatar Sep 16 '22 07:09 jurgenvinju