Packages
kirala_l4u
0.1.1
An embedded lisp interpreter based on the gleam implementation of MAL lisp.
Current section
Files
Jump to
Current section
Files
src/l4u@resources.erl
-module(l4u@resources).
-compile(export_all).
load(<<"default0.lisp">>) -> <<"(def! read-file\n (fn* (filename)\n (eval (load-file filename))\n))\n\n(def! defmac (macro* (name args & body)\n `(def! ~name (macro* ~args ~@body))))\n\n(def! defun (macro* (name args & body)\n `(def! ~name (fn* ~args ~@body))))\n\n\n(def! defn defun)\n(def! def def!)\n(def! let let*)\n(def! fn fn*)\n(def! first car)\n(def! rest cdr)\n(def! head car)\n(def! tail cdr)\n\n(def! swap! (fn* [a f & xs] (reset! a (apply f (deref a) xs))))\n\n\n\n\n\n(defmacro! rename!\n (fn* [name_from name_to]\n `(do\n (bindf old_value (erase! ~name_from))\n (def! ~name_to old_value))))\n\n(def! run-time (fn* [f]\n (let* [start (time-ms)\n result (f)\n end (time-ms)]\n (list (/ (- end start) 1000.0) result))))\n\n\n(def! reduce (fn* (f init xs)\n (if (empty? xs) init (reduce f (f init (first xs)) (rest xs)))))\n(def! foldr (fn* [f init xs]\n (if (empty? xs) init (f (first xs) (foldr f init (rest xs))))))\n\n(def! nth\n (fn* [xs index]\n (if (if (<= 0 index) (not (empty? xs))) \n (if (= 0 index)\n (first xs)\n (nth (rest xs) (- index 1)))\n (throw \"nth: index out of range\"))))\n\n\n\n\n\n\n\n(def! concat\n (fn* [& xs]\n (foldr (fn* [x acc] (foldr cons acc x)) () xs)))\n(def! conj\n (fn* [xs & ys]\n (if (vector? xs)\n (vec (concat xs ys))\n (reduce (fn* [acc x] (cons x acc)) xs ys))))\n\n\n\n(def! sum (fn* [xs] (reduce + 0 xs)))\n(def! product (fn* [xs] (reduce * 1 xs)))\n\n(def! conjunction\n (let* [and2 (fn* [acc x] (if acc x false))]\n (fn* [xs]\n (reduce and2 true xs))))\n(def! disjunction\n (let* [or2 (fn* [acc x] (if acc true x))]\n (fn* [xs]\n (reduce or2 false xs))))\n\n(def! sum_len\n (let* [add_len (fn* [acc x] (+ acc (count x)))]\n (fn* [xs]\n (reduce add_len 0 xs))))\n(def! max_len\n (let* [update_max (fn* [acc x] (let* [l (count x)] (if (< acc l) l acc)))]\n (fn* [xs]\n (reduce update_max 0 xs))))\n\n\n\n\n\n\n\n\n(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))\n\n\n"/utf8>>;
load(<<"default1.lisp">>) -> <<"(defn reverse [xs]\n (let* [\n rev (fn* [xs acc]\n (if (empty? xs)\n acc\n (rev (rest xs) (cons (first xs) acc))))\n ]\n (rev xs ())))\n\n(defn map [f xs]\n (let* [\n map-rec (fn* [xs acc]\n (if (empty? xs)\n (reverse acc)\n (map-rec (rest xs) (cons (f (first xs)) acc))))\n ]\n (map-rec xs ())))\n\n(defn for-each [f xs]\n (let* [\n map-rec (fn* [xs]\n (if (empty? xs)\n (map-rec (rest xs) )))\n ]\n (map-rec xs)))\n\n(defn range [start end]\n :description\n \"\"\"\n Returns a list of integers from start (inclusive) to end (exclusive). \n \"\"\"\n (let* [\n range-rec (fn* [start end acc]\n (if (= start end)\n acc\n (range-rec (+ start 1) end (cons start acc))))\n ]\n (reverse (range-rec start end ()))\n ))\n\n\n\n(defn caar [x] (car (car x)))\n(defn cadr [x] (car (cdr x)))\n(defn cadar [x] (car (cdr (car x))))\n(defn caddr [x] (car (cdr (cdr x))))\n(defn caddar [x] (car (cdr (cdr (car x)))))\n(defn cddr [x] (cdr (cdr x)))\n(defn cdddr [x] (cdr (cdr (cdr x))))\n\n(def! case case*)\n\n\n\n"/utf8>>;
load(_) -> undefined.