Version 10 of HereTcl

Updated 2004-01-27 15:56:32

Peter Lewerin (2004-01-26): HereTcl is an unorthodox, radical, contrastandard, and hopefully interesting variant of Tcl...

> is the interpreter prompt // means to clear the results stack ; means the operation can't pop from input

 (1)   Values are simply pushed on the results stack until an
       operator appears
 > 2 3 4
 4 3 2

 (2a)  Postfix: two arguments are popped from the results stack
 > // 2 3 4 +                           > // 2 3 4 -
 7 2                                    -1 2

 (2b)  Infix: one argument is popped from the results stack; the
       other is read from the token stream
 > // 2 3 + 4                           > // 2 3 - 4
 7 2                                    -1 2

 (3a)  That is, unless the next token is ";" in which case
       the interpreter must attempt to evaluate as postfix
 > // 2 3 + ; 4                         > // 2 3 - ; 4
 4 5                                    4 -1

 (3b)  The above is equivalent to
 > // 2 3 +                             > // 2 3 -
 5                                      -1
 > 4                                    > 4
 4 5                                    4 5

 (3c)
 > // 2 + 3 4                           > // 2 - 3 4
 4 5                                    4 -1

 (4)   There must be at least one value on the results
       stack before the operator is read
 > // + 2 3 4
 error: addition requires two terms

 (5)   But the values on the results stack can be left
       over from previous operations
 > // 2
 2
 > + 3 4
 4 5
 > + 3 4
 4 7 5

RS: so binary operators work either infix or postfix (RPN), and the stack is returned, top at left?

(PL): Yes. The stack direction is simply the result of dumping a tcllib stack.

Stay tuned for more interesting examples...