| 1 |
;; this is miku primitive operators. |
| 2 |
;; don't change this file. |
| 3 |
;; normally, you should make another library files. |
| 4 |
|
| 5 |
(require_runtime_library "enumerator") |
| 6 |
|
| 7 |
(def 'defmacro |
| 8 |
(macro (name alist (rest body)) |
| 9 |
`(def ,(list 'quote name) (macro ,alist ,@body)))) |
| 10 |
|
| 11 |
;; (defmacro setq (var val) |
| 12 |
;; `(set ,(list 'quote var) ,val)) |
| 13 |
(defmacro setq ((rest args)) |
| 14 |
(set 'result '(set)) |
| 15 |
(each_slice args 2 #((pair) |
| 16 |
(append result (list (list 'quote (car pair)) (nth pair 1))))) |
| 17 |
result) |
| 18 |
|
| 19 |
(defmacro defun (name alist (rest body)) |
| 20 |
`(def ,(list 'quote name) #(,alist ,@body))) |
| 21 |
|
| 22 |
(defun to_hash (ary) |
| 23 |
(setq result (new Hash)) |
| 24 |
(each ary #((pair) (store result (car pair) (cdr pair)))) |
| 25 |
result) |
| 26 |
|
| 27 |
(defmacro and (body (rest other)) |
| 28 |
(if (empty? other) |
| 29 |
body |
| 30 |
`(if ,body (and ,@other)))) |
| 31 |
|
| 32 |
(defmacro or (body (rest other)) |
| 33 |
`(if ,body |
| 34 |
true |
| 35 |
,(if other |
| 36 |
`(or ,@other)))) |
| 37 |
|
| 38 |
(defmacro let (bind (rest body)) |
| 39 |
(#((mapped) |
| 40 |
`(#(,(map mapped #((node) (car node))) |
| 41 |
,@body) ,@(map mapped #((node) (cdr node))))) |
| 42 |
(map bind #((node) |
| 43 |
(if (listp node) |
| 44 |
(cons (car node) (nth node 1)) |
| 45 |
(cons node nil)))))) |
| 46 |
|
| 47 |
(defmacro let* (bind (rest body)) |
| 48 |
(if (cdr bind) |
| 49 |
`(let (,(car bind)) |
| 50 |
(let* ,(cdr bind) ,@body)) |
| 51 |
`(let (,(car bind)) |
| 52 |
,@body))) |
| 53 |
|
| 54 |
(defmacro progn ((rest body)) |
| 55 |
`(#(() ,@body))) |
| 56 |
|
| 57 |
(defmacro cond (condition (rest follow)) |
| 58 |
`(if ,(car condition) (progn ,@(cdr condition)) ,(if (not (empty? follow)) (cons 'cond follow)))) |