Professional Documents
Culture Documents
1. New Tools
2. New Techniques
3. A New Approach
Introduction
Lisp is distinctive.
What makes it distinctive is that it is designed to evolve.
/* C */
int sum (int n){
int i,s = 0;
for(i = 0; i < n; i ++ ) {
s += i;
}
return s;
}
; CL
(defun sum(n)
(let ((s 0))
(dotimes (i n s)
(incf s i))))
but to write (say) a function that takes the number n and returns a *function* that
adds n to its argument
(defun addn(n)
#'(lambda (x) (+ x n)))
Programming languages teach you to not want what they don't provide. You have to
think in a language to write programs in it, and it is hard to want something you
can't describe.
When pg started writing programs in Basic he didn't miss recursion, because basic
doesn't have recursion, and he was thinking in basic, and could only conceive of
iterative algorithm.
addn shows the use of 'lexical closures'. Lisp programs use lexical closures.
Closures are only one of the features of lisp that other languages don't provide.
another unique feature is that lisp programs can be represented by lisp
datastructures . So you can write programs that write programs. (this feature is
called 'macros')
with closures, run time typing and macros, lisp transcends OO. This point is maed
clear in Chapter 17.
Chapters 2-13 introduce all the concepts you need to understand the code in Chapter
17.
The reward for learning this => you will as suffocated programming in C++ as a C++
programmer would feel coding in basic, ** because a C++ programmer knows
programming techniques that are 'natural' to him, but impossible to express in
Basic*.
Almost any program can benefit from having a language tailored to its needs (??)
But the more complex the program, the more valuable bottom up programming becomes.
(KEY) in a b.up program, each layer becomes a sort of programming language for the
one above (??) (_ rough analogy, you write assembler in microcode, C in assembler,
Python in C, then you use Python to write what you want - vs writing what you want
-(say a matrix multiplication program) in microcode. I *think* the idea is that
since 'lisp is extensible' you can do this kind of 'each layer being a different
language' quite easily, wheras each step of microcode to python is quite
significant effort)
Extensibility falls out of bottom up programming. The top most layer of your
program is a programming language for the user.
Programs that use lisp as an extension language - Emacs, Autocad, Interleaf.
Lisp allows you to write shorter programs, but also to write them faster. The
'shorter' effect is amplified by the (repl based) edit-compile-test cycle being
very short.
Unless you know lisp well, the above seem to be a list of grand claims. at the
moment these are 'empty lakes'. But as you gain more experience and see examples of
code, these will 'fill up with water'.
1.3 A New Approach
Less planning (and letting implementation guide the overall design) can mean better
design.
Tempera vs oil painting. Oil 'allows for second thoughts'.
Thoughts:
1. the lisp way *of thinking* is the real takeaway, not the minutiae of Common
Lisp.
2. In languages with gc and first class functions, much of the 'uniqueness' of
lisp is eroded. (say with ruby). The delta is what macros let you do.
3. CL macros != Racket (etc) macros. The latter would seem to be more
sophisticated. Treat learning CL macros as a 'first cut'. Learn Racket and CL
'macrology' side by side.
see
https://stackoverflow.com/questions/19664993/is-it-possible-to-implement-common-
lisps-macro-system-in-scheme.