Kotlin / kotlin-interactive-shell

Kotlin Language Interactive Shell
Apache License 2.0
588 stars 36 forks source link

Support for unnamed variables #42

Closed asm0dey closed 4 years ago

asm0dey commented 4 years ago

Whe we use language-CLIs like ipython we know that when we call some expression without assigning it to variable implicit variable is being created like this:

In [4]: "a"*2                                                                                                                                                                                                                                
Out[4]: 'aa'

In [5]: print(Out[4])                                                                                                                                                                                                                        
aa

Here we call output of In [4] by Out[4].

Same effect in jshell:

jshell> 1+1
$2 ==> 2

jshell> System.out.println($2)
2

jshell generates unnamed variables.

I believe the same thing should be supported in kotlin-interactive-shell

ligee commented 4 years ago

The default Kotlin REPL behaviour is to define the result field named resN (where N is the line number) for every "expression-line" so in your first example it would be res4. Completion doesn't work for these fields though, but this is a different issue.

ligee commented 4 years ago

I also added rendering of the resX fields, so it should be now obvious how to use them.