transcendental-lisp/lisp/random/array.lisp

42 lines
1.1 KiB
Common Lisp
Raw Permalink Normal View History

(let ((static))
2018-01-28 09:55:23 -05:00
(setq static
(dlambda
(:create-indices (length)
(call static :create-indices-tail (- length 1) ()))
2018-01-28 09:55:23 -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
(defun array (length)
(let* ((this)
(indices (call static :create-indices length))
(index-bindings (map (λ (i) (list (fuse 'index i))) indices)))
(eval
`(let ,index-bindings
(setq this
(dlambda
(:get (i)
(eval (fuse 'index i)))
(:set (i value)
(if (and (< i ,length) (> i -1))
(set (fuse 'index i) value)
(call this :get i))) ;; show error
(:length ()
,length)
(t ()
((λ (size accumulator)
(if (< size 1)
accumulator
(recur
(- size 1)
(cons (call this :get (- size 1)) accumulator))))
,length nil)))))))))