Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

And what do you think about operator precedences? Would be harder programming in language where the operations are executed in sequential order?

Ex.:

2 + 3 * 4 == 20

2 + (3 * 4) == 24

Ok, Lisp family has not precedences by definition. Let's gonna talk about procedural and object oriented languages using this "feature".

share|improve this question
    
It would be a strange language indeed that doesn't have operator precedence that isn't generally the same as found in classical mathematics. –  greyfade Sep 14 '10 at 2:25
    
This doesn't seem off topic to me. Is there a reason you decided to close your own question? –  Macneil Nov 25 '10 at 5:24
    
@Macneil: It's objective and can be ask on Stackoverflow. –  bigown Nov 25 '10 at 9:02
1  
This is a poll type question and I don't see the value in it. It's like asking "which languages don't support parameterized types" –  Mike Brown Feb 25 '13 at 23:25
add comment

closed as too broad by Thomas Owens Aug 28 '13 at 10:29

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

5 Answers

up vote 12 down vote accepted

Smalltalk.

Everything's done with message sending, so 1 + 2 * 3 means "send * with parameter 3 to the object returned by sending the message + with parameter 2 to the object 1".

That throws people (it threw me) because of how we usually write maths, but since I can never remember C's operator precedence I cope in the same manner in both languages - I use ()s to group terms: 1 + (2 * 3).

share|improve this answer
add comment

Forth

It's (almost) all RPN notation, so no precedence rules needed. I'd wager most languages using postfix or prefix notation (PostScript, Lisp...) would work the same.

share|improve this answer
add comment

LISP-type languages don't need precedence because expressions are fully parenthesized. There is no need for precedence to evaluate

(sqrt (expt (- x1 x2) 2)
      (expt (- y1 y2) 2))

I know J, and I believe it's close relative K (along with their parent language, APL, as noted by @Jerry Coffin), evaluate everything right to left with no precedence.

share|improve this answer
    
Neither prefix notation (as in Lisp languages) nor postfix notation (HP calculators) need operator precedence. It's only infix that needs parentheses. –  Frank Shearar Sep 15 '10 at 6:15
2  
Prefix notation can do away with parentheses only if all operations have fixed arity. In the LISP family, the arithmetic operators can take more than two arguments (or less): (+) -> 0, (* 1 2 3 4) -> 24, etc. –  Hoa Long Tam Sep 15 '10 at 14:50
    
Ah, you got me there! Quite right; I assumed "operator" meant "binary operator" –  Frank Shearar Sep 15 '10 at 15:30
add comment

APL has no precedence. If memory serves, everything is evaluated right to left.

Oddly, at least in an official sense, neither C nor C++ has operator precedence. The standard isn't written that way, although (of course) it's mostly a different way of saying the same thing as having precedence. OTOH, it is only mostly the same thing -- ultimately, there's no way to write a precedence table for C or C++ and get everything quite right. There are a few things that just won't quite fit.

share|improve this answer
6  
C and C++ both have precedence. It's even a part of the formal grammar. I believe what you're talking about is the order of the evaluations of subexpressions. For example f() + g() * h() in C/C++ can call any of f, g, or h first, but it always computes (the equivalent of) the * happening before the +. –  Macneil Oct 29 '10 at 1:02
add comment

Prolog.

Well, kind've. There are standard operators, with standard precedence... but you can trivially define operators with arbitrary predence, because 1 + 2 is really the goal +(1, 2).

You may define infix (1 + 2), prefix (++X) and postfix (X++) operators, with arbitrary associativity (so left, right or both).

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.