soveran / clac

Command-line, stack-based calculator with postfix notation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

postfix after number should work and not be "ignored"

fasterit opened this issue · comments

3.5 8 *
= 28
3.5 8*
= 3.5

The latter format should work as well to

  • reduce typing effort and
  • prevent errors by overlooking the sane looking but erroneous result and possibly continue computation with that value

I still don't have a solution for this. The last version pushes nan to the stack when you type a non-existent word that starts with a number (like 8* in the example). The main problem I have is that 8* could be a legal word, and as there's a feature to define custom words this could be problematic. But I insist that I find the concern legitimate, and that's why I made sure nan is pushed in later versions when such construction is encountered.

A number plus a (given, allocated) operator should not make a legal word. Too much risk for confusion, not?
3.5 8* will always mean "3.5 * 8" (in infix), never something else.

Right now, 8* will be displayed as nan, so this partially solves the issue. As the input is parsed as shell input, it would complicate the code to parse it differently for that special case. I think this is a good compromise and I hope you understand <3

Closing the issue for now, and thanks again for your input.