/internal/src/mtscheme/core.clj
Clojure | 76 lines | 28 code | 17 blank | 31 comment | 5 complexity | 119c99b41e3c924b4c3b88d3ebab7aea MD5 | raw file
Possible License(s): GPL-3.0
- (ns mtscheme.core
- (:gen-class)
- (:refer-clojure :exclude [cond cons let]))
- ;; cond
- (defmacro cond [& args]
- (when args
- (clojure.core/let [fst# (ffirst args)]
- (list `if (if (= fst# (symbol "else")) :else fst#)
- (second (first args))
- (clojure.core/cons 'cond (next args))))))
- ;;(clojure.walk/macroexpand-all
- ;;(macroexpand-1
- ;; '(cond ((< x 0) (- 0 x)) ((= x 0) 100) (else x)))
- ;;(macroexpand-1
- ;;(clojure.walk/macroexpand-all
- ;; '(cond ((> 3 2) 'greater)
- ;; ((< 3 2) 'less)))
- (defn cons [fst snd]
- (clojure.core/cons fst (if (coll? snd) snd [snd])))
- ;; append
- (def append concat)
- ;; car / cdr
- (def car first)
- (def cdr rest)
- ;; null?
- (def null? empty?)
- ;;(coll? 1)
- ;; define
- (defmacro define [name-and-params body]
- (if (coll? name-and-params) ; function or var definition?
- `(defn ~(first name-and-params) [~@(rest name-and-params)] ~body)
- `(def ~name-and-params ~body)))
- ;;(defmacro define [& args]
- ;; `(def ~@args))
- ;; (macroexpand '(define lisa 1))
- ;; (macroexpand '(define nisse (+ 1 1 1)))
- ; let
- (defmacro let [& args]
- (clojure.core/let [body# (first (rest args))
- vars# (reduce concat [] (first args))]
- `(clojure.core/let [~@vars#] ~body#)))
- ;; (macroexpand '(let lisa 1)) ; serror
- ;; (macroexpand '(let lisa 1 (+ lisa 1))) ; serror
- ;; (macroexpand '(let lisa (+ 1 1))) ; serror
- ;; (macroexpand '(let (a 1))) ; serror
- ;; (macroexpand '(let ((a 1))))
- ;; (macroexpand '(let ((a 1)) a))
- ;; (macroexpand '(let ((a 1)(b 2))(+ a b)))
- ;; (macroexpand '(let (a 1 b 2)))
- ;; (macroexpand (let ((a (+ 1 1))(b 3)) (+ a b)))
- ;; begin
- (defmacro begin [& args]
- `(do ~@args))
- ;; lambda
- (defmacro lambda [fst snd & _]
- `(fn [~@fst] ~snd))
- ;; (macroexpand-1 '(lambda (x) (+ x v)))
- ;; display
- (def display println)