Commits

Anonymous committed 1d363a5

nothing to see here

Comments (0)

Files changed (5)

src/examples/arity.clj

-(defmacro dumb [] '(do (println "hello") 42))
-(defmacro repeat3 [f] `(do (~f ~f ~f)))
-
-(defn list2 ([arg1 & args] (do (println arg1) (println args))))
-
-(defn list3
-  ([arg1] (do (println arg1)))
-  ([arg1 arg2] (do (println arg1 arg2)))
-  ([arg1 arg2 & args] (do (println args) (list3 arg1 arg2))))
-
-(defn list4 ([& args] (println args)))
-
-(defn dodumb [] (dumb))
-
-

src/examples/atomclosure.clj

-(defn make_clojure []
-  (let
-      [x (atom 1)
-       f (fn [y] (swap! x + y))]
-    f))
-
-(defn make_clojure []
-  (letcc
-      [x (atom 1)
-       f (fn [y] (swap! x + y))]
-    f))
-
-((fn [] (do
-         (println "evaled")
-         1)))
-
-(defmacro make_clojured []

src/examples/closure.clj

-(def super_closure1
-  (fn [x] (
-           fn [y] (
-                   fn [] (+ x y)))))
-
-> super_closure1
-
-(((super_closure1 23) 19))
-
-> 42
-
-(((super_closure1 1) 3))
-
-> 4
-
-; super_closure2 - still simple, no shadowing
-(def super_closure2
-  (fn [x] (
-           fn [y] (
-                   fn [z] (* z (+ x y))))))
-> super_closure2
-
-; x = 3 y = 5
-(def secondx ((super_closure2 3) 5))
-> second
-
-(secondx 10)
-> 80
-
-; super_closure3 - simple, shadows x symbol later
-
-(def super_closure3
-  (fn [x] (
-           fn [y] (
-                   fn [x] (+ x y)))))
-> super_closure3
-
-; x = 100 y = 5
-(((super_closure3 100) 21) 21)
-> 42
-
-; super_closure4 - simple, shadows x differently
-(def super_closure4
-  (fn [x] (
-           fn [x] (
-                   fn [] (+ x x)))))
->super_closure4
-
-(((super_closure4 10) 32))
-> 64

src/examples/macro.xlx

-(defmacrox double_add (form) (list '+ form form))
-> double_add
-
-(double_add (+ 1 1))
-> 4
-
-(define f 42.0)
-> f
-
-(double_add (- (+ f 1) (+ f -1)))
-> 4
-
-(define = (lambda (x y) (.equal x y)))
-
-(defmacrox if (pred dothis elsethis) (list 'cond (list pred dothis) (list ':else elsethis)))
-
-;(defmacro if [pred dothis elsethis] (list 'cond (list pred dothis) (list ':else elsethis)))
-(defmacro ifx [pred dothis elsethis] `(cond (~pred ~dothis) (:else ~elsethis)))
-

src/examples/scratch.xlx

-
-(defmacro f [z] (list 'do '(prn 1 2 3 z) z))
-
-(define f (z) (do (prn '(1 2 3 z)) 42))
-
-(defn f [z] (prn '(1 2 3 z)) 42)
-(f 23)
-
-(defmacrox f (z) (list 'do '(prn 1 2 3 z) z))
-(macroexpand f)
-
-(defn lat? [l]
-  (cond (empty? l) true
-        ((atom? (first l)) (recur (rest l)))
-        :else false))
-
-(define lat?
-  (lambda (l)
-          (cond
-           ((null? l) true)
-           ((atom? (car l)) (lat? (cdr l)))
-           (:else false))))