by lispm · 11y ago · 0 comments
Oh, not again.
The author is confusing s-expression syntax with Lisp syntax. Even s-expressions are more than lists (conses, cyclic conses, symbols, vectors, strings, various numbers, structures, ...) and the s-expression reader knows about more than pure s-expressions - for example comments.
Not every s-expression is a valid Lisp expression. For example (let "let") is not a valid Common Lisp expression. The syntax for LET is:
let ({var | (var [init-form])}*) declaration* form* => result*
This is also using the syntax definition for 'declaration' and 'form'.Lisp has built-in syntax (provided by special operators in Common Lisp) and arbitrary complex syntax provided by macros.
This is valid for other languages with a notation based on s-expressions, like Scheme or Clojure.
That sentence is an oversimplification to give context to the rest of the content in that section. Should probably have an asterisk to clarify.
Everyone who reads or hears this sentence. I've heard 'everything is a list' a zillion times already. It's just wrong. In every way.
So, it's worth mentioning and replacing with something more accurate.
(john "123" 1) consists of a list, a symbol, a string, an integer
|hi there| is a symbol
#*1010101011 is a bit vector
#2A((1 1 1) (1 1 1)) is a 2d array
and so on.Also look up the current Scheme report and see its syntax definition. 'Everything is a list' is fooling the reader and treating him/her like an idiot.
If you pick up just about any book on Lisp, it's all about recursion and lists. I don't remember SICP talking about native vectors or hash tables. I don't remember Touretzky talking about those either (maybe it was just that I had an early edition (1988-ish?) or my memory was faulty). Certainly The Little Lisper/Schemer never talks about them.
The first book I remember talking about other primitives in Lisp was Siebel's "Practical Common Lisp".
There are quite a few pernicious fallacies the swim around the "everything is a list", "S-exprs are easy to parse because they're uniform" (oh, really? Try identifying a list in the presence of dotted pairs), etc.
In Lisp the cons structure is actually the primitive. Lists are built on top.
Indeed the article begs for potshots from smug lisp weenies:
1) It's clearly talking about Clojure, yet leads with "Let's simplify the way we write Lisp". Them's fighting words in the Lisp corral.
2) Paredit clone, but only acknowledges that for animations.
3) No emacs version! (Understandable given #2 however)
Then again what he says is true for 99% of the cases, and a good simplification.
>Even s-expressions are more than lists (conses, cyclic conses, symbols, vectors, strings, various numbers, structures, ...)
Still expressed as lists when it comes to the syntax level.
It's not. Read it slowly: only a subset of s-expressions are valid Lisp programs. Examples for invalid Lisp programs, even though valid s-expressions:
(cl:if x > 1 t nil) ; IF takes 2 or three forms
((cl:lambda) (a) a) ; not a valid lambda expression
(cl:let "a let expression" ((a 1)) (+ a 1)) ; the second element should be a list of bindings
(cl:defun foo args (length args)) ; arguments needs to be a list
(cl:let ((a nil t)) a) ; a binding is a variable or a list of symbol/value
and so on.Lisp syntax is not the syntax of s-expressions. Lisp syntax is defined ON TOP of s-expressions.
> Still expressed as lists when it comes to the syntax level.
Comments are not expressed as lists. Feature expressions are not lists. etc etc...
Sure, but the thing we're debating is whether "all s-expressions are valid Lisp programs" (that would be a miracle actually), but whether Lisp syntax is all lists.
And all those examples are still lists -- that the lists can also contain other items inside them, or that underneath they are implemented as cons etc, doesn't really change that.
>Comments are not expressed as lists.
They are not retained anyway when the strings are parsed to the "live" AST (AFAIK), so they are an exception to the other syntax in that too.
> Most programming languages have several syntax rules. Lisp has one: everything is a list. The first element is a function name, and the rest are its arguments. Thus, the language is simply a collection of compile- and run-time functions, trivially extensible.
Step by step.
> Lisp has one syntax rule: everything is a list.
That's wrong. completely wrong. 'everything is a list' is not THE ONE syntax rule of Lisp. Lisp, like most other programming languages, has MANY syntax rules.
A defining feature of current Lisp dialects is even that the syntax rules are programmer extensible and thus Lisp has an unbounded number of syntax rules. Thus the complete opposite is true: Lisp has arbitrary many syntax rules.
> The first element is a function name, and the rest are its arguments.
That's also wrong. It always was. Lisp has since day zero supported more than just function call forms.
Valid Lisp expressions:
3
"1 2"
((lambda (a) a) 1) ; (lambda (a) a) is not a function name
(defun foo () ()) ; defun is not a function name
(let ((a 1)) a) ; let is not a function name
> Thus, the language is simply a collection of compile- and run-time functions, trivially extensible.I would not even know what that actually might mean...
alists are not expressed as lists.