Loop Unrolling Code
The code to accomplish loop unrolling is simple:
(defn unrollb [code ivar n nmax codelst] (if (>= n nmax) (cons 'do (reverse codelst)) (unrollb code ivar (+ n 1) nmax (cons (subst n ivar code) codelst) ))) (defn unroll [loopcode] (unrollb (third loopcode) ; code (get (second loopcode) 0) ; i 0 (get (second loopcode) 1) ; nmax '()))
(unroll '(dotimes [i 3] (println (get arr i))) ) (do (println (get arr 0)) (println (get arr 1)) (println (get arr 2)))