2 ms·
> In real Lisp code you'd likely indent it something like this: Not only would that not be idiomatic, the operator for modulus in Common LISP is mod not %. and
by andsoitis 3y ago
> In real Lisp code you'd likely indent it something like this:
Not only would that not be idiomatic, the operator for modulus in Common LISP is mod not %. and the brackets you and the parent used in the s-expr are around the wrong groups of symbols. So you're more likely to see:
(mod (* (+ 1 x) (- 2 3)) x)
or maybe with some limited indentation, such as:
(mod
(* (+ 1 x) (- 2 3))
x)
- _dain_ 3y agoNobody said it had to be Common Lisp. I'm going by the notation the grandparent commenter used. My point was that indentation can clarify the structure of nested sexps vs putting them on one line. And that is actually what people do. "mod" vs "%" hasn't the least to do with it. This isn't even really about arithmetic; those are just at-hand examples the GP commenter chose. Could just as well have been (foo (bar (baz (bax x 2) "hello") "world") "!") >the brackets you and the parent used in the s-expr are around the wrong groups of symbols No they're not. Yours is wrong. Multiplication has higher priority than addition so the order of evaluation begins with (x * 2) not (1 + x).
- andsoitis 3y ago> No they're not. Yours is wrong. Multiplication has higher priority than addition so the order of evaluation begins with (x * 2) not (1 + x). OK, I shouldn't have gone that far. FWIW, modulus has the same operator precedence as multiplication and division. So really, it is more like: (- (+ 1 (* x 2)) (mod 3 x)) or using the increment function: (- (1+ (* x 2)) (mod 3 x))