2022-09-20 17:57:55 +00:00
|
|
|
(define (eq? x y)
|
2022-09-03 13:27:52 +00:00
|
|
|
(eq x y))
|
2021-12-12 10:43:57 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (atom? x)
|
2021-12-12 10:43:57 +00:00
|
|
|
(atom x))
|
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (string? x)
|
2021-12-12 10:43:57 +00:00
|
|
|
(eq? (type x) "string"))
|
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (boolean? x)
|
2021-12-12 10:43:57 +00:00
|
|
|
(eq? (type x) "boolean"))
|
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (symbol? x)
|
2021-12-12 10:43:57 +00:00
|
|
|
(eq? (type x) "symbol"))
|
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (number? x)
|
2021-12-12 10:43:57 +00:00
|
|
|
(eq? (type x) "number"))
|
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (list? x)
|
2021-12-12 10:43:57 +00:00
|
|
|
(eq? (type x) "list"))
|
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (function? x)
|
2021-12-12 10:43:57 +00:00
|
|
|
(eq? (type x) "function"))
|
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define nil '())
|
2021-12-12 10:43:57 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (nil? x)
|
|
|
|
(eq? x nil))
|
2021-12-12 10:43:57 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (and x y)
|
2022-09-03 13:27:52 +00:00
|
|
|
(cond
|
|
|
|
(x (cond (y true) (true false)))
|
|
|
|
(true false)))
|
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (not x)
|
2022-09-03 13:27:52 +00:00
|
|
|
(cond (x false) (true true)))
|
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (or x y)
|
2022-09-03 13:27:52 +00:00
|
|
|
(cond (x true) (y true) (true false)))
|
2022-08-25 06:48:19 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (rest x)
|
2022-09-03 13:27:52 +00:00
|
|
|
(cdr x))
|
2021-12-12 10:43:57 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (first x)
|
2022-09-03 13:27:52 +00:00
|
|
|
(car x))
|
2021-12-12 10:43:57 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (second x)
|
2022-09-03 13:27:52 +00:00
|
|
|
(first (rest x)))
|
2021-12-12 10:43:57 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (third x)
|
2022-09-03 13:27:52 +00:00
|
|
|
(second (rest x)))
|
2022-07-02 13:24:30 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (reduce f ls)
|
2022-09-15 18:50:23 +00:00
|
|
|
(cond
|
2022-09-20 17:57:55 +00:00
|
|
|
((nil? (rest ls)) (first ls))
|
2022-09-15 18:50:23 +00:00
|
|
|
(true (f (first ls) (reduce f (rest ls))))))
|
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (string-join ls s)
|
2022-09-15 18:50:23 +00:00
|
|
|
(reduce (fn (x y) (string x s y)) ls))
|
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (map f ls)
|
2022-09-15 18:50:23 +00:00
|
|
|
(cond
|
2022-09-20 17:57:55 +00:00
|
|
|
((nil? ls) nil)
|
2022-09-15 18:50:23 +00:00
|
|
|
(true (cons
|
|
|
|
(f (first ls))
|
|
|
|
(map f (rest ls))))))
|
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (append x y)
|
2022-07-02 13:24:30 +00:00
|
|
|
(cond
|
2022-09-20 17:57:55 +00:00
|
|
|
((nil? x) y)
|
2022-09-03 13:27:52 +00:00
|
|
|
(true (cons (first x) (append (rest x) y)))))
|
2022-07-02 13:24:30 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (reverse x)
|
2022-07-02 13:24:30 +00:00
|
|
|
(cond
|
2022-09-20 17:57:55 +00:00
|
|
|
((nil? x) x)
|
2022-09-03 13:27:52 +00:00
|
|
|
(true (append (reverse (rest x)) (cons (first x) '())))))
|
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (range i n)
|
2022-09-03 13:27:52 +00:00
|
|
|
(cond
|
2022-09-20 17:57:55 +00:00
|
|
|
((= i n) nil)
|
2022-09-03 13:27:52 +00:00
|
|
|
(true (append (list i) (range (+ i 1) n)))))
|
2022-07-02 13:24:30 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (read-line)
|
|
|
|
(bytes->string (reverse (rest (reverse (read-file-bytes "/dev/console" 256))))))
|
2022-08-25 06:48:19 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (read-char)
|
|
|
|
(bytes->string (read-file-bytes "/dev/console" 4)))
|
2022-06-06 14:02:34 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (print exp)
|
|
|
|
(do
|
|
|
|
(append-file-bytes "/dev/console" (string->bytes (string exp)))
|
|
|
|
'()))
|
2022-08-25 06:48:19 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (println exp)
|
|
|
|
(do
|
|
|
|
(print exp)
|
|
|
|
(print "\n")))
|
2022-09-03 13:27:52 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (uptime)
|
2022-10-17 18:58:08 +00:00
|
|
|
(bytes->number (read-file-bytes "/dev/clk/uptime" 8) "float"))
|
2022-08-25 06:48:19 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (realtime)
|
2022-10-17 18:58:08 +00:00
|
|
|
(bytes->number (read-file-bytes "realtime" 8) "float"))
|
2022-08-25 06:48:19 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (write-file path str)
|
|
|
|
(write-file-bytes path (string->bytes str)))
|
2022-08-25 06:48:19 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (append-file path str)
|
|
|
|
(append-file-bytes path (string->bytes str)))
|
2022-08-25 06:48:19 +00:00
|
|
|
|
2022-09-20 17:57:55 +00:00
|
|
|
(define (regex-match? pattern str)
|
|
|
|
(not (nil? (regex-find pattern str))))
|