| > In lisp, nearly everything is written in the same form. I.e. everything either is a function call or looks like one. Once you know that, you pretty much know lisp syntax. Actually not. Lisp has several types of forms. A function call is one. There are atleast two others: macro forms and special forms. function form with + (+ 1 2)
macro form with DEFUN. The syntax for DEFUN is: defun function-name lambda-list [[declaration* | documentation]] form*
The function name the is either a symbol or a list of (setf name). The lambda-list has complex syntax with optional, aux, rest and keyword arguments, declaration has a complex declaration syntax, etc...The third type of form would be built-in syntax. LET is an example. The syntax for LET is: let ({var | (var [init-form])}*) declaration* form* => result*
This means that (let ((a 1)
b)
(setf b a))
is a valid program.This is not a valid Lisp program, which Lisp will complain about: * (let ((a 1 2)
b)
(setf b a))
; in: LET ((A 1 2) B)
; (A 1 2)
;
; caught ERROR:
; The LET binding spec (A 1 2) is malformed.
Reason: Lisp expects that bindings are either symbols, lists with a single symbol or pairs with a symbol and a value form. (a 1 2) thus is not valid.Is Lisp syntax easy? Once you look deeper, it actually isn't. Only a core language with only function calls is relatively easy. * Lisp writes programs on top of a data structure called s-expressions. S-expressions are easy, Lisp not. * Lisp usually has the operator as the first element of a lisp -> uniform appearance. * Lisp has some built-in syntax. Usually as little as possible. * Lisp lets the developer add new syntax via macros -> zillions of macros and the user needs to learn a few patterns to understand Lisp code. |
If you squint a bit, macros and built-ins are similar in structure to functions (they're all s expressions).
I agree with much of what you said, but I still maintain that lisp syntax is still relatively trivial compared to most languages.
I also don't think exposing newcomers to macros on a language that is homoiconic is terribly useful until they're already comfortable with the basic s-expression syntax.