git @ Cat's Eye Technologies Robin / 62703a4
Check arg count manually in `and`/`or`; refine `bind-args`. catseye 12 years ago
3 changed file(s) with 36 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
33 ### `bind-args` ###
44
55 | (robin (0 1) ((small (0 1) *) (bind-args (0 1) *))
6 | (bind-args (a b) (list 1 2)
6 | (bind-args (a b) (1 2)
77 | (list a b)))
88 = (1 2)
99
10 Expressions in the list of values are evaluated.
11
1012 | (robin (0 1) ((small (0 1) *) (bind-args (0 1) *))
11 | (bind-args (a b) (list 1)
13 | (bind-args (a b) ((subtract 5 4) (subtract 10 1))
14 | (list a b)))
15 = (1 9)
16
17 Too many or too few arguments will raise an `illegal-arguments`
18 exception.
19
20 | (robin (0 1) ((small (0 1) *) (bind-args (0 1) *))
21 | (bind-args (a b) (1)
1222 | (list a b)))
1323 ? uncaught exception: (illegal-arguments (1))
1424
1525 | (robin (0 1) ((small (0 1) *) (bind-args (0 1) *))
16 | (bind-args (a b) (list 1 2 3)
26 | (bind-args (a b) (1 2 3)
1727 | (list a b)))
1828 ? uncaught exception: (illegal-arguments (1 2 3))
29
30 The literal arguments are reported in the exception.
31
32 | (robin (0 1) ((small (0 1) *) (bind-args (0 1) *))
33 | (bind-args (a) ((subtract 5 4) (subtract 1 0))
34 | a))
35 ? uncaught exception: (illegal-arguments ((subtract 5 4) (subtract 1 0)))
33 (let (
44 (bind-args
55 (macro (self args env)
6 ;''(head args) is the literal list of identifiers;
7 (eval env (head (tail args))) is the list of
8 values to be bound to those identifiers.''
96 (let (
10 (id-list (head args))
11 (orig-val-list (eval env (head (tail args))))
12 (expr (head (tail (tail args))))
13 (bind-args-r (fun (self id-list val-list env-acc)
7 (id-list (head args))
8 (orig-val-list (head (tail args)))
9 (expr (head (tail (tail args))))
10 (bind-args-r (fun (self id-list val-list env-acc)
1411 ;''This will need to be converted into a macro at some point,
1512 but for now, this is easier.''
1613 (if (empty? id-list)
2118 (raise (list (literal illegal-arguments) orig-val-list))
2219 (self self (tail id-list) (tail val-list)
2320 (prepend
24 (list (head id-list) (head val-list))
21 (list (head id-list) (eval env (head val-list)))
2522 env-acc))))))
2623 (new-env (bind-args-r bind-args-r id-list orig-val-list env))
2724 )
0 (robin (0 1) ((small (0 1) *) (env (0 1) *))
0 (robin (0 1) ((small (0 1) *) (env (0 1) *) (list (0 1) *))
11 (let (
22 (and (macro (self args env)
3 (if (eval env (head args))
4 (if (eval env (head (tail args))) #t #f)
5 #f)))
3 (if (equal? (length args) 2)
4 (if (eval env (head args))
5 (if (eval env (head (tail args))) #t #f)
6 #f)
7 (raise (list (literal illegal-arguments) args)))))
68 (and* (macro (self args env)
79 (if (equal? args ())
810 #t
1618 (conj (fun (li)
1719 (conj-r conj-r li)))
1820 (or (macro (self args env)
19 (if (eval env (head args))
20 #t
21 (if (eval env (head (tail args))) #t #f))))
21 (if (equal? (length args) 2)
22 (if (eval env (head args))
23 #t
24 (if (eval env (head (tail args))) #t #f))
25 (raise (list (literal illegal-arguments) args)))))
2226 (or* (macro (self args env)
2327 (if (equal? args ())
2428 #f