Plaster
New
List
Login
common-lisp
default
anonymous
2022.11.12 12:42:06
(defun dim-code (arr dim-num n) "Create the code for a nested list from array contents. ARR = array, DIM-NUM = the selected dimension to bring from the array, and N is the selected index of DIM-NUM. In the case of a 2-Dimensional array (a matrix), DIM-NUM = 0 implies a row, and DIM-NUM = 1 implies a column." (labels ((nested-loop (syms dims code) "Generate nested list code." (if (car syms) (nested-loop (cdr syms) (cdr dims) `(loop :for ,(car syms) :below ,(car dims) :collect ,code)) code)) (remove-nth (seq n) (remove-if (constantly t) seq :start n :count 1))) (let* ((adims (array-dimensions arr)) (asyms (loop :for i :below (length adims) :collect (gensym)))) (nested-loop (remove-nth asyms dim-num) (remove-nth adims dim-num) `(aref ,arr ,@(substitute-if n (constantly t) asyms :start dim-num :count 1))))))
Raw
Annotate
Repaste
Edit