181 points · by behnamoh · 4y ago · 128 comments
But in the comments here and as with most articles about Lisp, the conversation moves to... can newcomers understand Lisp's syntax? My spouse and I gave a talk about this very topic: "Lisp but Beautiful; Lisp for Everyone". https://fosdem.org/2022/schedule/event/lispforeveryone/
There's a lot in there (including demonstrations of representations of lisp which don't have parentheses at all). But the biggest point in the talk is that lisp isn't scary for new programmers... it's scary for experienced programmers. As we talk about in the video, my spouse and I co-ran introductions to programming using Racket aimed at humanities students with no required prior programming experience whatsoever.
What we found was that the students who had no prior programming experience, after just a few minutes, had no problem with the syntax (and DrRacket made it easy enough to pick up the language). But we did have complaints in the class about lisp's syntax... from those who already knew how to program. They already had a frame, and within that frame, lisp's syntax looked alien. Without a frame, students just accepted it and did fine with the syntax... great, even. (Many of them praised its clarity; like any decent lisp editor, DrRacket helps identify the kinds of parentheses-oriented errors that users think they're going to encounter.)
Anyway, I do more work in Guile these days than Racket, but both are really great systems with great communities. The thing I miss most about Racket though is that DrRacket gave an easy entry point for students which wasn't "and now start learning Emacs". (Guix is pretty great, however.)
However, Lisps have unparalleled macro flexibility. It’s a clear trade-off that Lispers often have trouble admitting is a trade-off.
I'm kind of curious how much of this is the problem with parens, and how much of this is the conventions that Lisp programmers seem to mostly adopt. For instance, here's the concise 99-bottles from Rosetta Code for Racket:
(define (sing bottles)
(define (plural n) (~a n " bottle" (if (= n 1) "" "s")))
(printf "~a of beer on the wall\n~a of beer\n~
Take one down, pass it around\n~a of beer on the wall\n\n"
(plural bottles) (plural bottles) (plural (sub1 bottles)))
(unless (= 1 bottles) (sing (sub1 bottles))))
(sing 99)
And even with a snippet this short, it's not quick for me to scan. Lispers generally like hanging parens, the indentation varies depending on what construct you're in, and that example uses recursion instead of a for-loop [0].Ok, so let's turn the concise Python one into a hypothetical Lisp:
(for i in (range 99 0 -1)
(let b = "bottles of beer")
(let w = "{b} on the wall")
(print "{i} {w}, {i} {b}\n")
(print "Take one down and pass it around, {(- i 1)} {w}.\n")
)
I think you could "know generally what things are" with that version even if it was blurry. And of course, this "hypothetical lisp" is legal Racket/Scheme after implementing a few macros.[0] I know Racket has for loops, but they didn't choose to use them in that example. Which is my point.
1> (defun bottles-verse (n)
(flet ((bottles (:match)
((0) "No bottles")
((1) "1 bottle")
((@x) `@x bottles`)))
(put-line `@(bottles n) of beer on the wall\n\
@(bottles n) of beer\n\
Take one down; pass it around\n\
@(bottles (pred n)) of beer on the wall\n`)))
bottles-verse
2> [mapdo bottles-verse 5..1]
4 bottles of beer on the wall
4 bottles of beer
Take one down; pass it around
3 bottles of beer on the wall
3 bottles of beer on the wall
3 bottles of beer
Take one down; pass it around
2 bottles of beer on the wall
2 bottles of beer on the wall
2 bottles of beer
Take one down; pass it around
1 bottle of beer on the wall
1 bottle of beer on the wall
1 bottle of beer
Take one down; pass it around
No bottles of beer on the wall
nil
3>
Why does 5..1 go from 4 to 1? Because 1..5 goes from 1 to 4; it's a half-open interval.
5..1 goes over the same values in reverse.:match is a "parameter list macro", which is something I invented. flet knows nothing about pattern matching; it transforms to a lambda, which also knows nothing about pattern matching, but :match takes the parameter list and body, transforming the code using the pattern expander logic.
String literals and quasiliterals can go across multiple lines, but with the permission granted by a continuing backslash. Being explicit about this lets us catch errors when a literal is left open accidentally. All unescaped whitespace before a continuing backslash, and leading whitespace at the start of the next line is deleted:
"abcd \
efgh" -> "abcdefgh"
"abcd \
\ efgh" -> "abcd efgh" ;; escaped space counts
"abcd\ \
efgh" -> "abcd efgh" ;; on either side of \Off topic (sorry) but one thing Racket is missing is great Python interop to mix in deep learning and other libraries. Common Lisp and Clojure have this support. Years ago I tried saving trained Keras weights and using them in Racket with the Matrix support: it works, but not very fun to use.
I think Scheme is awesome as long as it's not your first language, but I think if Scheme is your first introduction to CS particularly in college, it can be pretty brutal depending upon the instructor. I think a lot of higher learning institutions were trying to copy MIT's use of SICP for their intro courses.
To what, Art History? Poli Sci?
After a few weeks it "clicked", and since then I've been a huge fan of Scheme. When other students went out of their way to write C-to-Scheme converters to keep coding their homework in C, if you fully embraced the language it felt something close to enlightenment ;-)
I used Scheme later to teach programming to absolute non-science people and they all simply "got" how it worked, even though they had previously struggled doing even very basic things in Excel Macros and the like.
Scheme is a perfect tool for learning how to program, and it is even useful later to write complex programs in production. Yes, C might be faster, and Python might have more hits on StackOverflow, but to really understand the concepts behind polymorphism, recursion, lazy evaluation, oop, etc. Scheme helps a lot with it's simple syntax.
I still think the clojure syntax and immutability semantics are prettier than racket's but that's just my own vanity. I'm back on racket for the reasons mentioned in the article pretty much: good fundamental language, big and practical standard library, plus every freak academic CS thing you could ever want to play with available as well.
The tooling and community also encourage you to think of problems in terms of DSLs, something it partially shares with ruby as well. That approach isn't always a good fit, or one you can get buy-in for, but when it works it works well for me.
[0] see python talks about not using classes for single method cases which are just fat closures. Yet it's still often used.
I have an abacus that has better perf than Python, so I’d say this is a safe bet :P
The anti-Microsoft bias at the time was pretty strong in most of the open source community given the various dirty tricks that had been employed against Linux around 2000. Within the corporate world there was a big strategic split between folks who were all-in on microsoft and .NET vs people who wanted open source and Java (I worked at a big bank at the time and this was a very sharp point of division with careers made and broken on the back of tech choices, fear or otherwise of vendor lock-in etc).
As for MS's strategy, my recollection is at the time MS was all-in on C# and trying to replace C++ and Java rather than pushing F#, which was somewhat of a side-gig for them. Visual Studio was very dominant in terms of IDE then both for C++ and C#, with only Java guys and unix nerds like me using anything else.
(1) Here getting confused with scopes. E.g. assigning variable in one function and using it somewhere else, mixing global/local scope, assign/use order. Looking at that I was thinking a language that has more explicit and strict way to declare variables and look at scopes is probably better for beginners. The alternative with Python is that it can be somewhat confusing, and at times you see them only if they get executed. Racket definitely doesn't have that problem. It is as obvious as it can be.
(2) If your introduction is through some kind of project (data science, web app ...) you'll likely be using some object oriented features from very beginning. I saw her getting confused with `foo()` vs `foo.bar()` vs `foo.bar`. There was definitely a big gap in her understanding, but I think Racket's focus on functional paradigm and most libraries being that way -- is somewhat a nicer experience for beginners.
Overall, Racket is a simple language but can get fancy as far you'd want it to, so I think the barrier of entry is probably better than Python.
Local/lexical scoping is really a code structure/management/scaling thing. A name management system if you like.
As the joke goes, the two biggest problem in CS are naming and caching.
I had the same problem when learning Python. Top that up with mutable and non-mutable structures and it can get very hard to make sense of Python as a beginner.
I remember I had a theory that foo.bar() would change foo and bar(foo) would return a value while leaving foo unchanged ... that turned out to be very wrong.
It also took me forever to realize that when you call foo.bar(), foo is the first argument of bar().
Racket Is an Acceptable Python - https://news.ycombinator.com/item?id=20392448 - July 2019 (168 comments)
Both use a lot of "english" phrases which makes it easier for the novice to understand basic control structures.
I don't love Java/C++/JavaScript but I do like their backward compatibility (though JavaScript packages/libraries are often quicksand.)
Racket is a far more powerful tool, but also less immediate to learn, especially for those who have a background with imperative languages, not fast at all to fire up and not easy to use as a glue for anything else.
Python is a kind of bridge from unix shell scripts not so many nowadays have practice with and a script-versed programming language. Racket is about programming in classical terms, with an unique ecosystem.
In that sense probably Smalltalk with Pharo or classic (old) Lisp with Emacs are more acceptable Python since they do not act as a glue but they are FAR more immediate to use and have a purpose on it's own behind programming: they are end-users programming environments, as Python is an end-user scripting tool.
Every time I dreamed of code, I could never actually get what language I was writing in.
But, each time, the code text was wrapped thin and was long.
The theme was just perfect. I have looked at a lot of themes and color-schemes for vim (and terminal) and VS Code, but could not match the one from the dream.
It was just perfect.
And although I write a lot of Python, I think the code I dreamt of was typed.
> We found the age-old belief that "lisp syntax is just too hard" is simply false; the main thing that most people lack is decent lisp-friendly tooling with a low barrier to entry, and DrRacket provides that.
If the syntax requires special tooling to make it usable, isn't that a sign that the syntax is hard?
Are there many people who believe Lisp syntax is as easy as Python or other non-Lisp languages? If that's true for you, I'd be interested in hearing more about your experience.
But a kid with no previous exposure to programming is nothing like your average developer with strong pre-existing conditioning about how programming languages must look like. And this is the issue I feel with a lot of folks complaining about Lisp syntax. It's easy but it's not _familiar_ and some find it harder than others to get used to this discrepancy.
I'd also end up in not great places when utilizing parinfer while editing code written using different formatting than what parinfer expected. I'd have to fall back to paredit and hope for the best.
This is all to say that yes, sometimes editing lisp syntax is "hard", at least for me. Turns out some humans make so-so AST parsers.
That said, structural editing is great once you get good at it, and something I miss back in other languages.
That's the punishment for removing some of the "reduntant" parentheses from Scheme.
Compare
Clojure: (let [a 1
b 2]
(+ a b))
Scheme: (let ([a 1]
[b 2])
(+ 1 2))
If for some reason, say, `b` get deleted a Scheme compiler can tell you which binding pair has a problem.In more complicated setups, in Scheme/Racket I indent the piece of code, and from the indentation I can see, where end parenthesis is missing.
Mess up Python indentation and you get something like that, but worse.
You should be able to indent the code automatically and then the wrong subordination of the pieces shows up as wrong indentation.
Like, e.g. what you think should be inside some conditional statement isn't intended at the expected level for that role.
It's not a huge hurdle and other languages have equivalent problems. But the lisp one is particularly ill-suited to other tools, even visual techniques like manually aligning indents.
I've taught programming to beginners, including lisps, and it's definitely one of the early disorientations even without prior expectations about code. You don't need much: I eventually settled on just giving them sublime with rainbow parens and telling them to hit enter a lot. But you need something and it's not obvious what's missing unless someone points you in the right direction.
I've met a lot of folks that seem to possess mental models that are fundamentally mismatched with what Lisp expects: It's not just the syntax but a lot of the base models of the language that demand an open mind and time involvement before they get imprinted. And at least in some cases, blaming the parens becomes the easy way out of why one doesn't get it.
The base case is simple enough, the symbol-function value of the first symbol in a list is looked up, the rest of the arguments are evaluated or self-evaluated, then passed in to the function. The problem is that when the first symbol is a macro, you need to remember which of the following arguments are evaluated, or taken as unevaluated forms. Anyone who thinks this is easier to parse because there's less syntax either has too little experience with Common Lisp, or is kidding themselves.
However, the vocabulary part of a Lisp dialect consists of things which are named. Names can easily be looked up in documentation.
Furthermore, you know what is and is not part of the form even if you don't recognize the operator: you know that (fnoozle blub (grogg)) q42 is invoking fnoozle with two argument expressions, and q42 has no part of it. You don't know how/if those two arguments are evaluated but if you look up fnoozle in the manual, it should be clear. The manual will talk about the arguments, and you can identify which of those is blub and which is (grogg).
Even so there are some syntactic hints in terms of symbol naming, like how you can be pretty confident that a form that starts with WITH- is probably some kind of UNWIND-PROTECT macro that grabs a resource and cleans up after itself. Another example is that a symbol with asterisks for the first and last characters names a special variable.
I've always been scared of Lisp syntax, but after just a little experience with it it all kind of fades away and it feels like an indentation-based language, while remaining very compact. Now I'm like "why aren't all higher-level languages lisps"?
Editor tooling definitely helps, but it's one of those "skill floor skill ceiling" ideas. Parenthesis-based syntax has a slightly higher "skill floor" (takes more effort to edit), but with editor tooling has a much higher "skill ceiling", where experts can move blocks at the level of syntax rather than characters. Even just vscode's new bracket highlighting and guides are a small feature but a big help to see structure.
For parentheses, I find Racket and in particular Scheme to be enjoyable. My primary reasons are that it creates a massive amount of regularity and consistency in the language, of which there is none in Python. I had my girlfriend at the time take the How to Code: Simple Data course on edX, which uses the Racket learning languages. Not once did I need to answer a syntax question. Not one complaint about parentheses. She had no prior experience programming.
I find the people who whine and moan about parentheses are usually ones who have massive preconceived notions of what programming should look like or are so deep in some other language they are resistant to change.
I honestly feel like the best textual syntax is something like ML (as found in F#) or Scheme. Anything else is basically just random tweaks and way too much time has been wasted on textual syntax, which is conceptually bounded in terms of its expressiveness. But programmers and computer scientists are extremely myopic. Somehow we graduated from punch cards to text files and have plateaued ever since.
> decent lisp-friendly tooling with a low barrier to entry, and DrRacket provides that
I'm not really sure what the commenter meant by that, but in my experience, all I ever needed was the auto-formatter and parentheses matching DrRacket provides. Matching delimiters occurs in any language, it's just that you have more of them.
So, do you write your code on Notepad?
It's interesting that every time Lisp syntax comes up there's a comment like this. But when someone adds "refactoring" and "intellisense" to other languages it gets applauded. Why?
You dont need special tools. But being able to manipulate the sexpressions directly gives you more power.
If we were discussing teaching apprentice roof installers, you wouldn't argue that collated nails (the kind that feed into a nail gun) are worse for teaching because they are harder to use without additional tooling (a nail gun). The 'additional tooling' is in fact industry standard tooling that the apprentice will be using from the very start anyways, and that they need to be comfortable with as well.
Worst case, you can align your parens vertically, like many AutoLISP programmers did when their only tool was Notepad or EDIT.COM. And usually incorrect parens result in code blowing up at build time, not runtime. Counting parentheses is definitely easier than counting whitespace.
If anything, Lisp just happens to be language with community that embraced quite advanced editor enhancements before many other languages got invented, and thus lisper's baseline expectations might be bigger than other developers'
I still like “think python” as an introductory text to programming https://greenteapress.com/thinkpython/html/index.html - and I’d still go python if the goal was a specific one-off outcome.
But now that I’ve gone through HTDP, that’ll be my textbook for beginners http://htdp.org/2022-2-9/Book/part_preface.html
Heavy book to drag to community evening classes though…
Python is "battery included" in the sense that with the language it's users can access a rich set of ready-usable code pip-able in a venv without any special gimmick and python itself is probably preinstalled in most desktops people who ever write a line of code use, that means python is not a stranger, it's a citizen of a familiar and ready made ecosystem for most users.
Lisp on contrary have many flavors, syntax is similar, but here is (defn, here (defun, ... and CL is still complex and not such immediate. QuickLisp is not here by default etc. Lisp is a stranger in most user's familiar ecosystem.
Non only Lisp is from a civilized age where computer were desktops, a unique ecosystem at the users fingertips, centered on users needs and desire. In that sense lisp is an ecosystem, not a part of a larger ecosystem the user already know. Again a stranger.
Once you know a bit let's say SBCL or Emacs it's far easier implementing something that do not demand something ready-made and absent (the aforementioned battery included) BUT if nobody teach them and only very few know them...
I say that fly a small plane is easier than drive a car, but while I do both things most people do not and so for them I say something alien and the subject of the topic is also alien to them. Most think that's easier turning the steering wheel obtaining a definite result instead of gently hit a stick to see loose effects. Of course that's true, if you are bound to a little path named a road, more specifically a small part of it, however it's far easier NOT being bound to such small areas and loosely move in the air, with far less strict limits all around. You have to try to understand though and so someone have to tech you up front... That's the modern Lisp issue...
That's a very interesting observation. It's also interesting in that when you get back to "high traffic" areas where you have to interact with others, the limits get stricter again.
I'll probably torture that analogy for a while.
I think it is easier to put a nail through a 2x4 than a push-pin, but that presupposes I have a hammer; if I have a nailgun it's going to be easier to put 100 nails in than 100 push-pins. If I have neither, then the push-pin wins. There are always tradeoffs, but it doesn't mean that nails are inherently "hard" and push-pins are inherently "easy"
Even with python I find myself getting bogged down by missing a parenthesis here and there around function calls, but perhaps that problem is unique to me and my attention and memory issues. Syntax highlighting in editors is great, and certainly it helps me, but I wish for them to be even more interactive and assertive: it should mark fields with obvious errors like unclosed quotes and parentheses, I shouldn't have to wait after compile or run-time to be informed of these errors.
Aid that reduce syntax errors should always be welcome. Moreover, some of us have high working memory and some don't so I welcome opinionated tools like Spyder IDE and Jupyter that are hands-on in the dev stage, and serve to encourage a fun and exploratory dev environment.
It's surprising how many professional devs don't have this habit. I learned it pairing one day.
PyCharm does that and more.
What editor are you currently using?
When I was little my dad had a reverse polish notation calculator he explained and taught me to use. I think it was sort of a novelty for him, but when I encountered lisp in college my first thought was something like "oh this is just like reverse polish calculators".
There was sort of a strange learning curve for me though. The basics were fairly intuitive to me, then things got frustrating, and then easier again.
I really miss lisp though and wish it (or scheme or racket) had more widespread use, especially in numerical computing. I admit, though, that the hardware-lisp gap is bigger in my mind than the hardware-c gap, which extends to more procedural languages.
IMO Lisp's is hard, but simple; Python's is hard and complex.
Tooling can make it easier (keeping track of parentheses and significant whitespace, respectively), but not simpler.
The TXR language was developed using nothing but Vim, for all the C and Lisp code.
The tooling is the same as for C: indentation, coloring, parenthesis matching, and that's more than you need.
E.g. visually select some code with V and cursor movement, then hit =, and it's nicely reindented.
Vim's Lisp indentation is based on the classic Vi ':set lisp' mode which was in Unix since 1980 something. That is combined with some generic autoindent settings, most of which are pretty much the same as for C.
GNU mkid (from the id-utils project) indexes Lisp like other languages for quickly finding all references to an identifier.
Exuberant Ctags recognizes Lisp files, for jump-to-definition.
People who talk about special tooling for Lisp must be coming from the perspective of Nano or Notepad.
Or else from the perspective of "any programming editor which is not the one I know is 'special tooling', and the one I know doesn't recognize any Lisp file suffixes."
It doesn't. Lisp is perfectly editable in Vim, with basic indentation and syntax highlighting. Lisp's properties make it easy to work with even in that type of basic editor without special Lisp support.
Exuberant ctags indexes Lisp code for jump to definition.
Not in this case. Lisp syntax is easy, people lack familiarity.
The only "hard" part is checking that the number of parens are right. But it's not that other programming languages don't have equivalent "hard" problems, like closing the right kind and amount of brackets on C, of whitespace problems in python.
In Linux I'm using Geany https://www.geany.org/ with almost the default highlighting. The only change I made was to make the good and bad matches of parenthesis more visible. (In the default, the color of the parenthesis changes from black to blue or red, but it's too difficult to see. I changed it so the color is black but the background is blue or red. It's just a two lines change in the style, not special tool.)
In Windows I'm using WinEdt https://www.winedt.com/ and using again almost the default highlighting.
My recommendation is to mix () with [] and {} as recommended unofficially, instead of using only (). [For my personal code I use a few more [] and {} than the standard. I use [] for long [begin ...] blocks and {} for {define ...}. That helps a lot to find the problems.]
1. https://github.com/racket/rhombus-prototype/blob/master/reso... 1. https://beautifulracket.com/appendix/why-i-no-longer-contrib...
How is that the community's problem?