h3rald / min

A small but practical concatenative programming language and shell
https://min-lang.org
MIT License
311 stars 23 forks source link

REPL behaviour, question, maybe a feature request #54

Closed zenon closed 4 years ago

zenon commented 4 years ago

The REPL writes the TOS (when length of stack > 0), prefixed with "[n] ->" or "{n} ->", with n the length (i.e. the number of TOS). The choice of [] or {} is confusing.

Looks like {} is for quotes, [] for anything else including dictionaries (that have the {} in their syntax). Modules seem to use {} too. Is there anything else behind?

If not, suggestion: (n) for quotes {n} for dictionaries [], or even no parens otherwise.

Plus: I'd like to be able to switch this off. Having ROOT on the stack is not the only situation where I don't want the TOS to be printed :-)

h3rald commented 4 years ago

Mmmm looks like the {x} is a bug really... It should always be [].

Well... I'd prefer not to have too many options, especially for things like these... I'd like to make the way the REPL/Shell behaves more standard, maybe.

At present the behavior is the following:

$ min -i
[/home/h3rald/test]$ 1
[1] -> 1
[/home/h3rald/test]$ 1
[2] -> 1
[/home/h3rald/test]$ 1
[3] -> 1
[/home/h3rald/test]$
[3] -> 1
[/home/h3rald/test]$
[3] -> 1
[/home/h3rald/test]$

Note that even if I press ENTER the top of the stack is always printed. This can probably become annoying in some situations.

On the other hand for example NodeJS only prints the last-evaluated expression, and of course there's no stack there so it's much simpler:

$ node
> 1
1
> 1
1
> 1
1
>
>
>
>

Perhaps the default prompt should contain the total number of items on the stack., like this maybe:

$ min -i
[/home/h3rald/test][0]$ 1
1
[/home/h3rald/test][1]$ 1
1
[/home/h3rald/test][2]$ 1
1
[/home/h3rald/test][3]$
[/home/h3rald/test][3]$
[/home/h3rald/test][3]$

In that way if you don't like it you can remove it by resetting the prompt. What do you think @zenon ? Or maybe just remove it entirely...

zenon commented 4 years ago

You may have a word, say preprompt, or repl-echo, or repl-state-writer, or something, that does the curent thing, and is used here. Then everybody can change ist to anything she or he wants.