Live data from Hacker News

An Intuition for Lisp Syntax

stopa.io

51–60 of 201 posts

Re: An Intuition for Lisp Syntax

#51
Is structural editing a genuine advantage over line-based editing?

The author presents it as such, but their structural editing example shows that it takes three operations to negate a condition (create array, write “not”, slurp forwards).

That would be one operation in most line-based languages (write “!”), and it also introduces less line noise.

Re: An Intuition for Lisp Syntax

#52
The article and the heading seem to diverge a bit. "An Intuition for Lisp Syntax" is much simpler than all the pages: in lisp, the syntax for control structures like a loop is the same as the syntax for everything else.

The reason for that is because introducing special syntax disrupts useful patterns that could be used for writing completely new control structures. Threading macros, for example, are pretty much impossible to do properly in Python because of syntax irregularities.

Re: An Intuition for Lisp Syntax

#53
Can anybody recommend resources for the "next level"? I get that "code is data", the "unless" example is nice, but what I don't get is: why would I want to do that?

As a non-LISP developer I get by without macros and all the fancy things that are possible with LISP. I would like to see a strong case of daily tasks that are much easier with LISP macros. Anybody?

Re: An Intuition for Lisp Syntax

#54

Can anybody recommend resources for the "next level"? I get that "code is data", the "unless" example is nice, but what I don't get is: why would I want to do that? As a non-LISP developer I get by without macros and all the fancy things that are possible with LISP. I would like to see a strong case of daily tasks that are much easier with LISP macros. Anybody?

If you buy into the argument that less code, that writing code at a higher level of abstraction results in less time to market, less maintenance overhead, more responsiveness to change in future, less bugs etc. Etc. If you believe a 1000 line program is worse than a readable 100 line program that both do the same thing, then lisp with its macros is that thing.

Super expressive and readable. I went from not being able to read clojure to now having written a few apps in it and feeling comfortable with the syntax in a few weeks.

I definitely write less code to achieve the same ends but it’s still early days for my lisp adventure.

Re: An Intuition for Lisp Syntax

#55
post #10

I've never really bothered to learn lisp, but this is incredible. I get it now. That being said, I wonder how data types would work as opposed to lists. What would a language based around maps look like?

Take a look at Connection Machine Lisp (http://diyhpl.us/~bryan/papers2/paperbot/25aa007a093cd69bbf0...)

Re: An Intuition for Lisp Syntax

#56

This is maybe the best introductions to Lisp i have seen, especially for a js dev like me it could hardly get more approachable and convincing. I could not help but thinking at the end, this is really awesome but s-expressions are kind of hard to read and reason about for my brain, it would be cool if we could generate them from more readable syntax, maybe something like javascript :D . Unfortunately the standard js…

> it would be cool if we could generate them from more readable syntax

There are a few options out there; maybe take a look at Sweet Expressions? Some Lisp implementations have native support for different syntax, but the nice thing about these formats (which are essentially just serialisations of concrete syntax trees) is that we can convert them into the expected format automatically, e.g. using a pre-processor.

I have a go-to page on my blog for discussions involving s-expressions, including links to various alternative syntaxen: http://chriswarbo.net/blog/2017-08-29-s_expressions.html

Re: An Intuition for Lisp Syntax

#57

Is structural editing a genuine advantage over line-based editing? The author presents it as such, but their structural editing example shows that it takes three operations to negate a condition (create array, write “not”, slurp forwards). That would be one operation in most line-based languages (write “!”), and it also introduces less line noise.

In a simple example like the author provided maybe is not that obvious but try to imagine an example with a more complex nested syntax and maybe some threading or function composition in it.

If you have to modify the behaviour of a specific block of code you only need to edit that structure and your block won't get messy neither requiere special syntax.

As you say, If your "!" transaltes to an expression in your language and you are already writting pure functions that compose niceley then I agree that the benefit would be at a syntax level only, the homogeneity of treating all code (macros or runtime) equally.

Re: An Intuition for Lisp Syntax

#58

Earlier quoted context omitted.

> I could not help but thinking at the end, this is really awesome but s-expressions are kind of hard to read and reason about for my brain, it would be cool if we could generate them from more readable syntax, maybe something like javascript :D . So many people start out thinking like this when they learn Clojure or some other Lisp and then after like 2-4 weeks of reading Lisp code, any C-like code starts to look co…

I heard that before but i wonder how much is survivorship bias :D it reads just so awkward to me as a programming language, even though i 100% dig the beauty and everything that it allows.

It's just a different paradigm than what most developers are familiar with so there is a learning bump, same as functional programming if all you've done is object-oriented stuff. The awkwardness is only temporary. If you can already see the beauty of Lisp code, then you just need to build a little project in it to make the awkwardness fade away.

I recommend Clojure/ClojureScript. It's quite practical for web development and also an excellent gateway into functional programming.

Re: An Intuition for Lisp Syntax

#59

Can anybody recommend resources for the "next level"? I get that "code is data", the "unless" example is nice, but what I don't get is: why would I want to do that? As a non-LISP developer I get by without macros and all the fancy things that are possible with LISP. I would like to see a strong case of daily tasks that are much easier with LISP macros. Anybody?

Threading macros, core.async in Clojure that does quite a bit of code rewriting, anaphoric macros, with- macros that bind to some context, destructing in Clojure, slingshot's try+/catch+ in Clojure.

None of that is strictly impossible in languages without macros but best case you'd have to wrap everything in a copious amount of lambdas making for very nasty looking code. Worst case some compile time optimizations wouldn't be possible.

Any single macro isn't THE killer macro, but giving all of them up is a big deal. Similarly replicating semantics of a single macro in some other language may be doable but getting many of them to compose would be tough.

Most popular languages tend to get new keywords, operators and other forms of syntax over time implicitly acknowledging limitations of the "user space" syntax. You don't see that as much in LISPs since most such things can be implemented as a macro.

Re: An Intuition for Lisp Syntax

#60
I don't think I like it. I find it hard to quickly skim and find out what each of the elements is, since it can be anything.

The example amounts to:

  function drawTriangle(left, top, right, color) {
    drawLine(left, top, color);
    drawLine(left, right, color);
    drawLine(top, right, color);  
  }

  drawTriangle({ x: 0, y: 0 }, { x: 3, y: 3 }, { x: 6, y: 0 }, "blue" );
  drawTriangle({ x: 6, y: 6 }, { x: 10, y: 10 }, { x: 6, y: 16 }, "purple");
Maybe it's a case of getting used to it, but with my version I can very quickly ignore parts of code, which are not relevant to the thing I'm looking for.
Post reply on HN