Tell me more ×
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
I reopened it in effect to close this proposal: area51.stackexchange.com/proposals/24689/programming-language – bigown Feb 2 '11 at 11:08
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 at 23:25

5 Answers

up vote 8 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

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

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
1  
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

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
5  
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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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