2022-09-03 13:27:52 +00:00
|
|
|
(defn eq? (x y)
|
|
|
|
(eq x y))
|
2021-12-12 10:43:57 +00:00
|
|
|
|
|
|
|
(defn atom? (x)
|
|
|
|
(atom x))
|
|
|
|
|
|
|
|
(defn string? (x)
|
|
|
|
(eq? (type x) "string"))
|
|
|
|
|
|
|
|
(defn boolean? (x)
|
|
|
|
(eq? (type x) "boolean"))
|
|
|
|
|
|
|
|
(defn symbol? (x)
|
|
|
|
(eq? (type x) "symbol"))
|
|
|
|
|
|
|
|
(defn number? (x)
|
|
|
|
(eq? (type x) "number"))
|
|
|
|
|
|
|
|
(defn list? (x)
|
|
|
|
(eq? (type x) "list"))
|
|
|
|
|
|
|
|
(defn function? (x)
|
|
|
|
(eq? (type x) "function"))
|
|
|
|
|
|
|
|
(defn lambda? (x)
|
|
|
|
(eq? (type x) "lambda"))
|
|
|
|
|
|
|
|
(def null '())
|
|
|
|
|
|
|
|
(defn null? (x)
|
|
|
|
(eq? x null))
|
|
|
|
|
2022-09-03 13:27:52 +00:00
|
|
|
(defn and (x y)
|
|
|
|
(cond
|
|
|
|
(x (cond (y true) (true false)))
|
|
|
|
(true false)))
|
|
|
|
|
2022-08-25 06:48:19 +00:00
|
|
|
(defn not (x)
|
2022-09-03 13:27:52 +00:00
|
|
|
(cond (x false) (true true)))
|
|
|
|
|
|
|
|
(defn or (x y)
|
|
|
|
(cond (x true) (y true) (true false)))
|
2022-08-25 06:48:19 +00:00
|
|
|
|
2022-09-03 13:27:52 +00:00
|
|
|
(defn rest (x)
|
|
|
|
(cdr x))
|
2021-12-12 10:43:57 +00:00
|
|
|
|
2022-09-03 13:27:52 +00:00
|
|
|
(defn first (x)
|
|
|
|
(car x))
|
2021-12-12 10:43:57 +00:00
|
|
|
|
2022-09-03 13:27:52 +00:00
|
|
|
(defn second (x)
|
|
|
|
(first (rest x)))
|
2021-12-12 10:43:57 +00:00
|
|
|
|
2022-09-03 13:27:52 +00:00
|
|
|
(defn third (x)
|
|
|
|
(second (rest x)))
|
2022-07-02 13:24:30 +00:00
|
|
|
|
2022-09-03 13:27:52 +00:00
|
|
|
(defn append (x y)
|
2022-07-02 13:24:30 +00:00
|
|
|
(cond
|
2022-09-03 13:27:52 +00:00
|
|
|
((null? x) y)
|
|
|
|
(true (cons (first x) (append (rest x) y)))))
|
2022-07-02 13:24:30 +00:00
|
|
|
|
2022-09-03 13:27:52 +00:00
|
|
|
(defn reverse (x)
|
2022-07-02 13:24:30 +00:00
|
|
|
(cond
|
2022-09-03 13:27:52 +00:00
|
|
|
((null? x) x)
|
|
|
|
(true (append (reverse (rest x)) (cons (first x) '())))))
|
|
|
|
|
|
|
|
(defn range (i n)
|
|
|
|
(cond
|
|
|
|
((= i n) null)
|
|
|
|
(true (append (list i) (range (+ i 1) n)))))
|
2022-07-02 13:24:30 +00:00
|
|
|
|
|
|
|
(defn read-line ()
|
2022-08-25 06:48:19 +00:00
|
|
|
(decode-string (reverse (rest (reverse (read-file-bytes "/dev/console" 256))))))
|
|
|
|
|
|
|
|
(defn read-char ()
|
|
|
|
(decode-string (read-file-bytes "/dev/console" 4)))
|
|
|
|
|
|
|
|
(defn print (exp)
|
|
|
|
(do (append-file-bytes "/dev/console" (encode-string (string exp))) '()))
|
2022-06-06 14:02:34 +00:00
|
|
|
|
|
|
|
(defn println (exp)
|
|
|
|
(do (print exp) (print "\n")))
|
2022-08-25 06:48:19 +00:00
|
|
|
|
2022-09-03 13:27:52 +00:00
|
|
|
(def pr print)
|
|
|
|
(def prn println)
|
|
|
|
|
2022-08-25 06:48:19 +00:00
|
|
|
(defn uptime ()
|
|
|
|
(decode-number (read-file-bytes "/dev/clk/uptime" 8)))
|
|
|
|
|
|
|
|
(defn realtime ()
|
|
|
|
(decode-number (read-file-bytes "realtime" 8)))
|
|
|
|
|
|
|
|
(defn write-file (path str)
|
|
|
|
(write-file-bytes path (encode-string str)))
|
|
|
|
|
|
|
|
(defn append-file (path str)
|
|
|
|
(append-file-bytes path (encode-string str)))
|
|
|
|
|
|
|
|
(defn regex-match? (pattern str)
|
|
|
|
(not (null? (regex-find pattern str))))
|