by metroholografix · 4y ago · 0 comments
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.
When they wanted their programs executed by a computer, their editor -Edwin- matched parens, exactly like how one would do it today, or even easier with things like Paredit.
What's more challenging in Scheme, as Abelson and Sussman teach it, is the use of recursion instead of looping and in particular understanding that recursion is only equivalent to looping when the recursion is in "tail position", i.e. when there is nothing left for the calling function to do except return to its own caller.
Common Lisp style tends to use looping, not recursion.
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.