331 points · by Tomte · 3y ago · 306 comments
> If you want extensible syntax, what should the base syntax be?
The regularity and austerity of Lisp syntax comes from this idea. If Lisp, by default, were loaded up with all sorts of syntactic constructs [1] many of us take for granted today (which may in and of themselves be good!), then it leaves less room for the programmer to extend it in their own way. It turns out that the syntaxes we take for granted today—like for(;;){} loops or pipe | operators—are perfectly serviceable in their S-expression-equivalent form to the working Lisp programmer.
The author is right about why Common Lisp's syntax extension facilities (macros) work; the language is in a sort of syntactic Goldilocks zone.
[1] To properly discuss Lisp, we really ought to distinguish meta-syntax (the parentheses) and syntax (the grammar of symbols and lists). Common Lisp has lots of syntax, like
; variable binding
(LET ((<var> <expr>)*) <decl>* <expr>*)
; type declaration
(DECLARE (TYPE <type> <var>))
; function definition
(DEFUN <var> (<arg>*) <decl>* <doc>? <expr>)
All of this is different syntax! These are different rules about how symbols etc. are allowed to be arranged to produce a semantically meaningful program. But they wear the same clothes of meta-syntax, which is relatively small, mostly based off of the fundamental idea of S-expressions: <s-expr> := <atom> | ( <s-expr>* )
<atom> := <symbol> | <number> | ...
Ordinary macros allow extension of the former class of syntax, while reader macros allow extension of the latter class of syntax. When talking about "macros" unqualified, we usually mean the former, but Common Lisp supports both.[1] https://wiki.portal.chalmers.se/agda/ReferenceManual/Mixfix
It is used by Agda and Maude and is quite versatile.
Note that one of examples above is if_then_else_ function which implements a typical language construct, but in Agda, due to lasiness, it is just an ordinary function.
[2] https://news.ycombinator.com/item?id=20697414
McCarthy did not understand lambda calculus at the time he specified Lisp and what can be a function became a special form, if I not mistaken.
So, for another approach at extensible syntax you may consider mixfix notation and lazy evaluation.
Binding constructs look like let (ITER, rackets for loops, BB, my looping construct: https://git.sr.ht/~bjoli/goof-loop which pushes the limits of what can be comfortably done without breaking hygiene). Derived conditional constructs look like cond (trivia, match, case).
After some time you get a taste for how things are supposed to work to integrate (and to some extent compose) with the rest of the system. The discussions in the SRFI mailing lists can sometimes obsess over small details that, when finished, always seems to come together in a nice way.
A major saving grace here (which was not covered in the section on macros) is that you can write clever macros that do appropriate checking at macroexpansion time, not runtime. This lets you use Lisp to write checkers for your Lisp code, which gives you a Turing-complete language you already know to do the checking instead of the (formally and practically) more limited checking of a grammar.
Lots of interesting problems involving working with different database engines, processing data, compiler design, etc.
<alter> := (ALTER-TABLE (:IF-EXISTS? :ONLY?) <symbol> :*? <action>+)
| ...
<action> := ...
Despite using S-expressions, this is parseable with as much rigor as more free-form character syntax.I think Coalton [1] is a good example of this. The language is embedded as S-expressions in Common Lisp, but you get Rust-like error messages, showing exact source lines (with line numbers) and embedded underlines showing the location of the offending code.
With that said, what is true is that if you're using Common-Lisp-style macros and you're manipulating S-expressions programmatically, lexical information may get thrown out. This is not unlike doing a bunch of string manipulation in an ORM to generate SQL, which will have similarly poor error messages.
1 + x * 2 - 3 % x
is longer to decipher than (% (- (+ (* x 2) 1) 3) x)
which is itself harder than (-> x (* 2) (+ 1) (- 3) (% x))
But it takes a while to be used to it.
And yes, it really helps writing macros, but I wouldn't say this as always be a good thing. Macros are far from being the alpha and omega of programming, as they add an implicit layer of transformation to your code making it easier to write but very often harder to read and reason about.It was the ah-ha moment for me... why not express the source cost directly as that AST? Most languages require lots of ceremony and custom rules just to get here. Sexps are a step ahead (inherently simpler) since they're already parsable as an unambiguous tree structure. It's hard to unsee - reading any non-Lisp language now feels like an additional layer of complexity hiding the real logic.
Sure, s-exprs are much easier to parse. But the compiler or runtime still needs to report an error when you have an s-expr that is syntactically valid but semantically wrong like:
(let ())
(1 + 2)
(define)
Kicking that down the road is a feature because it lets macros operate at a point in time before that validation has occurred. This means they can accept as input s-exprs that are not semantically valid but will become after macro expansion.But it can be a bug because it means later phases in the compiler and runtime have to do more sanity checking and program validation is woven throughout the entire system. Also, the definition of what "valid" code is for human readers becomes fuzzier.
But they always have to do all the sanity checking they need, because earlier compiler stages might introduce errors and propagate errors they neglect to check.
> program validation is woven throughout the entire system
Also normal and unavoidable.
As far as processing has logical phases and layers, validation aligns with those layers (the compiler driver ensures that input files can be read and have the proper text encoding, the more language-specific lexer detects mismatched delimiters and unrecognized keywords, and so on); combining phases, e.g. building a symbol table on the go to detect unidentified identifiers before parsing is complete, is a deliberate choice to improve performance but increase complication.
(1 + x * 2 - 3) % x
and (1 + (x * 2) - 3) % x
both are clearer than the S-expression in my opinionIs there a recommended "intro to understanding lisp" resource out there for someone like myself to dive in to?
(-> 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.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)) '(
1. This is a list: ( ). Everything is a list. Data structures are all lists.
2. A program is a list of function calls
3. Function calls are lists of instructions and parameters. For (A B C), A is the function name, B and C are parameters.
4. If you don't want to execute a list as a function, but as data, you 'quote' it using a single quote mark '(A B C)
5. Data is code, code is data.)Practical Common Lisp - https://gigamonkeys.com/book/
Casting SPELs in Lisp - http://www.lisperati.com/casting.html
Structure and Interpretation of Computer Programs - https://mitp-content-server.mit.edu/books/content/sectbyfn/b...
One of many prior discussions here on HN: https://news.ycombinator.com/item?id=22913750
... amongst many resources for learning LISP.
https://www.braveclojure.com/clojure-for-the-brave-and-true/
(1 + (x * 2)) - (3 % x)
So the correct S-exp (let's use mod for modulo rather than %): (+ 1
(* x 2)
(- (mod 3 x)))
It's a sum of three terms, which are 1, (* x 2) and something negated (- ...),
which is (mod 3 x): remainder of 3 modulo x.The expression (% (- (+ (* x 2) 1) 3) x) corresponds to the parse
((x * 2 + 1) - 3) % x
I would simplify that before anything by folding the + 1 - 3: (x * 2 - 2) % x
Thus: (% (- (* 2 x) 2) x).
Also, in Lisps, numeric constants include the sign. This is different from C and similar languages where -2 is a unary expression which negates 2: two tokens.So you never need this: (- (+ a b) 3). You'd convert that to (+ a b -3).
Trailing onstant terms in formulas written in Lisp need extra brackets around a - function call.
(%
(-
(+ (* x 2)
1)
3)
x)
This makes the structure clearer, although it's still wasteful of space, and you still have to read it "inside-out". The thread macro version would be: (-> x
(* 2)
(+ 1)
(- 3)
(% x))
It's more compact, there's no ambiguity about order-of-operations, and we can read it in order, as a list of instructions:"take x, times it by 2, add one, subtract 3, take modulus with the original x".
It's pretty much how you'd type it into a calculator.
EDIT: care to explain the downvote?
(defn run-analysis [path]
;load data from converted arrow file
(let [data (load-data path)]
(-> data
;; Calc a Weeknumber, Ad_Channel, and filter Ad_Channel for retail
add-columns
;; Agg data by DC, Store, WeekNum, Item and sum qty and count lines
rolled-ds
;; Now Agg again, this time counting the weeks and re-sum qty and lines
roll-again)))
;;Run the whole thing(time (run-analysis arrow-path))
This code processes 27 million lines in 75 seconds (shout out to https://techascent.github.io/tech.ml.dataset/100-walkthrough... library)
(% (- (+ (* x 2)
1)
3)
x)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)This is the main thing I use Lisp (well, Guile Scheme) for. I used to use bc for little scratch pad calculations, now I usually jump into Scheme and do calculations. I don't recall if I thought it looked like gibberish at first but it's intuitive to me now.
x * 2 + 1 - 3 % x
x.*(2).+(1).-(3).%(x)
Unfortunately our brains are broken by pemdas and need clear delineations to not get confused; this syntax also extends to multiple arguments and is amenable to nesting.
1 + x * 2 - 3 % x
would just be "x-2".But if we're talking more generally, if I have an expression like
2*x^3 + x^2 - 5*x
a trained eye immediately can read off the coefficients of the polynomial and I'm not sure if that's true of (+ (* 2 (^ x 3)) (^ x 2) (- (* 5 x))) (+ (* 2 (^ x 3))
(^ x 2)
(- (* 5 x)))
Whereas: 2*x^3 +
x^2 -
5*x
Would probably error out in most languages, due to parsing issues and ambiguity. Even worse ambiguity, if you put the signs in front, as then every line could be an expression by itself: 2*x^3
+ x^2
- 5*x
Could be 3 expressions or 2 or 1.Love the single pipe operator. What language works this way?
x 3 1 2 x * + - %
I definitely prefer white-space over commas and other syntactic obstacle courses. x 2 * 1 + (-) 3 + x %
When I was using my rpn calculator. (-) flips the sign of the number on top of the stack.Or use flip -. But you can avoid growing the stack long enough to be confusing.
"Start with 10; add 5; divide by 3; ..."
:)
1+x*2-3%x
is just as easy if not easier to decipher compared to both of your other examples imo. The above is equivalent to (1+(x*(2-(3%x))))
in APL/j/k. You get used to it pretty quickly.This is false. Lisps do not have to have an image-based development system in order to have Turing-complete macros in the same language as the code, inside the code.
The proof is the existence of such systems. There are Lisp dialects which do not have image dumping, yet have working macros.
What you need is for the macros (and any helper functions of the macros) to be loadable into the compiler process. You do not need image saving and restoring for that to work.
Image saving and restoring is an independent feature of memory management; it traverses the heap and writes a representation of all the objects which can be used to re-animate the session.
Some Lisps rely on image saving for producing executables, but that's not related to how macros work.
No, it _is_ because of homoiconicity, which though a fancy word, does mean something: code is data. That is the reason Lisp syntax works. Clojure is less uniform, but it is still homoiconic, and that is why it has the same powers as CL.
The POSIX shell is homoiconic because after you have defined some functions, you can execute the command "set" (with no arguments) to see the definitions. They are stored in a form that can be copy and pasted into the shell. (There may be reformatting and comments removed).
The homoiconic feature in Lisp (Common Lisp) is the ED function. It will recall the textual definition of a function, allowing it to be edited.
The big idea in Lisp of using a data structure for manipulating code isn't homoiconic; the data structure definitely isn't in the source code format. It's homoiconic to the extent that uncompiled code can be stored as a data structure and converted back to a character-level of representation. (This is possible due to something that Lisp calls print-read consistency, an important concept in Lisp.)
The code-to-code transformations in Lisp do not work by converting code to text and back again.
We can take advantage of that even if we go through some front-end that provides a surface syntax, like infix.cl, which loses homoiconicity.
So rather that homoiconicity, the two concepts important in Lisp are print-read consistency and code as a data structure.
I think when people say “code is data” what they really mean is something more specific, like the AST is easy to access and manipulate in the language.
(def add (x y) (+ x a))
(def sub (x y) (- x y))
(add 1 2) # 3
(sub 1 2) # -1
(first '(add 1 2)) # 'add
(rest '(add 1 2)) # (list 1 2)
(apply 'sub (rest '(add 1 2))) # -1
(reverse '(add 1 2) # '(2 1 add)
Excuse my pseudo lisp quote syntax, it's been a while.
IF the "Syntax / Parenthesis" is the "only" thing that puts you off LISP (I'm sure there are many other semi-valid reasons), keep pushing. It's a little bit like smoking, most smokers didn't enjoy their first two or three cigarettes, but suddenly one day you realise you addicted and now all other non S-Expr-Languages looks ugly. It's kinda like magic the "sudden switch" from hate-to-love. At least for me :)
YMMV
What did it for me is realising that after some time, you don't pay attention to the parentheses. Identation in lisps is semantic, which looks weird when you're used to one level at a time. But try using a sensible formatter (e.g. Clojure's cljfmt, Racket's fixw). They will show you good ways to format your code, making it very readable, parentheses and all.
Then you get used to structural editing with Paredit or vim-sexp, and you're sold on S-expresssions.
It's not physically addictive.
Would you be addicted to a video game that sucks?
"I want to play a game because it's critically acclaimed and has stunning graphics, not because I can't stop."
"I want to read a novel because it's author is a winner of literary prizes, not because I can't put it down ..."
Lisp in general and Common Lisp in particular have a lot more going on than the syntax though. I think there's an old saw about syntax being the bikeshedding of the programming language world when it's semantics where all the real thought and expertise is required. It's the semantics that CL interesting, like for example its well defined notions of compile, load and eval time[1] and the ability to redefine existing types and functions, even while in the debugger.
Personally I switched to clojure 8 years ago after this article along with PG's essays pushed me over the edge.
https://elixir-lang.org/getting-started/optional-syntax.html
A more encouraging response would be one that doesn't focus on whether or not I understand correctly (I'd already acknowledged that I may not), but on what the differences are, thereby spreading your knowledge rather than using it to make people feel excluded.
While I wouldn't go as far as saying that elixir has the same benefits as lisp regarding uniform syntax in combination with a flexible macro system, elixir's macro system is undoubtedly powerful. The big difference with a lisp is that elixir's macro's operate on an intermediate ast representation that looks a lot like lisp code. So while elixir doesn't have a very uniform syntax itself, I think its macro system gives comparable power and flexibility.
btw, the other poster didnt mention elixir macros. they mentioned optional syntax which frankly terrifies me :)
This month for #12in23 we're exploring languages that are Lisp dialects. We're digging into Clojure, Common Lisp, Emacs Lisp, Racket and Scheme, with interviews and live streaming, exclusive swag and lots of fun exercises for you to complete!
https://exercism.org/challenges/12in23This group would swear by Lisp. And by that I mean, they would treat Lisp as the gold standard. Sometimes, the only standard that matters. They would go to unimaginable lengths to explain why Lisp is really the purest form of computer science expression; how it sharpens your mind and elevates your skill; how it is akin to poetry, only better, because it's poetry in code.
And after all this was done, and repeated several times over, I would gently nod at this exalted madman who had been blessed by the touch of the Lisp God. And then we'd both go back to whatever language we were actually using at the time.
Over the years, as a left-handed person, I've come to see this as evidence of underlying diversity in thought patterns that can't simply be learned/trained around. Certain people find certain metaphors and modes of computing much easier to work with than others. Few people on either side can see this. The result is that you have people who, having feeling like they were fighting scissors all their lives suddenly discovering that a different sort of scissor exists that gives better results, start evangelizing it to everyone. The rest of the world tries it, finds it impossible to use, and concludes the weird scissor advocates are mad.
Neither the LH people holding LH scissors nor the RH people holding RH scissors are "wrong". It's just the RH people trying to use LH scissors who are having a bad time.
(The limit case of this is a few people who are using languages which are uniquely tailored to themselves and absolutely nobody else; colorforth, the late author of TempleOS, Urbit, etc)
People would rather die/retire than change how they program. The assembly guys died/retired rather than learn structured languages. The imperative people died/retired rather than learn OOP. The OOP people are currently dying/retiring as languages shift to be much more functional.
ALL of these things have existed for 50+ years, so why did they take so long to adopt (as people now almost universally agree these things are better)? It's all about what they are taught and use early on in their career. With the exception of 5-10% of outliers, everyone takes what they learned in school, adds a little more past that as they are learning to code, then cement their synapses into that pattern for the rest of their career.
A conflating factor here is corporate backing. If you look at the popular programming languages, only a couple became successful without a large corporate sponsor. Corporations tend to be conservative in their investments too. This creates a secondary effect where even when you encounter a superior language pattern, you cannot use it because your company isn't likely to pay you to rewrite complex libraries in a new language.
JS pushed the world so far toward functional programming because even though it was different, it was the only standard. OOP devs in the 90s and 00s would rather die/retire than actually learn JS and more functional programming paradigms. But because it was the standard, big companies like Google and MS were forced to pour in resources and make it accessible. In turn, that has led to a glut of functional features being bolted on to other languages now that a generation of programmers has adopted them.
I'd hypothesize that if Eich had made a Scheme instead of JS (as he originally intended), we wouldn't be having this debate today. It would have forced corporate backing of a lisp and of a functional language. The current crop of devs would have been introduced to both of these ways of thinking and nobody would question the merits of a lisp-like language compared to ALGOL/C derivatives that have been foisted into mainstream education and corporate support for the last 50+ years.
I don't know what programming language landscape you're looking at, but to me it doesn't look like that at all. I grant you that more and more languages are getting functional bits glued on. That doesn't make them FP languages, though. And my perception is that they aren't being used as FP languages. They're being used as other-paradigm languages that can do a bit of FP when desired. If people actually wanted an FP language, they'd switch to one. And they aren't.
As the saying goes, academia advances one funeral at a time.
I think the software dying or retiring is perhaps a more important factor than the developers, who can be flexible if the money/kudos is there for them. Rust has been picked up in various places to "forcibly retire" C/C++ programs which have had too many CVEs in their lifetimes; the only reason they were not retired earlier is the lack of a language with the required properties. If there was a bug-free highly performant implementation of SSL that existed in Lisp, that might be a thing that encouraged people to take a look at adopting it despite their lack of familiarity.
> ALL of these things have existed for 50+ years
Especially Lisp. Lisp has been around for a long time. At this point I think it's suffering from a "true communism has never been tried" argument which overlooks that people have tried it and takeoff has not been achieved, and its advocates continue to blame everyone else (as in your post) rather than engage in a little introspection or reflection.
> I'd hypothesize that if Eich had made a Scheme instead of JS (as he originally intended)
As the world turns, WASM now has a canonical format in S-expressions.
True, and good insight, but it doesn't mean that all scissors, or all languages, are equal. They can all perform computation, but a person with a particular language might create incredible things that another person with another language would have a hard time with.
Let's appreciate the difference in tastes, which reflect our different in thought processes and approach to the world, but it does not mean that every language is the same, nor every person is the same. A Lisp virtuoso will build tools which are completely alien in design and operation than tools built by a Java virtuoso.
I really don't want to take this off-topic, but this fallacy is very present in our modern approach to human diversity, where instead of celebrating our differences, we simply reduce it to a one-size-fits-all approach. There is enough space for everybody, the result is effectively the same, but you simply can't replicate a Lisp-wielding Paul Graham in any other language.
But anyone who wants to really dig deeper will wonder about replicating which particular aspect of PG's productivity.
If the aspect they care about is the ViaWeb ecommerce site that he sold to Yahoo for a few million, then all of PG's essays[1] about (paraphrasing) "Lisp syntax being their secret weapon to agility and flexibility compared to others using inferior blub languages" ... isn't going to be convincing to others who notice that Amazon ecommerce was built on Perl/Java/C/C++ instead of Lisp. And later, Shopify was built with Ruby on Rails and PHP instead of Lisp.
In other words, maybe the secret weapon to building ViaWeb wasn't "Lisp" but instead, "PG's brain". (https://en.wikipedia.org/wiki/Confounding)
This is why language discussions focusing on "superior syntax" really don't really move the needle when it comes to mass adoption. Yes, Lisp's "code-as-data" is powerful etc, etc but there may be other factors that make that syntax feature not so important in the bigger picture.
[1] "Beating the Averages" : http://www.paulgraham.com/avg.html
Crossing with the "build what, exactly?" thread: https://news.ycombinator.com/item?id=36195055 - does the special alien-ness translate into either greater user satisfaction or greater commercial success?
It is possible that there are Lisp virtuosos. It is also possible that you have to be a virtuoso to write Lisp, as is definitely the case for J. Every J program is a tiny work of art. That's why there aren't very many of them.
> you simply can't replicate a Lisp-wielding Paul Graham in any other language
You can't replicate Tolstoy in any language other than Russian, either. I'm not sure that proves anything other than the existence of unique talents that are also bound to their circumstances?
Today one's rarely in a position where you have to bootstrap your development environment from almost nothing, so there are better alternatives.
But if you're stuck on a desert island with a computer and a CPU databook, bootstrap a FORTH compiler and then use that to make your LISP. :)
What's interesting to me is that I see Lisp and Forth as extremely similar-in-spirit languages, though FORTH is definitely "lower level" (pointer arithmetic everywhere) than Lisp. Depending on your implementation, I bet you could squeeze out nearly every bit of performance to be had on a given system with forth (given enough time), but I'd be really surprised if you could with any lisp.
I think I read code visually. I understand its literal 2D-visual shape first, and use punctuation as visual markers to help me along. Then I backfill the gaps in the structure with the actual "content" of the code.
For the longest time I was baffled by the other camp's attempts to get rid of punctuation. What are they thinking? I now believe what they're thinking is of code as linear text. If you read the code linearly first, as text, and build the structure in your head as you go then yeah, all; of(that) seems {kinda} pointless && annoying.
Now guess which camp is more likely to write blog posts about how theirs is the One True Way? Ah, the humanity.
I coded in Java for 20+ years and then switched to Kotlin. Semicolons were gone, it was a breath of fresh air.
And then I learned Rust and I faced what I thought were two absolutely insurmountable obstacles: semicolons AND snake_case. I considered Rust ugly for these reasons and really dragged my feet. But I was curious about the language, so I perservered.
One week later, I wasn't noticing any of these any more. I still do think that semicolons are a manifestation of a language developer who favors their time over mine, but it's become more of a pet peeve than a deal breaker.
The human mind is wonderfully flexible.
Absolutely.
I took a couple of Lisp classes in my computer science program, and I saw this almost instantly. Some people who had a very hard time catching up in most other languages suddenly shined. However, some students who were otherwise very successful, had a harder time with functional languages.
I always wondered how this worked. Is it that we're just wired differently?
> ...concludes the weird scissor advocates are mad.
I just wanted to clarify I don't think this. I appreciate when people are passionate about something like Lisp. At least, I'm happy for them!
very much so. Richard Feynman had once said that even the simple act of counting is perhaps completely different between different people. Some people count by visually seeing a count, some use a voice, and may be there are others who have a different system.
Every year, or so, I'll design a programming language on paper to work through my "latest thoughts" as impacted by languages and ideas I've picked-up since. Each time the design is different, with different priorities etc.
I think what I'm doing is exactly what you describe: clarifying my mental model of programming languages -- so that I arrive at something which "feels right".
I can then come back to actually-existing languages and express my "prelinguistic" ideas using whatever syntax they make available.
Absent this activity, I think I gradually end up too conceptually confused -- blending a mixture of whatever languges i'm working in.
The power of a single radical paradigm solves this problem for people, like me, who require a theory to feel comfortable; but without all the effort i go to.
(Though for me, of course, it's a hobby --- I like to see how close I can get to designing a language which, at that moment, is the one I'd wish to program in).
Reminds me of the paper "Programming as Theory Building" https://pages.cs.wisc.edu/~remzi/Naur.pdf
Where do I subscribe?
> Each time the design is different, with different priorities etc.
Classic trilemmas. Nice.
Scott McCloud's triangle for style of illustrations was a eureka moment for me. The tips are ideographic, textual, and realism (IIRC). All comics lie somewhere within that triangle (solution space). Mind blown.
There are many either-or tradeoffs: closer to the metal vs abstractions, explicit memory management vs garbage collectors, etc.
But there's probably also a few trilemmas, like functional vs imperative vs declarative.
Anywho. Just a casual notion. I'd love to see a big list of design decisions for programming languages.
Today's embarrassment of riches has reduced the enthusiasm for language jihads. But it'd still be nice to have something more than esthetics and vibes to guide our choices.
Could you expand on why this is so powerful for you?
Not doubting it’s power, but I’m having a hard time understanding _why_ it’s so powerful for some people.
The ultimate halting problem?
We got along great.
The early meetings at Apple for the design of the Dylan language definitely had both Lisp and Smalltalk folks participating. I wouldn't be surprised if some of the participants were FORTH folks, too.
https://www.donhopkins.com/home/catalog/text/interactive-pro...
https://donhopkins.com/home/archive/forth/forth-postscript.t...
David Singer at Schlumberger developed a Lisp-to-PostScript compiler in 1987 called "LispScript".
https://news.ycombinator.com/item?id=21968842
https://donhopkins.com/home/archive/NeWS/NeScheme.txt
Arthur van Hoff at the Turing Institute in Glasgow developed an object oriented C to PostScript compiler called "PdB" around 1990-1993:
https://compilers.iecc.com/comparch/article/93-01-152
We used PdB to develop HyperLook for NeWS, integrate The NeWS Toolkit components into HyperLook, and implement the SimCity user interface on SunOS/SVR4/X11/NeWS.
https://news.ycombinator.com/item?id=22456471
ChatGPT Summary of the above thread:
This discussion thread revolves around the concept of implementing Lisp-like macros in PostScript for creating more efficient drawing functions. The user "DonHopkins" highlights their work on the Open Look Sliders for The NeWS Toolkit 2.0, where they leveraged a Lisp "backquote" like technique to optimize special effects drawings. The user explains that this approach accelerates drawing at the expense of increased space utilization. They also propose a potential solution to space conservation by only expanding and promoting macros during tracking, then demoting them upon tracking completion.
DonHopkins shares several resources on NeWS, LispScript, and the PostScript compiler, and also refers to window management tasks in Forth and PostScript for comparison. Additionally, they discuss a paper on syntactic extensions to support TNT Classing Mechanisms and share a demonstration of the Pie Menu Tab Window Manager for The NeWS Toolkit 2.0.
Another user, "gnufx", appreciates the shared resources and brings up the metacircular evaluator in HyperNeWS or HyperLook as a potential speed bottleneck in the system.
DonHopkins responds by explaining the use of a metacircular evaluator (ps.ps) they wrote for debugging. They clarify that speed was not a concern as the evaluator was not used in any speed-critical situations. DonHopkins also discusses the technique of "PostScript capture," likening it to partial evaluation of arbitrary PostScript code with respect to the imaging model. They relate this concept to Adobe Acrobat's "Distiller" and Glenn Reid's "PostScript Distillery".
I have! There was a knife fight and they both stabbed themselves, horrific.
As far as the last decade is concerned, the most productive open-source and professional Lispers have done some advertising of Lisp, but mostly through a combination of technical blog posts and actually making things.
I can't convince anyone to use it. They just don't like the look of it, they stumble at the brackets. I know that I can't write something in it and expect other people to use it, build it or maintain it.
So I don't use it. And nor does anyone else.
Forcing the overhead of learning CommonLisp, which is actually a fairly big language despite the syntax, on top of learning how to use emacs is a big ask.
"Oh, there's also Crash Bandicoot".
"Wow, color me impressed".
Fully expect the first HN thread while we climb out of the ruins to be though 'what has lisp ever done for us, it doesn't even run my web app'
By that time, it would be: "It doesn't even run my magic sauce prompt for GPT42"
Of course, if you ditch the "modern" requirements, I'm sure there is more web infrastructure and scripts supported by Common Lisp than people would want to admit. . .
when naughty dog got sold, all the remaining Gavin lisp systems were eventually stripped, so that the company for all intents and purposes became a standard c++ shop. some time later some hipsters wired plt scheme[2] as a scripting language for the Naughty Engine 2.0. unlike the original Gavin approach this is not some deep leveraged architectural decision, and it being lisp is pretty irrelevant to the sort of capabilities it provides. imho scripting language for a game engine selection is a lipstick on a pig kind of process, as demonstrated by various basic-like potato languages that came with legendary triple-As.
[0]https://all-things-andy-gavin.com/2011/03/12/making-crash-ba... [1]https://franz.com/success/customer_apps/animation_graphics/n... [2]https://www.gameenginebook.com/resources/gdc09-statescriptin...
There’s also Metabase, also written in it.
Some people do not realize this, but the thing you build when you compile an Emacs distribution is not a text editor. It's just a specialized lisp interpreter that has primitives for handling things like frames, buffers, and other UI-type stuff like detecting key chords, plus some math and stringy stuff, and a few other bits and bobs. The editor itself is written in Elisp.
To illustrate, this is what I get when I run `sloccount` on the source download of Emacs 28.2 from gnu.org:
Totals grouped by language (dominant language first):
lisp: 1253948 (75.66%)
ansic: 368126 (22.21%)
objc: 17115 (1.03%)
sh: 7261 (0.44%)
cpp: 1851 (0.11%)
yacc: 1566 (0.09%)
perl: 1442 (0.09%)
php: 1035 (0.06%)
pascal: 1011 (0.06%)
python: 993 (0.06%)
awk: 781 (0.05%)
cs: 770 (0.05%)
ada: 725 (0.04%)
ruby: 405 (0.02%)
erlang: 153 (0.01%)
java: 65 (0.00%)
tcl: 16 (0.00%)
It's basically 75% elisp, 25% C, and more or less all of that C code is either implementing the lisp interpreter itself, or interfacing to system libraries. Using Emacs is really the closest you can get these days to working on one of the old LISP machines from the 80s, except it's more fun.Which well known projects do use lisp? I think Google Flights uses lisp [1]; there must be more?
Others: https://lisp-lang.org/success/
The only one that comes to mind for more powerful is abstraction over control flow. Instead of delimited continuations, one can go with unification and implict control flow.
What are the increases in power you consider lisp users blind to?
(p.s. first class environments, first class macros are missing from common lisp and scheme, but not from all lisps)
But abstracting has a cost. Sometimes in terms of performance (perhaps mitigated with great effort or a sufficiently smart compiler), but always in terms of cognitive load. A elegant lisp expression is meaningless in isolation. When reading lisp code, you must recursively find and remember the definitions for each token on the page before you can understand what it does. Hopefully the author knew Naming Things is Hard and choose good names. Hopefully the names point you in the right direction. But you can't be sure unless you traverse each definition to its leaves. Lisp programmers are blind to the power and clarity of thought that comes from direct expression - all definitions visible at once, with no indirection.
A lisp programmer might look down on a Java programmer's reliance on IDEs. An IDE is a powerful tool for shoveling mountains of code, but a lisp programmer might say "I can solve this problem without mountains of code". Likewise an apl programmer might look at a lisp solution and say "I can solve this problem without defining any new terms". A forth programmer might say "I can solve this without parentheses". A C programmer might say "I can solve this without a heap". An assembly programmer might say "That entire program is equivalent to a single x86-64 instruction".
By crafting different bespoke DSLs for each new problem, lisp programmers lose the opportunity to hone one DSL to perfection. The knowledge that any problem could be solved with lisp lures them toward the fallacy that every problem should be solved with lisp.
Static typing, mutable values with unique ownership.
Relatedly, I was just looking at this, mostly to see what the fuck possessed someone to do it: https://macropy3.readthedocs.io/en/latest/index.html
Origin of the phrase "Blub Paradox": http://www.paulgraham.com/avg.html
I am a big fan of "functional programming languages", including Lisp to an extent. That said, I appreciate the teachings they can impart - abstract structures, design sense / "design patterns", and ways of thinking etc. - more than any sort of dogma associated with "their way". Although, to be fair, I did go through my own period of foolishness in ... say, "venerating" this particular "methodology".
Your comment did prompt thought of Pratchett's book "Interesting Times". Specifically, passages like "... It had come as a revelation to Lord Hong when he looked at the problem the Ankh-Morpork way and realized that it might just possibly be better to give the job of Auspicious Dog-maker to some peasant with a fair idea about metal and explosive earths than to some clerk who'd got the highest marks in an examination to find the best poem about iron. In Ankh-Morpork, people did things."
The tricky bit in everything, and the difference between the true expert and not quite is often found in forms of "executive function" ... Knowing what to apply and when ... when to change up strategies, what the value is in some methodology and how to bring that into what you are doing ... all these sorts of things.
I always know when I'm at more of an "advanced intermediate" level (a sort of "first black belt" level) when I know too many ways to go about doing something but have no idea which is likely to produce solid progress in a relatively time-efficient way.
So, bit of a digression off of your comment, but stimulating from my perspective and hopefully of some use to anyone who might read this.
I in fact agree with the observation, but I also think that the same can often said of many passionate people. Scala? Blockchain?
Continuing the observations, mainstream approaches seem to have less passionate followers. Very few people are evangelizing Java as passionately as others do Lisp. I wonder what makes mainstream less attractive in this sense.
There is a difference for a language between "readable" and "understandable".
To me, languages that don't have type annotations (ideally with type inference) might look pleasing to the eye but they are a nightmare to maintain and modify because so much vital information is missing.
> (list 1 2 3 4)
is a way to create a list consisting of elements 1, 2, 3, and 4. This procedure is defined as returning a `list?` (a contract checking for a list) and the values provided are `any/c` (a contract representing any value). But many other languages can support something like that just fine. Where contracts further help are with composition and specifying allowable values or ranges of values. For example, > (round 2.4)
2.0
as we expect. But looking at the definition of `round`, we see that `(round x)` accepts an `x` satisfying contract `real?` and returns `(or/c integer? +inf.0 -inf.0 +nan.0)`. If you try to `round` Infinity or NaN, you get what you "expect" and not some new value. If you try to `round` POSITIVE_INFINITY in Java, you'll get > Math.round(Double.POSITIVE_INFINITY)
9223372036854775807
because, with types, Math.round() must return an int or a long.you're right that a contract allows you to specify more precise properties than a "regular" type system, but it comes at the aforementioned cost. If you want both, dependent types would be your best bet, but those are... rather complex in practice and to my knowledge, not really "production-ready".
as for your example though, it would be possible to implement `Math.round()` in such a way in Java that it doesn't just return an int, but some sum type that encodes whether it's an actual result or some invalid value. The reasons why this isn't done are probably a) it's awkward, though possible, to express sum types in Java (this would be easier in some other languages), b) it would force the caller to always have to explicitly consider the case that the value is invalid even when they know it's not, making mathematical calculations tedious and hard to understand.
And of course, you're not forced to use dependent types, so "regular" statically typed programs are just a subset of dependently typed ones.
For that kind of limited use, I find s-expressions great because it's trivial to add simple s-expression parsers to things where you suddenly need to support complex nested structures with minimal syntactic noise, but I'd claw my eyes out if I had to read s-expressions all day every day.
(And since I prefer Ruby: just prepending a "%" the example s-expressions in the article makes them valid Ruby literal strings, so now I'm kinda tickled at the thought of taking a little s-expression parser and building a tiny Ruby Lisp implementation that lets you just intersperse lisp code in your Ruby. Surely someone must have already done so for fun)
[
// define some_fun(x) => let y=2;let z=y*3;return x+z
{"some_fun": [["x"], [
{"y": 2,
"z": ["*", "y", 3]},
["+", "x", "z"]
]},
// call it
["some_fun", 100]
]
Here I'm using JSON dictionaries to bind variables, and lists for everything else (instruction sequences, argument lists, etc.). Now I can quote stuff to define JSON data, or otherwise define programs.I'm not a lisper but it seems what's special about lisp is it defines its programs in a generic data format.
The most obvious thing lacking from the point of view of interpreting in a Lisp-like way is an ergonomic syntax for symbols.
People have experimented with computation in JSON, pretty much like how you have it; but it's lame to work with. Nobody wants to write quotes around basic identifiers like "+". And it is inefficient, to boot.
Interning of symbols is a key advantage of Lisp, and it was there in 1958 already; so by using JSON this way, you're regressing before that.
Lisp converts symbols into small values, which are atoms. Two or more occurrences of the same symbol are the same atom. An atom is a small word-sized quantity. Often a pointer, but not necessarily so; it could be a numeric index into a table of objects. Anyway, it is very efficient to test whether two atoms are the same object.
One of the things that still makes Lisp special. It makes metaprogramming "easy" in contrast to metaprogramming in almost every other language out there.
The other big thing is its high degree of interactivity and dynamic capabilities.
It's also very easy to get visual results in Racket which often helps to keep kids motivated (seeing results of their work quickly and easily, versus needing to jump through hoops or read lots of documentation just to render a single image).
The most trivial counterexample is an interpreter - it can simply evaluate the macros just like ordinary functions.
A step up in complexity is a compiler that - during compilation - compiles macro definitions by emitting code and dynamically loading it (Goo does this http://people.csail.mit.edu/jrb/goo/goo.htm , and I have also put a toy implementation of this together using dlopen, and there are probably many other impls that do this.)
Clojure is one of the weakest lisps when it comes to macros, but you can still define and use them at run-time, and it has no image-based development.
Visual Cues Help! Maybe your eyes are different, but most the programming world has agreed with me over the years and voted C-style over Lisp. I have even proposed a syntax style called "Moth" that attempts to meld the best of C-style, Lisp, and XML in terms of composability and roll-your-own control & block structures. I welcome better takes on the goal.
Moth link: https://www.reddit.com/r/ProgrammingLanguages/comments/ky22d...
One of the first rules of making a new programming language should really be to do as little as possible in the parser. By making your parser extremely complicated, you also make it extremely difficult for anyone to write tools for your language. Instead, it's much better to push that out to the rest of the compiler and/or the type system.
I agree (though it doesn't necessarily irk the eye after some getting used to). Rather than saying it has a "uniform" syntax as the article author does, I am fond of saying lisp has "no syntax," because it's essentially true.
Yes. RPN is more like Forth than Lisp.
> Syntactic uniformity also means there is a lot less room for syntax bikeshedding. Really the only thing you can bikeshed is the naming convention for identifiers, and how S-expressions should be indented.
This might be true in theory, but in practice I find to be effectively false. Lisp makes is very easy to add your own macros that implement DSLs with custom "syntax". Common Lisp for instance has bunch of these build in, for instance for iterating over lists. While this is technically not syntax in the traditional sense that the parser is aware of it, it has the same characteristics for a user. You need to learn the "syntax" that the macros implement and _that_ syntax you can certainly bikeshed about.
CL is the "worse is better" of "the right thing".
Embedding Hygiene-Compatible Macros in an Unhygienic Macro System: https://www.jucs.org/jucs_16_2/embedding_hygiene_compatible_...
Abstract: It is known that the essential ingredients of a Lisp-style unhygienic macro system can be expressed in terms of advanced hygienic macro systems. We show that the reverse is also true: We present a model of a core unhygienic macro system, on top of which a hygiene-compatible macro system can be built, without changing the internals of the core macro system and without using a code walker. To achieve this, the internal representation of source code as Lisp s-expressions does not need to be changed. The major discovery is the fact that symbol macros can be used in conjunction with local macro environments to bootstrap a hygiene-compatible macro system. We also discuss a proof-of-concept implementation in Common Lisp and give historical notes.
The code is in Figure 1, on page 10 of the PDF (p. 280 in the actual journal)it is the feature of the code being represented the same way as the datastructures it manipulates. i know, what a completely unneccessary and unimportant point. now let's all forget this and turn our attention back to the compiler, it wants you to fix those bugs now... back to work.
Every language can do this. You just don't get QUOTE. But any compiler can implement QUOTE.
That is to say, the "quote" form in lisp is far more than just a string template, which is what it often turns into in other languages. That, or you build up a bunch of structs that you don't normally see.
Okay...
> Lisp (and XML) have a uniform syntax.
.. ookay. The rest of the arguments, and the conclusion, can then be equally applied to XML, specifically the:
> I maintain that Common Lisp is the gold standard of DX for macros
Does (s)he also maintain that XML is the gold standard of DX for macros? I guess that'd mean XSLT?
...
Or the article is just trying to be too clever for its own good.
XML and Lisp both have uniformity. What you can express in Lisp, you can express in XML. That's formally true.
But once you've seen S-expressions, XML is so verbose that you want to throw up. You could do what Lisp does in XML, but your fingers would fall off from all the typing, and your eyes would glaze over from reading all the verbiage. You'd fall asleep before you got to the point.
It's really hard to overstate how disgustingly ugly XML is after you've seen the same thing done in S-expressions. I knew XML, and then I learned what S-expressions are (though I don't program in Lisp), and the next time I saw XML I was shocked at how ugly, tedious, and verbose it was.
So, yes, they're equivalent, and no, they're not. The verbosity matters, and it kills the usefulness of XML as a programming language. You could do it, but nobody wants to.
Unless you mean to say you can easily parse XML if you're using an XML parser library, in which case you can just as easily parse any other language using its parser: for example Python using its `ast` module.
XSLT is amazing. And XSLT scripts are really hard to read - just like Lisp is (at least, it is to me).
Xslt itself is complete trash.
- developing an entirely new language in XML was a meh idea, but it was severely lacking making using it difficult unless you were allowed to extend it via custom functions and elements
- the template-as-transform and template-as-function confusion was completely unnecessary and made it much harder to learn and grok than necessary
- but the worst mistake by far was the impliciteness and confusion of `.`, the thing is verbose as all hell, the implicit passing and transformation of the context was completely unwarranted, not unlike Perl’s magical side-effect unless you’re deep in the sauce it makes the entire thing a lot worse, and with even less payout given the general verbosity of XSLT and XML (in perl all the magic provides amazingly terse CLI commands, it’s just a shame people then used that in perl files)
Trying to debug some XSLT right now, every implementation processes the script differently, have reached the point of just declaring that it is broken and using something else.
I should be writing Common Lisp, I get paid for that.
Heh! I haven't touched XSLT for decades. I can't remember it enough to discuss its strengths and weaknesses; all I can remember (weaknesses) was that it dealt badly with namespaces. I think it was invented before XML namespaces came along, and the terseness of XSLT became a horrible mess in the face of namespaces.
I remember being told in about 1996 that XML was the future; the guy that told me was my boss, who was a manager, not a techie. We worked for a document company, and in that sense I think he was right. So I put a fair bit of effort into learning to use XSLT to translate XML data notation into HTML presentation notation.
XML never made the grade as a document notation, and literally nobody I knew wanted to know anything about XSLT.
But yeah, XSLT was a lot like regular expressions - pretty much a write-only notation. Hmm - I just realised that I'm using the past tense, as if it was my dead uncle or something.
And then cakelisp turned out to not really be a lisp according to the author.
Each of these feels completely different to program in, and it's mostly not about the standard library.