From 76b1f987a23e5dc1c861cde5864948ad6776d9c8 Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Sun, 4 Feb 2018 09:47:25 -0500 Subject: [PATCH] Move array functions out of global scope --- lisp/random/array.lisp | 69 ++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/lisp/random/array.lisp b/lisp/random/array.lisp index 4c73904..92f23a8 100644 --- a/lisp/random/array.lisp +++ b/lisp/random/array.lisp @@ -1,40 +1,43 @@ -(defmacro array (length) - (let* ((this (gensym)) - (index-prefix (fuse this 'index)) - (indices (create-indices length)) - (index-bindings (map (lambda (i) (list (fuse index-prefix i))) indices))) +(let ((static)) - `(let ,index-bindings - (setq ,this - (dlambda - (:get (i) - (eval (fuse ',index-prefix i))) + (setq static + (dlambda + (:create-indices (length) + (call static :create-indices-tail (- length 1) ())) - (:set (i value) - (if (and (< i ,length) (> i -1)) - (set (fuse ',index-prefix i) value) - (call ,this :get i))) ;; show error + (:create-indices-tail (index accumulator) + (if (< index 0) + accumulator + (recur (- index 1) (cons index accumulator)))))) - (:length () - ,length) + (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))) - (t () - ((lambda (indices accumulator) - (if (null? indices) - accumulator - (recur - (rest indices) - (cons - (call ,this :get (first indices)) - accumulator)))) - (reverse ',indices) - nil))))))) + `(let ,index-bindings + (setq ,this + (dlambda + (:get (i) + (eval (fuse ',index-prefix i))) + (: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) - (create-indices-tail (- length 1) ())) + (:length () + ,length) -(defun create-indices-tail (index accumulator) - (if (< index 0) - accumulator - (recur (- index 1) (cons index accumulator)))) + (t () + ((lambda (indices accumulator) + (if (null? indices) + accumulator + (recur + (rest indices) + (cons + (call ,this :get (first indices)) + accumulator)))) + (reverse ',indices) + nil))))))))