Re: Perl Quiz of the Week #25 (RPN calculator)
demerphq <[email protected]> Wed, 29 Sep 2004 12:30:42 +0200
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
> Operators that require one value ("unary operators") take the topmost
> element off the stack, perform their function on the value, and push
> the result back onto the stack. Operators that require two values
> ("binary operators") take the top two elements off the stack and
> perform their function using the "earliest" value as the first term
> and the "latest" value as the second. For example, "20 5 /" pushes
> 20, pushes 5 (resulting in the stack 1: 25, 0: 5), then pops 5, pops
> 20, divides 20 by 5, then pushes the result (4) back onto the stack.
>
> If there are not enough elements on the stack to perform an operation,
> the calculator should report an error and stop processing the line.
>
> The calculator should support at least the following operators, whose
> functions are similar to those in Perl: + - * / % **
Is minus considered to be a binary operator or a unary operator or both?
Ie: is -1 a legal value for the system or does it have to be treated as 0 1 -?
Id really like to see an example of how you expect minus/negative to work.
Cheers,
yves