Wichtige Funktionen
| Funktion | Bedeutung |
|---|---|
car / first, cdr / rest | Kopf und Rest |
cons, list, append | Listen bauen |
mapcar, reduce, remove-if | Higher-Order |
funcall, apply | Funktionen aufrufen |
let, setf | Variablen |
defun, defmacro, lambda | Funktionen/Makros |
loop, dolist, dotimes | Schleifen |
format | Ausgabe |
gethash, make-hash-table | Hashtabellen |
defstruct, defclass | Datentypen |
(let ((tabelle '(("length" . 3) ("reverse" . 3))))
(dolist (zeile tabelle)
(format t "~10a ~a~%" (car zeile) (cdr zeile))))
(format t "~a~%" (list (type-of 1) (type-of 1/2) (type-of 1.0d0) (type-of #\a)))
(format t "~a~%" (list (equal '(1 2) '(1 2)) (eq 'a 'a) (eql 1.0 1.0) (= 1 1.0)))
(format t "~a~%" (list (string 'abc) (symbol-name 'xyz) (intern "FOO")))
(format t "~a~%" (loop for i below 5 collect (expt 2 i)))Ausgabe
length 3 reverse 3 (BIT RATIO DOUBLE-FLOAT STANDARD-CHAR) (T T T T) (ABC XYZ FOO) (1 2 4 8 16)
Typische Fehler
(print (undefined-funktion 1))Fehlermeldung
The function COMMON-LISP-USER::UNDEFINED-FUNKTION is undefined.
(print (+ 1 "2"))Fehlermeldung
The value "2" is not of type NUMBER
Weiterführende Quellen
- „Practical Common Lisp“ (Peter Seibel, kostenlos online)
- „Common Lisp the Language“ und die HyperSpec (lispworks.com/documentation/HyperSpec)
- „Land of Lisp“ und „On Lisp“ (Paul Graham)
- lispcookbook.github.io/cl-cookbook
Merke
- Lisp: Code ist Daten, Makros erweitern die Sprache, die REPL treibt die Entwicklung
- CLOS, das Condition-System und der Compiler machen Common Lisp zu einer vollwertigen Industriesprache
Aufgabe
Schreibe ein Makro mit-zaehler, das Aufrufe einer Funktion zählt.