summaryrefslogtreecommitdiff
path: root/tests/stdlib.lisp
blob: 380fa2acb1b040e8766cf7a9ad22baa2ecaf0a3d (plain)
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
(define cadr (x) (car (cdr x)))
(define caddr (x) (car (cdr (cdr x))))
(define cadddr (x) (car (cdr (cdr (cdr x)))))

(define YY (recur) (lambda (f) (lambda (a) (f ((recur recur) f) a))))
(define Y (YY YY))

(define for (start end f)
    (if (<= start end)
        (do (f start) (for (+ start 1) end f))
        '()))

(define with-open-file (path mode f)
    (let ((fid (sys-open-file mode path)))
        (let ((value (f fid)))
            (do
                (sys-close-file fid)
                value))))

(define read-file (path)
    (with-open-file path 0 (lambda (fid)
        ; (print (sys-get-char fid))
        ; (print (let ((x (lambda (arg) fid))) (x 42)))
        (let ((helper (Y (lambda (recur s)
                           (let ((ch (sys-get-char fid)))
                             (if (null? ch) s (recur (+ s ch))))))))
            (helper ""))
        )))