2018-02-04 09:47:25 -05:00
|
|
|
(let ((static))
|
2018-01-28 09:55:23 -05:00
|
|
|
|
2018-02-04 09:47:25 -05:00
|
|
|
(setq static
|
|
|
|
(dlambda
|
|
|
|
(:create-indices (length)
|
|
|
|
(call static :create-indices-tail (- length 1) ()))
|
2018-01-28 09:55:23 -05:00
|
|
|
|
2018-02-04 09:47:25 -05:00
|
|
|
(:create-indices-tail (index accumulator)
|
|
|
|
(if (< index 0)
|
|
|
|
accumulator
|
|
|
|
(recur (- index 1) (cons index accumulator))))))
|
2018-01-28 09:55:23 -05:00
|
|
|
|
2018-02-04 09:47:25 -05:00
|
|
|
(defmacro array (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)))
|
2018-01-28 09:55:23 -05:00
|
|
|
|
2018-02-04 09:47:25 -05:00
|
|
|
`(let ,index-bindings
|
|
|
|
(setq ,this
|
|
|
|
(dlambda
|
|
|
|
(:get (i)
|
|
|
|
(eval (fuse ',index-prefix i)))
|
2018-01-28 09:55:23 -05:00
|
|
|
|
2018-02-04 09:47:25 -05:00
|
|
|
(:set (i value)
|
|
|
|
(if (and (< i ,length) (> i -1))
|
|
|
|
(set (fuse ',index-prefix i) value)
|
|
|
|
(call ,this :get i))) ;; show error
|
2018-01-28 09:55:23 -05:00
|
|
|
|
2018-02-04 09:47:25 -05:00
|
|
|
(:length ()
|
|
|
|
,length)
|
2018-01-27 20:02:03 -05:00
|
|
|
|
2018-02-04 09:47:25 -05:00
|
|
|
(t ()
|
|
|
|
((lambda (indices accumulator)
|
|
|
|
(if (null? indices)
|
|
|
|
accumulator
|
|
|
|
(recur
|
|
|
|
(rest indices)
|
|
|
|
(cons
|
|
|
|
(call ,this :get (first indices))
|
|
|
|
accumulator))))
|
|
|
|
(reverse ',indices)
|
|
|
|
nil))))))))
|