summaryrefslogtreecommitdiff
path: root/tests/stdlib.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/stdlib.lisp')
-rw-r--r--tests/stdlib.lisp29
1 files changed, 21 insertions, 8 deletions
diff --git a/tests/stdlib.lisp b/tests/stdlib.lisp
index 380fa2a..96a55bb 100644
--- a/tests/stdlib.lisp
+++ b/tests/stdlib.lisp
@@ -2,6 +2,10 @@
(define caddr (x) (car (cdr (cdr x))))
(define cadddr (x) (car (cdr (cdr (cdr x)))))
+(define not (x) (if x 0 1))
+(define or (x y) (if x 1 (if y 1 0)))
+(define and (x y) (if x (if y 1 0) 0))
+
(define YY (recur) (lambda (f) (lambda (a) (f ((recur recur) f) a))))
(define Y (YY YY))
@@ -10,6 +14,10 @@
(do (f start) (for (+ start 1) end f))
'()))
+(define stdin (sys-stdin))
+(define stdout (sys-stdout))
+(define stderr (sys-stderr))
+
(define with-open-file (path mode f)
(let ((fid (sys-open-file mode path)))
(let ((value (f fid)))
@@ -17,12 +25,17 @@
(sys-close-file fid)
value))))
+(define read-until (fid predicate)
+ (let ((helper (lambdarec rec (s)
+ (let ((ch (sys-get-char fid)))
+ (if (predicate ch) s (rec (concat s ch)))))))
+ (helper "")))
+
+(define read-until-eof (fid)
+ (read-until fid null?))
+
(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 ""))
- )))
+ (with-open-file path 0 read-until-eof))
+
+(define read-line (fid)
+ (read-until fid (lambda (ch) (or (= ch "\n") (null? ch)))))