Re: Perl Quiz of the Week #25 (RPN calculator)
Smylers <Smylers-/[email protected]> Wed, 29 Sep 2004 12:00:08 GMT
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
demerphq writes: > Is minus considered to be a binary operator or a unary operator or > both? I can't be both, cos with postfix notation that's ambiguous. Conventionally it's a binary operator. > Ie: is -1 a legal value for the system I suppose that even with "-" as a binary operator you could still treat "-1" as being a negative number. That then means that "-1" is different from "- 1", in the same way that "3 4" is different from "34". The Unix command dc (a RPN calculator similar to the one in this quiz) uses underscore for negative numbers. But this is a way of _denoting_ a single negative number, such as "_1" for -1; it is _not_ a unary minus operator, which would of course follow the number it is making negative. You could use a symbol for unary minus, so long as it is distinct from binary minus (and also from denoting a negative number, if you have such a symbol). But such an operator isn't necessary: if you have some way of denoting negative numbers then you can make do with "-1 *" (or "_1*" or whatever) instead. Or if you don't even have that then you can still perform unary minus with "0 swap -". Smylers