Re: Unary operators, was Re: Definable operators
4 May 1997 00:26:09 -0400

          From comp.compilers

Related articles
Problems with Hardware, Languages, and Compilers (1997-03-07)
Re: Definable operators (1997-04-16)
Re: Definable operators (Craig Burley) (1997-04-18)
Re: Definable operators (1997-04-20)
Unary operators, was Re: Definable operators (Tony Finch) (1997-04-22)
Re: Unary operators, was Re: Definable operators (1997-05-04)
| List of all articles for this month |

Newsgroups: comp.compilers
Date: 4 May 1997 00:26:09 -0400
Organization: Not-much
References: 97-03-037 97-04-095 97-04-113 97-04-134 97-04-152
Keywords: syntax, design

Tony Finch <> writes:
>I don't really see a big problem, so long as the restrictions imposed
>by the language designers are sensible and understandable, and the
>programmers don't go overboard with their freedom and define prefix
>plus to convert its argument to an IP address and launch Netscape.

While I have never wanted to do THAT <g>, I have always felt that
since unary - is used for arithmetic negation, that unary + should be
used for absolute value. In the "traditional" sense, unary + applied
to a number doesn't change the value at all. And, if applied to a
literal (which is not already prefixed with unary -), unary + as \
absolute value does the same thing. But when applied to a variable it
is very useful.

I don't know of any language that does this, but on the other hand
I also don't know of many people that seriously use unary + for
anything other than applied directly to a literal to contrast with a
unary -, for example -23 and +23. Those uses would not change.
[Yuck. That certainly violates the principle of trying to use
operators for their familiar meaning rather than something else.
We've had ABS(X) for forty years and |x| for a century, I'd let
sleeping values lie. -John]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.