Skip to content

Commit

Permalink
s/dolistl/dosublists
Browse files Browse the repository at this point in the history
  • Loading branch information
iamFIREcracker committed Dec 12, 2023
1 parent c28bf15 commit a99e52c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/2023/day11.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

(defun sum-all-distances (&optional (image (parse-image)))
(looping
(dolistl ((g1 . rest) (hash-table-keys image))
(dosublists ((g1 . rest) (hash-table-keys image))
(dolist (g2 rest)
(sum! (manhattan-distance g1 g2))))))

Expand Down
2 changes: 1 addition & 1 deletion vendor/make-quickutils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
:digits
:divf
:dolist+
:dolistl
:dorange
:dorangei
:doseq
:dosublists
:enumerate
:flatten
:hash-table-alist
Expand Down
35 changes: 18 additions & 17 deletions vendor/quickutils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
;;;; See http://quickutil.org for details.

;;;; To regenerate:
;;;; (qtlc:save-utils-as "quickutils.lisp" :utilities '(:KEEP-IF :KEEP-IF-NOT :AAND :AIF :AWHEN :BND* :BND1 :COPY-ARRAY :COPY-HASH-TABLE :DIGITS :DIVF :DOLIST+ :DOLISTL :DORANGE :DORANGEI :DOSEQ :ENUMERATE :FLATTEN :HASH-TABLE-ALIST :HASH-TABLE-KEY-EXISTS-P :HASH-TABLE-KEYS :HASH-TABLE-VALUES :IF-LET :IOTA :LOOPING :MAKE-KEYWORD :MKSTR :MULF :NCYCLE :REPEAT :STRING-ENDS-WITH-P :STRING-STARTS-WITH-P :SYMB :VOID :WHEN-LET :WHILE :WITH-GENSYMS) :ensure-package T :package "AOC.QUICKUTILS")
;;;; (qtlc:save-utils-as "quickutils.lisp" :utilities '(:KEEP-IF :KEEP-IF-NOT :AAND :AIF :AWHEN :BND* :BND1 :COPY-ARRAY :COPY-HASH-TABLE :DIGITS :DIVF :DOLIST+ :DORANGE :DORANGEI :DOSEQ :DOSUBLISTS :ENUMERATE :FLATTEN :HASH-TABLE-ALIST :HASH-TABLE-KEY-EXISTS-P :HASH-TABLE-KEYS :HASH-TABLE-VALUES :IF-LET :IOTA :LOOPING :MAKE-KEYWORD :MKSTR :MULF :NCYCLE :REPEAT :STRING-ENDS-WITH-P :STRING-STARTS-WITH-P :SYMB :VOID :WHEN-LET :WHILE :WITH-GENSYMS) :ensure-package T :package "AOC.QUICKUTILS")

(eval-when (:compile-toplevel :load-toplevel :execute)
(unless (find-package "AOC.QUICKUTILS")
Expand All @@ -16,8 +16,8 @@
(setf *utilities* (union *utilities* '(:ABBR :KEEP-IF :KEEP-IF-NOT :LET1 :AIF
:AAND :AWHEN :BND* :BND1 :COPY-ARRAY
:COPY-HASH-TABLE :DIGITS :DIVF
:DOLIST+ :DOLISTL :DORANGE :DORANGEI
:DOSEQ :ENUMERATE :FLATTEN
:DOLIST+ :DORANGE :DORANGEI :DOSEQ
:DOSUBLISTS :ENUMERATE :FLATTEN
:HASH-TABLE-ALIST
:HASH-TABLE-KEY-EXISTS-P :MAPHASH-KEYS
:HASH-TABLE-KEYS :MAPHASH-VALUES
Expand Down Expand Up @@ -239,15 +239,6 @@ the following identity holds:
`(loop :for ,var :in ,list do ,@body ,@(when result? `(:finally (return ,result)))))


(defmacro dolistl ((var list &optional (result nil result?)) &body body)
"Like DOLIST, except:
- `var` is bound to successive sublists of `list` (similar to MAPL)
- `var` can lambda-list (similar to DOLIST+)
"
`(loop :for ,var :on ,list do ,@body ,@(when result? `(:finally (return ,result)))))


(defmacro dorange ((var from to &optional (step 1) (result nil result?)) &body body)
"Binds `var` to all the distinct values in the range [`from`, `to`[, with
`step` step (note: `to` is excluded), and runs `body` inside that
Expand Down Expand Up @@ -286,6 +277,15 @@ each element of the sequence and executing `body`. Return the value
,return))


(defmacro dosublists ((var list &optional (result nil result?)) &body body)
"Like DOLIST, except:
- `var` is bound to successive sublists of `list` (similar to MAPL, LOOP..ON)
- `var` can lambda-list (similar to DOLIST+)
"
`(loop :for ,var :on ,list do ,@body ,@(when result? `(:finally (return ,result)))))


(defgeneric enumerate (x)
(:documentation "Equivalent to `(zip (iota (length x)) x)`."))

Expand Down Expand Up @@ -678,10 +678,11 @@ PROGN."

(eval-when (:compile-toplevel :load-toplevel :execute)
(export '(keep-if keep-if-not aand aif awhen bnd* bnd1 copy-array
copy-hash-table digits divf dolist+ dolistl dorange dorangei doseq
enumerate flatten hash-table-alist hash-table-key-exists-p
hash-table-keys hash-table-values if-let iota looping make-keyword
mkstr mulf ncycle repeat string-ends-with-p string-starts-with-p
symb void when-let when-let* while with-gensyms with-unique-names)))
copy-hash-table digits divf dolist+ dorange dorangei doseq
dosublists enumerate flatten hash-table-alist
hash-table-key-exists-p hash-table-keys hash-table-values if-let
iota looping make-keyword mkstr mulf ncycle repeat
string-ends-with-p string-starts-with-p symb void when-let
when-let* while with-gensyms with-unique-names)))

;;;; END OF quickutils.lisp ;;;;

0 comments on commit a99e52c

Please sign in to comment.