-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchap1.scm
65 lines (50 loc) · 2.04 KB
/
chap1.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#lang scheme
; 1. the atom is a string of characters beginning with a letter or special character
; other than a left "(" or right ")" parentheses.
;
; 2. the list is a collection of atoms or S-expressions enclosed by parentheses.
; 2.1. () is the special S-expression, which contains zero S-expressions enclosed by
; parentheses, is called the null (or empty) list.
;
; 3. all atoms and lists are S-expression.
; (car l)
; 4. the car is the first atom of a list, or the first S-expression of a non-empty list.
; 4.1. you cannot ask for the car of an atom.
; 4.2. you cannot ask for the car of an empty list.
; (cdr l) <could-er>
; 5. the cdr is the list wihout (car l).
; 5.1. you cannot ask for the cdr of an atom.
; 5.2. you cannot ask for the cdr of a null list.
; Q: what does car take as an argument?
; A: it takes any non-empty list.
; Q: what does cdr take as an argument?
; A: it takes any non-empty list.
; (cons a l) <cons the atom a onto the list l>
; 6.1. cons adds an atom to the front of a list.
; (cons s l)
; 6.2. cons adds any S-expression to the front of a list.
; Q: what does cons take as it arguments?
; A: it takes 2 arguments:
; the 1st one is any S-expression;
; the 2nd one is any list.
; In practice, (cons \alpha \belta) works for all values \alpha and \belta, and
; (car (cons \alpha \belta)) = \alpha
; (cdr (cons \alpha \belta)) = \belta.
; (null? l)
; Q: is it true that the list l is the null list, where l is ().
; A: Yes.
; (null? '())
; Q: what is (null? (quote ()))?
; A: True.
; you cannot ask null? of an atom.
; In practice, (null? \alpha) is false for everything, except the empty list.
; (atom? s)
; Q: how many arguments does atom? take and what are they?
; A: it takes one argument.
; the argument can be any S-expression.
; (eq? a1 a2)
; Q: how many arguments does eq? take and what are they?
; A: it takes 2 arguments.
; both of them must be non-numeric atoms.
; In practice, lists may be arguments of eq?. Two lists are eq? if they are the same list.
; In practice, some numners may be arguments of eq?