spreadsheet tinkering

This commit is contained in:
mehbark 2025-01-02 19:51:47 -05:00
parent 6cd8d7a339
commit 7434b620f5
2 changed files with 28 additions and 11 deletions

View file

@ -12,14 +12,25 @@
(= width (length (car rows))) (= width (length (car rows)))
(assert (apply #'= (mapcar #'length rows))) (assert (apply #'= (mapcar #'length rows)))
(= cells-name (gensym "CELLS")) (= cells-name (gensym "CELLS"))
(= cells `(list ,@(mapcar ))) (= current-index (gensym "CURRENT-INDEX"))
(= cells `(make-array (list width (length rows)) (= cells
`(list
,@(loop for row in rows
for y from 0
collecting
`(list
,@(loop for cell in row
for x from 0
collecting `(lambda () (let1 ,current-index '(,x ,y) ,cell)))))))
(= cells
`(progn
(defvar ,current-index nil)
(labels ((,cells-name ()
(make-array '(,(length rows) ,width)
:element-type 'function :element-type 'function
:initial-contents :initial-contents ,cells))
(macrolet ((cell (&rest subscripts) `(aref ,cells-name ,@subscripts))) (cell (x y)
,cells))) (assert (not (equal (list x y) ,current-index)))
)) (funcall (aref (,cells-name) y x))))
(,cells-name))))
(sheet cells))
(1 2 3 4 5)
(6 7 8 9 10))

View file

@ -686,6 +686,12 @@
`(loop for ,(first (car binds)) in ,(second (car binds)) `(loop for ,(first (car binds)) in ,(second (car binds))
do (doprod ,(cdr binds) ,@body)))) do (doprod ,(cdr binds) ,@body))))
(defmacro mapprod ((&rest binds) &body body)
(if (null binds)
`(progn ,@body)
`(loop for ,(first (car binds)) in ,(second (car binds))
collect (mapprod ,(cdr binds) ,@body))))
(defpattern structure (expr) (defpattern structure (expr)
(match expr (match expr
((list 'quote x) `',x) ((list 'quote x) `',x)