git @ Cat's Eye Technologies Robin / 04e283e
Rewrite `itoa` and `not` as functions. Chris Pressey 1 year, 5 months ago
2 changed file(s) with 22 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
2222 | (itoa (literal m))
2323 ? abort (expected-number m)
2424
25 | (itoa)
26 ? abort (illegal-arguments
27
28 | (itoa 100 101)
29 ? abort (illegal-arguments
30
2531 '<<SPEC'
2632
27 (define itoa (fexpr (args env)
28 (bind itoa-r (fexpr (args env)
29 (bind-args (self val) args env
30 (if (equal? val 0)
31 ()
32 (let ((digit (remainder val 10))
33 (rest (divide val 10)))
34 (prepend (add 48 digit) (self self rest))))))
35 (bind-args (val) args env
36 (if (equal? val 0)
37 (list 48)
38 (if (lt? val 0)
39 (prepend 45 (reverse (itoa-r itoa-r (subtract 0 val))))
40 (reverse (itoa-r itoa-r val))))))))
33 (define itoa (fun (val)
34 (bind itoa-r (fun (self val)
35 (if (equal? val 0)
36 ()
37 (let ((digit (remainder val 10))
38 (rest (divide val 10)))
39 (prepend (add 48 digit) (self self rest)))))
40 (if (equal? val 0)
41 (list 48)
42 (if (lt? val 0)
43 (prepend 45 (reverse (itoa-r itoa-r (subtract 0 val))))
44 (reverse (itoa-r itoa-r val)))))))
1313 `not` expects exactly one argument.
1414
1515 | (not)
16 ? abort (illegal-arguments ())
16 ? abort (illegal-arguments
1717
1818 | (not #t #f)
19 ? abort (illegal-arguments (#t #f))
19 ? abort (illegal-arguments
2020
2121 `not` expects its single argument to be a boolean.
2222
2525
2626 '<<SPEC'
2727
28 (define not (fexpr (args env)
29 (bind-args (a) args env
30 (if a #f #t))))
28 (define not (fun (a)
29 (if a #f #t)))