Mercurial > rlm
comparison src/rlm/mike.clj @ 0:78a630e650d2
initial import
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 18 Oct 2011 00:57:08 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:78a630e650d2 |
---|---|
1 (ns rlm.mike) | |
2 | |
3 (defmacro define [name e] | |
4 (if (symbol? name) | |
5 `(def ~name ~e) | |
6 `(define ~(first name) (fn [~@(rest name)] (~@e))))) | |
7 | |
8 (defmacro lambda [a b] | |
9 `(fn [~@a] ~b)) | |
10 | |
11 (defmacro with-quote-everything [form] | |
12 (let [prime (first form) | |
13 rests (rest form) | |
14 rests (map (fn [form] `(quote ~form)) rests) | |
15 ] | |
16 `(~prime ~@rests))) | |
17 | |
18 (defn mike-define [name e] | |
19 (if (symbol? name) | |
20 (intern *ns* name e) | |
21 (mike-define (first name) '(lambda (rest name) e )))) | |
22 | |
23 (defn Y | |
24 "The y-combinator" | |
25 [m] | |
26 ((fn [future] | |
27 (m (fn [arg] | |
28 ((future future) arg)))) | |
29 (fn [future] ;;this reminds me a lot of a quine! | |
30 (m (fn [arg] | |
31 ((future future) arg)))) )) | |
32 | |
33 | |
34 (defn factorial [n] | |
35 (if (zero? n) | |
36 1 | |
37 (* n (factorial (dec n)))) ) | |
38 | |
39 ((Y (fn [rec] | |
40 (fn [n] | |
41 (if (zero? n) | |
42 1 | |
43 (* n (rec (dec n)))) ))) 6) |