• ☆ Yσɠƚԋσʂ ☆@lemmy.mlOP
    link
    fedilink
    arrow-up
    1
    ·
    7 hours ago

    OK, my code snippets are Common Lisp. But note that none of them involve list/vector/set literals. I was thinking of [] for array indexing and {} for code blocks.

    Again, Clojure uses vectors for arguments, so you end up with syntax like this which provides the same visual information as any mainstream language.

    It doesn’t solve the main issue anyway. Take this snippet from the “infix” readme:

    Yes it does actually because you have syntax hints indicating the type of data structure you’re looking at. For example, in the snippet you highlight, the function arguments are in a vector.

    It ends with a cluster of )))) (reinforcing the “lots of parentheses” impression) and all of those parentheses mean something different

    First of all, you have exact same amount of parens as you would in a mainstream language like Java, C, or Js. Second, the parens do mean the same thing in that example. The big benefit with s-exps though is that you have structural editing, and you don’t actually manage parens by hand or even think about them. You treat expressions as building blocks that you manipulate and compose together. There’s nothing even remotely comparable to this available in languages like Haskell.

    However, here’s an example for you where you don’t have same parens.

    (defn foo [{:keys [x y]}]
      (let [z (str x " " y)]
        {:result z}))
    

    here you have different data structures manipulated, and you have different parens representing them.

    From the outside in, we have the end of a symbol definition (def …), the end of a function (fn …), the end of a macro invocation (infix …), and the end of a function call sqrt(…). It definitely isn’t just “the same number [of parentheses] as any other language that uses parentheses to make function calls”.

    It’s just broken down in the example. In practice you have defn and you just write:

    (defn hypot [x y]  (infix sqrt(x ** 2 + y ** 2)))
    

    The huge advantage over Haskell is that syntax is very simple and regular. You don’t have to think about it at all. Languages like Haskell and Perl introduce a lot of mental overhead because you have to memorize all the special cases and behaviors the syntax introduces. You can write really concise code, but there’s a cost to it. There’s a reason people refer to Perl as a write only language. On the other hand, Clojure hits the sweet spot of being very concise without needing a complex syntax.

    • I disagree with pretty much everything you write here, but especially this:

      First of all, you have exact same amount of parens as you would in a mainstream language like Java, C, or Js.

      My Perl example uses “mainstream language” syntax. Apparently that doesn’t count because it’s Perl (scary! mental overhead! write only!), so here’s exactly the same thing in JavaScript:

      function hypot(x, y) {    return Math.sqrt(x ** 2 + y ** 2);}
      

      … or

      const hypot = function (x, y) {    return Math.sqrt(x ** 2 + y ** 2);};
      

      … or

      const hypot = (x, y) => Math.sqrt(x ** 2 + y ** 2);
      

      Note how none of these involve four layers of nested parentheses.