Wichtige Formen
| Zweck | Scheme |
|---|---|
| Definition | (define x 5), (define (f a) ...) |
| Funktion | (lambda (x) ...) |
| Lokal | let, let*, letrec, benannter let |
| Verzweigung | if, cond, case, when, unless |
| Zuweisung | (set! x 10) |
| Listen | cons, car, cdr, list, append, map, filter |
| Makro | define-syntax + syntax-rules |
| Fortsetzung | call/cc |
| Ausgabe | display, write, newline, format |
(define (zeile text wert)
(display text) (display " => ") (write wert) (newline))
(zeile "(quote (a b))" '(a b))
(zeile "(list 'a \"b\")" (list 'a "b"))
(zeile "(vector 1 2)" (vector 1 2))
(zeile "(cons 1 2)" (cons 1 2))
(zeile "(string #\\a #\\b)" (string #\a #\b))
(zeile "(exact->inexact 1/8)" (exact->inexact 1/8))
(zeile "(boolean? #f)" (boolean? #f))
(zeile "(procedure? car)" (procedure? car))
(zeile "(list 'quote 'x)" (list 'quote 'x))
(zeile "(char->integer #\\a)" (char->integer #\a))(quote (a b)) => (a b) (list 'a "b") => (a "b") (vector 1 2) => #(1 2) (cons 1 2) => (1 . 2) (string #\a #\b) => "ab" (exact->inexact 1/8) => 0.125 (boolean? #f) => #t (procedure? car) => #t (list 'quote 'x) => (quote x) (char->integer #\a) => 97
Typische Fehler
(display (unbekannt 1))Unbound variable: unbekannt
(display (+ 1 "2"))Wrong type argument in position 2
Weiterführende Quellen
- „Structure and Interpretation of Computer Programs“ (mitpress.mit.edu/sicp, kostenlos online)
- „The Little Schemer“ (Friedman, Felleisen)
- r7rs.org: der aktuelle Standard
- gnu.org/software/guile/manual: Handbuch von GNU Guile
Merke
- Scheme ist minimal, mächtig und ideal, um Programmierkonzepte zu verstehen
- Endrekursion, Closures, Makros und Continuations sind die Kernideen
Aufgabe
Löse die ersten Übungen aus Kapitel 1 von SICP.