Move array functions out of global scope

This commit is contained in:
Mike Cifelli 2018-02-04 09:47:25 -05:00
parent c33d8e5d38
commit 76b1f987a2
1 changed files with 36 additions and 33 deletions

View File

@ -1,40 +1,43 @@
(defmacro array (length) (let ((static))
(let* ((this (gensym))
(index-prefix (fuse this 'index))
(indices (create-indices length))
(index-bindings (map (lambda (i) (list (fuse index-prefix i))) indices)))
`(let ,index-bindings (setq static
(setq ,this (dlambda
(dlambda (:create-indices (length)
(:get (i) (call static :create-indices-tail (- length 1) ()))
(eval (fuse ',index-prefix i)))
(:set (i value) (:create-indices-tail (index accumulator)
(if (and (< i ,length) (> i -1)) (if (< index 0)
(set (fuse ',index-prefix i) value) accumulator
(call ,this :get i))) ;; show error (recur (- index 1) (cons index accumulator))))))
(:length () (defmacro array (length)
,length) (let* ((this (gensym))
(index-prefix (fuse this 'index))
(indices (call static :create-indices length))
(index-bindings (map (lambda (i) (list (fuse index-prefix i))) indices)))
(t () `(let ,index-bindings
((lambda (indices accumulator) (setq ,this
(if (null? indices) (dlambda
accumulator (:get (i)
(recur (eval (fuse ',index-prefix i)))
(rest indices)
(cons
(call ,this :get (first indices))
accumulator))))
(reverse ',indices)
nil)))))))
(:set (i value)
(if (and (< i ,length) (> i -1))
(set (fuse ',index-prefix i) value)
(call ,this :get i))) ;; show error
(defun create-indices (length) (:length ()
(create-indices-tail (- length 1) ())) ,length)
(defun create-indices-tail (index accumulator) (t ()
(if (< index 0) ((lambda (indices accumulator)
accumulator (if (null? indices)
(recur (- index 1) (cons index accumulator)))) accumulator
(recur
(rest indices)
(cons
(call ,this :get (first indices))
accumulator))))
(reverse ',indices)
nil))))))))