# Tag Info

## Hot answers tagged operators

### Why do programming languages use the asterisk * for multiplication?

I believe the first language to use * for multiplication was FORTRAN, in its original specification in 1956 (with earlier drafts). None of the other symbols you ...
• 13.2k

### Why do programming languages use the asterisk * for multiplication?

The other answers have covered the first uses of * in programming languages. To these I will add that the asterisk has been used as a symbol for multiplication in ...
• 20.2k
Accepted

### Why is array access not an infix operator?

The answer to "why" questions is often partly historical - unless there is a good reason to be different, following existing conventions helps limit a new language's "strangeness budget&...
• 2,478

### Why do programming languages use the asterisk * for multiplication?

The fundamental reason is because neither true multiplication symbols × nor were (or are) common on US keyboards. Using ...
• 748
Accepted

### Why do programming languages use the asterisk * for multiplication?

Maybe FORTRAN, maybe MATH-MATIC FORTRAN's Preliminary Report in 1954 anticipated using the × symbol for multiplication (and ×× ...
• 5,276

### Why is array access not an infix operator?

There are a couple of arguments in favour of the x[y] syntax for arrays, over an infix operator. One is that we want array access to bind the left operand more ...
• 20.2k
Accepted

### Why do relational comparison operators never short-circuit?

The saving is rare The benefit of short-circuiting is that you don't have to compute the second operand. But there is only one value the first operand can have where short-circuiting is possible ─ ...
• 20.2k

### Why is array access not an infix operator?

it is, sometimes In Haskell, array access is the binary operator !!. In APL, one of the ways of doing array access is the dyadic function ...
• 1,661
Accepted

### How do you correctly compile the chained comparison operators like ones that exist in Python (a < b < c), if b might have side-effects?

The trite answer is that if evaluating b twice is wrong, then it should only be evaluated once... Disclaimer: I don't know AEC, so I'm going to make up syntax. ...
• 3,162

### Why do relational comparison operators never short-circuit?

The primary reason for the existence and popularity of && and || is suppression of the right side effect, not efficiency....
• 2,066
Accepted

### Can two infix operators have the same priority, but different associativity? If so, how would it be implemented in the parser?

As far as I can see, this should work using a standard operator precedence parser. Wikipedia's pseudocode for the "precedence climbing method" already accounts for operators having different ...
• 20.2k

### Why do relational comparison operators never short-circuit?

It is not the case that relational comparison operators never short-circuit in any language. We can define this toy Haskell type and its comparison relationship to illustrate: ...
• 13.2k
Accepted

### What should be the precedence of the bitwise operators relative to each others?

The precedence should be the same as it is in C, for several reasons. C got it right C got the relative precedences for these operators right*, so there's nothing to fix by changing it: ...
• 20.2k

### How do you correctly compile the chained comparison operators like ones that exist in Python (a < b < c), if b might have side-effects?

So this one depends on your operational semantics, in particular on whether your language exhibits Lazy or Eager Evaluation. That said, please bear in mind that even in most eagerly-evaluated ...
• 1,883

### How do you correctly compile the chained comparison operators like ones that exist in Python (a < b < c), if b might have side-effects?

You've got some good answers already but I'll just point out that I've had to do this twice, and done it in two different ways; both work. Method one: When I was writing a Python-to-Python compiler at ...
• 3,849

### Can two infix operators have the same priority, but different associativity? If so, how would it be implemented in the parser?

The way a shift-reduce infix operator parser works is that you maintain a stack of the form A + ( B * ( ... ( G @ (those are unclosed parentheses), and when you ...
• 529

### Why do relational comparison operators never short-circuit?

You Might Surprise the Programmer by Preventing Side-Effects Let’s say your C compiler reads the line: if (printf("hello, world!") > 0) { and (...
• 1,062

### Why do programming languages use the asterisk * for multiplication?

FORTRAN I Based on some quick research, it appears that FORTRAN I was the first language to use * for multiplication. You can see a sample of FORTRAN I code here, ...
• 2,587

### What are the downsides of supporting chained comparison operators?

In an imperative programming language, the operational semantics of n-ary comparison operators are tricky. Say we have a < b < c, where ...
• 161

### If size could be determined at compile time then why could size not be determined at preprocess time?

C was designed to allow programs to be built on computers with extremely limited memory. This made it necessary to run certain processing phases to completion before loading in code that would ...
• 1,946

### Why is array access not an infix operator?

An single-dimensional array access is syntactically very similar to a single-argument function call; indeed, in some languages the syntax would be identical. The latter doesn't use any actual ...
• 1,946

### Ternary operators other than ?:

Many graphics and control applications could benefit from a bitwise variation of the ? : operator, and a compound-assignment variation, though the most natural ...
• 1,946

### What are the syntax options for implementing a ternary "if" operator?

Stack based langauges that directly use RPN tend to have quite different syntaxes for conditionals, built up from their underlying stack operations. In FORTH, you have words that compile directly to (...
• 460

### Why do relational comparison operators never short-circuit?

For completeness, if the relational comparison can be decided at compile time (as in your examples INT_MIN <= x and so on), rather than short-circuiting, some ...
• 299

### Why do relational comparison operators never short-circuit?

You've only given examples of what are essentially degenerate cases of short-circuiting - cases where compile-time constants determine the result, and the test could therefore be struck out of the ...
• 711
Accepted

### How is the VHDL operator <=, which can be both right-associative (signal assignment) and left-associative (less-than-or-equal), parsed?

General ways to resolve this kind of ambiguity: Context-free then rewrite: the nodes for both operations are initially parsed into a common AST node type, then a rewrite step somewhere in the ...
• 4,049

### What should be the precedence of the bitwise operators relative to each others?

If you want to minimize the need for parentheses Let's typical use case of bitshift/masking operations. Bit arrays Suppose that you have a bit array class, allowing an integer (or array of integers) ...
• 1,969
1 vote

### How do you correctly compile the chained comparison operators like ones that exist in Python (a < b < c), if b might have side-effects?

You can translate it to (a < (temp_b := b)) and (temp_b < c) before code generation. temp_b should be a unique identifier ...
• 1,931
1 vote

### Why do programming languages use the asterisk * for multiplication?

As discussed on RetroComputing, the asterisk character existed on IBM punch cards before electronic computers: "asterisk was added to IBM punch card codes 'somewhere around 1932' and was used for ...
• 167
1 vote

### What alternatives are there for C++ operator overloading syntax?

Using the attribute system to define a prefix or postfix attribute. Distinction from binary operators should and commonly happens over the type system simply by checking the operand count. The very ...
• 2,066

Only top scored, non community-wiki answers of a minimum length are eligible