5

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

Ex.:

2 + 3 * 4 == 20

2 + (3 * 4) == 14

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

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

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    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. – Maniero Nov 25 '10 at 9:02
  • 2
    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" – Michael Brown Feb 25 '13 at 23:25
  • Swift doesn’t have operator precedence in the language, but defined in the standard library or defined by the user. The language supports that operators have precedence, associativity but does not which one. – gnasher729 Feb 22 '18 at 9:05
16

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).

8

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.

6

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.

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

APL has no precedence. If memory serves, everything is grouped 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.

  • 8
    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
  • APL is parsed right-to-left, but evaluated left-to-right. – Ven Feb 21 '18 at 13:45
4

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).

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