37 | 37 |
Predicates and Types
|
38 | 38 |
--------------------
|
39 | 39 |
|
40 | |
Because booleans don't actually have a defined representation in
|
41 | |
Pixley, the next few tests are cheating a bit, relying on Scheme's
|
42 | |
defined representation for booleans instead. This would be easy
|
43 | |
to fix up, but a bit tedious: just wrap each of these in
|
44 | |
|
45 | |
(cond (... (quote true)) (else (quote false)))
|
46 | |
|
47 | 40 |
`equal?` works on symbols.
|
48 | 41 |
|
|
42 |
| (cond (
|
49 | 43 |
| (equal? (quote a) (quote a))
|
50 | |
= #t
|
51 | |
|
|
44 |
| (quote true)) (else (quote false)))
|
|
45 |
= true
|
|
46 |
|
|
47 |
| (cond (
|
52 | 48 |
| (equal? (quote a) (quote b))
|
53 | |
= #f
|
|
49 |
| (quote true)) (else (quote false)))
|
|
50 |
= false
|
54 | 51 |
|
55 | 52 |
`equal?` works on lists.
|
56 | 53 |
|
|
54 |
| (cond (
|
57 | 55 |
| (equal? (quote (one (two three)))
|
58 | 56 |
| (cons (quote one) (quote ((two three)))))
|
59 | |
= #t
|
|
57 |
| (quote true)) (else (quote false)))
|
|
58 |
= true
|
60 | 59 |
|
61 | 60 |
A symbol is not a list.
|
62 | 61 |
|
|
62 |
| (cond (
|
63 | 63 |
| (list? (quote a))
|
64 | |
= #f
|
|
64 |
| (quote true)) (else (quote false)))
|
|
65 |
= false
|
65 | 66 |
|
66 | 67 |
A list whose final cons cell's tail contains a null, is a list.
|
67 | 68 |
|
|
69 |
| (cond (
|
68 | 70 |
| (list? (cons (quote a) (quote ())))
|
69 | |
= #t
|
70 | |
|
|
71 |
| (quote true)) (else (quote false)))
|
|
72 |
= true
|
|
73 |
|
|
74 |
| (cond (
|
71 | 75 |
| (list? (quote (a b c d e f)))
|
72 | |
= #t
|
|
76 |
| (quote true)) (else (quote false)))
|
|
77 |
= true
|
73 | 78 |
|
74 | 79 |
A pair is not a list.
|
75 | 80 |
|
76 | 81 |
Actually, pairs aren't defined at all in Pixley, so I wouldn't
|
77 | 82 |
blame an implementation for just freaking out at this one.
|
78 | 83 |
|
|
84 |
| (cond (
|
79 | 85 |
| (list? (cons (quote a) (quote b)))
|
80 | |
= #f
|
|
86 |
| (quote true)) (else (quote false)))
|
|
87 |
= false
|
81 | 88 |
|
82 | 89 |
Booleans are not lists.
|
83 | 90 |
|
|
91 |
| (cond (
|
84 | 92 |
| (list? (equal? (quote a) (quote b)))
|
85 | |
= #f
|
|
93 |
| (quote true)) (else (quote false)))
|
|
94 |
= false
|
86 | 95 |
|
87 | 96 |
Lambda functions are not lists.
|
88 | 97 |
|
|
98 |
| (cond (
|
89 | 99 |
| (list? (lambda (x y) (y x)))
|
90 | |
= #f
|
|
100 |
| (quote true)) (else (quote false)))
|
|
101 |
= false
|
91 | 102 |
|
92 | 103 |
But the empty list is a list.
|
93 | 104 |
|
|
105 |
| (cond (
|
94 | 106 |
| (list? (quote ()))
|
95 | |
= #t
|
96 | |
|
|
107 |
| (quote true)) (else (quote false)))
|
|
108 |
= true
|
|
109 |
|
|
110 |
| (cond (
|
97 | 111 |
| (list? (cdr (quote (foo))))
|
98 | |
= #t
|
|
112 |
| (quote true)) (else (quote false)))
|
|
113 |
= true
|
99 | 114 |
|
100 | 115 |
The empty list can be expressed as `(quote ())`.
|
101 | 116 |
|
|
117 |
| (cond (
|
102 | 118 |
| (equal? (cdr (quote (foo))) (quote ()))
|
103 | |
= #t
|
|
119 |
| (quote true)) (else (quote false)))
|
|
120 |
= true
|
104 | 121 |
|
105 | 122 |
Binding to Names
|
106 | 123 |
----------------
|