• onlinepersona@programming.devOP
    link
    fedilink
    arrow-up
    2
    arrow-down
    1
    ·
    2 months ago

    I wanted to learn lisp, but the default formatting is just terrible. If it had a different formatting and supported infix notation, it would be readable to me.

    • Alavi@programming.dev
      link
      fedilink
      arrow-up
      4
      ·
      1 month ago

      The polish notation is the simplest thing to wrap you head around. Instead of operations being special syntax exceptions, they’re just functions! Functions that take parameters.

      the only syntax of lisps are (myfun p1 p2 p3)

      Mathematical operations are no exception (unlike otger languages). To make it simpler, think of it like this: + is just an alias (macro) for a function named plus which does addition. (plus 1 2 4 5) is the same as (+ 1 2 4 5). We don’t use infix notation because then that would be a syntactic exepction (like other languages) while this is the only syntax we have in lisp, for everything it’s really simple.

      and also, how is (1 + 2 + 4 + 5) (15 chars) better than (+ 1 2 4 5) (11 chars)? It’s a conceptual shift and once you make it, it makes so much more sense.

    • Zak@lemmy.world
      link
      fedilink
      arrow-up
      4
      arrow-down
      1
      ·
      2 months ago

      If it supported infix notation (outside of reader macros), it wouldn’t be Lisp.

        • Zak@lemmy.world
          link
          fedilink
          arrow-up
          5
          ·
          2 months ago

          Yes. Well, sort of.

          The actual quality is homoiconicity, meaning that code in the language is represented in the language’s own data structures (beyond the entire source file being a string). This enables structural macros - using the language to manipulate code before execution.

          Some languages have tried to do this without the language syntax actually being data structure literals. Rust does it, but a typical Lisp macro looks like a simple template where some things are marked to happen at compile-time and others get spliced in at runtime. Rust macros don’t beyond the most trivial examples.

        • Zak@lemmy.world
          link
          fedilink
          arrow-up
          3
          ·
          2 months ago

          To add to the point about homoiconicity, both the article and my toplevel comment mention thread macros. The article talks about them being equivalent (syntactically at least) to method chaining, which I agree with.

          The thing is, to get method chaining, the language has to have an object system, and the functionality you want to use has to be written in an object-oriented style. To get a thread macro, you need ten lines of code (aside from the docstring and metadata).

      • mlatu@moist.catsweat.com
        link
        fedilink
        arrow-up
        1
        ·
        2 months ago

        i had to try again a couple times too before i got my brain to understand it, also maybe had to find just the right guide (practical common lisp in my case), but now that it’s in there its much easier for me to reason about code using LISP than it was ever in C/++/#, D, Java, Python…