News for hackers. Stuff that matters.
Re:Why Lisp Syntax Works by Capricorn2481 on Monday June 05, 2023 @09:44AM (#36196090)

  (-> x (* 2) (+ 1) (- 3) (% x))
The part that is confusing if you don't know Clojure is (->). This a thread macro, and it passes "x" through a list of functions.

So it basically breaks this down into a list of instructions to do to x. You will multiply it by 2, add 1 to it, take 3 from it, then do the modulus by the original value of x (the value before any of these steps).

Clojurists feel like this looks more readable than the alternative, because you have a list of transformations to read left to right, vs this

  (% (- (+ (* x 2) 1) 3) x)
Which is the most unreadable of them all, to me.
Re:Why Lisp Syntax Works by fungiblecog on Monday June 05, 2023 @06:18PM (#36204821)
this is very readable if you know to read the operations inside-out instead of left-to-right
Re:Why Lisp Syntax Works by ziml77 on Monday June 05, 2023 @07:20PM (#36205709)
But that reading requires looking back and forth to read the operator and the operand. The further you move out the more you shift your eyes and the harder it becomes to quickly jump back to the level of nesting that you are currently on at the other side.
Re:Why Lisp Syntax Works by Capricorn2481 on Tuesday June 06, 2023 @12:06PM (#36214879)
Be that as it may, it's less readable than the other ones, to me
Re:Why Lisp Syntax Works by saltcured on Monday June 05, 2023 @08:44PM (#36206577)
I feel like there's a joke in here somewhere about a backwards Forth dialect, but this also reminds of of chaining idioms used in other languages.

Currying with OOP:

  res = x
    .mult(2)
    .add(1)
    .sub(3)
    .mod(x)
Currying with assignment operators:

  res = x
  res *= 2
  res += 1
  res -= 3
  res %= x
Naming things instead of Currying:

  scale = 2
  offset = 1 - 3
  with_scale = x * scale
  with_offset = with_scale + offset
  result = with_offset % x
Or aping that in Scheme:

  (let* ((scale 2)
         (offset (- 1 3))
         (with_scale (* x scale))
         (with_offset (+ with_scale offset)))
       (remainder with_offset x))