[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [ ? ]

5.3 A note on lisp

In a language like C you have some procedures that are the names of functions. And the function is maybe built in to the language or in some standard library, and when you call it, maybe you call it with the name of the function and then a list of arguments in brackets or something. But then you maybe have built-in keywords which you call another way, and then you have ‘operators’ like ‘+’ or ‘-’ or ‘*’ or ‘^’ or something and maybe they use infix notation ‘(a * b)’ or maybe not. Or maybe they are some random thing like the add one operator ‘(a++)’.

In lisp the most important 90% of the syntax takes five minutes to learn. You use lists for most everything, and a list is always in parens, like ‘(a b c d)’ and the convention is the first item in a list is always a procedure name (a function or a macro, etc.), and the rest is always args to that procedure—polish notation style. So to add two numbers it’s:

 
(+ a b)

To assign that to a variable you use a function that does that. We can use ‘setq’ in this case:

 
(setq some-variable (+ a b))

Note that since the syntax is so simple and consistent we can thus nest statements arbitrarily where we use a function as an argument to another function as above. So the basic structure of the program as a set of procedures remains visible and transparent, as it were. You can do that in other languages, but because the syntax is inconsistent, the code quickly becomes un-readable.

Signature glyph

 
Based on an email to
Steve Clarian 2006.7


[ Thorne's Great Big Book of Etceteras | Last build: 2008.08.19 ]
contact | pubkey | vcard | permalink | rss | search
Imprint of TtlÄxia-Verlag