# Do Scheme operators have associativity?

Do operators in the Scheme programming language have associativity. For example, the code (- 5 2 1) evaluates to 2, but it could evaluate to 4 if it was evaluated right-associative. However, it is unambiguous if you were to write the expression as (- (- 5 2) 1). The first example, however, leads me to believe that Scheme is left-associative in the case that you do not group all operations into only two arguments at a time.

• Uh... subtraction is not an associative operation in math, hence in programming. Your example has nothing to do with associativity, either. What is your actual question?
– chi
Feb 20 '16 at 22:54
• I mean left-associative vs. right-associative. Ex in regular algebra: 5-2-1 is 2 if evaluated left-associative. It is 4 if evaluated right-associative. Feb 20 '16 at 22:56
• Right, but there's only one subtraction in your example, so it's not a matter of which subtraction to do first. Further, left/right-associativity make sense for infix operators, but in Scheme everything is prefix, so it requires explicit parentheses and no associativity rule is needed. E.g. (- (- 5 2) 1) vs (- 5 (- 2 1)) are already unambiguous, unlike 5-2-1.
– chi
Feb 20 '16 at 23:26
• Your comment seems like an answer to my question. I will rephrase my question Feb 21 '16 at 0:00
• In scheme, (f u v w x y z) will try to evaluate f with the arguments u v w x y z, in that order. It does not evaluate (f u v) first and then something else with the rest. Feb 28 '16 at 9:59

Scheme computes (- a b c) as a - b - c, i.e., strictly left to right.
It really makes no sense to talk about associativity in Scheme, which applies to how an otherwise ambiguous expression like a # b # c is to be interpreted, either as (a # b) # c or a # (b # c) (or even forbid such combinations). In Scheme no such ambiguity is possible, everything is prefix. And the function called is responsible to decide what to do with it's arguments, even if the number of arguments is variable (as in this case). It is probably more natural to work left-to-right.
• (x . y) is an infix operator (even though only for the reader), and associativity concerns apply. Feb 21 '16 at 16:47