Skip to content

Commit 8d400dd

Browse files
Sync utils and fix compilation
1 parent d046237 commit 8d400dd

File tree

10 files changed

+32
-20
lines changed

10 files changed

+32
-20
lines changed

src/2024/day05.lisp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
(defun parse-input (&optional (strings (uiop:read-file-lines #P"src/2024/day05.txt")))
55
(destructuring-bind (rules updates) (split-sequence:split-sequence "" strings :test 'equal)
6-
(list (prog1-let (before-than (make-hash-table))
6+
(list (prog1-let before-than (make-hash-table)
77
(doseq ((a b) (mapcar #'extract-positive-integers rules))
88
(push b (gethash a before-than))))
99
(mapcar #'extract-positive-integers updates))))

src/2024/day10.lisp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
(defun parse-input (&optional (strings (uiop:read-file-lines #P"src/2024/day10.txt")))
6-
(prog1-let (map (make-hash-table :test 'equal))
6+
(prog1-let map (make-hash-table :test 'equal)
77
(doseq ((i s) (enumerate strings))
88
(doseq ((j ch) (enumerate s))
99
(setf (gethash (list i j) map) (- (char-code ch) (char-code #\0)))))))

src/2024/day11.lisp

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
(let1 curr (make-counter stones)
2121
(repeat times
2222
(setf curr
23-
(prog1-let (next (make-counter nil))
23+
(prog1-let next (make-counter nil)
2424
(dohash (stone n curr)
2525
(dolist (stone1 (change stone))
2626
(incf (gethash stone1 next 0) n))))))

src/2024/day12.lisp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(in-package :aoc/2024/12)
33

44
(defun parse-input (&optional (strings (uiop:read-file-lines #P"src/2024/day12.txt")))
5-
(prog1-let (map (make-hash-table :test 'equal))
5+
(prog1-let map (make-hash-table :test 'equal)
66
(doseq ((i s) (enumerate strings))
77
(doseq ((j ch) (enumerate s))
88
(setf (gethash (list i j) map) ch)))))
@@ -38,7 +38,7 @@
3838
;; facing the same direction, and if there is, we subtract one from the total
3939
;; sides count.
4040
(defun sides (r &aux (fence (fence r)))
41-
(prog1-let (total (length fence))
41+
(prog1-let total (length fence)
4242
(flet ((adjacent? (p1 p2)
4343
(= (+ (abs (- (car p1) (car p2)))
4444
(abs (- (cadr p1) (cadr p2))))

src/2024/day14.lisp

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
(defparameter *height* 103)
66

77
(defun parse-input (&optional (strings (uiop:read-file-lines #P"src/2024/day14.txt")))
8-
(prog1-let (grid (make-hash-table :test 'equal))
8+
(prog1-let grid (make-hash-table :test 'equal)
99
(dolist (s strings)
1010
(destructuring-bind (x y vx vy) (extract-integers s)
1111
(push (list vx vy) (gethash (list x y) grid))))))
1212
#+#:excluded (parse-input)
1313

1414

1515
(defun tick (curr)
16-
(prog1-let (next (make-hash-table :test 'equal))
16+
(prog1-let next (make-hash-table :test 'equal)
1717
(dohash ((x y) robots curr)
1818
(doseq ((vx vy) robots)
1919
(let ((x1 (mod (+ x vx) *width*))

src/2024/day22.lisp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#+#:excluded (prices 123)
2626

2727
(defun winning-by-sequence (prices)
28-
(prog1-let (map (make-hash-table :test 'equal))
28+
(prog1-let map (make-hash-table :test 'equal)
2929
(dosublists ((p1 p2 p3 p4 p5) prices)
3030
(when (and p1 p2 p3 p4 p5)
3131
(let1 sequence (list (- p2 p1) (- p3 p2) (- p4 p3) (- p5 p4))

src/2024/day23.lisp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(in-package :aoc/2024/23)
33

44
(defun parse-input (&optional (strings (uiop:read-file-lines #P"src/2024/day23.txt")))
5-
(prog1-let (edges (make-hash-table :test 'equal))
5+
(prog1-let edges (make-hash-table :test 'equal)
66
(doseq (s strings)
77
(destructuring-bind (from to) (split-sequence:split-sequence #\- s)
88
(pushnew to (gethash from edges))

src/2024/day24.lisp

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
(defpackage :aoc/2024/24 #.cl-user::*aoc-use*)
22
(in-package :aoc/2024/24)
33

4-
(declaim (optimize (debug 3)))
5-
4+
#;
65
(defun parse-input (&optional (strings (uiop:read-file-lines #P"src/2024/day24.txt")))
76
(destructuring-bind (connections initial-wires)
87
(split-sequence:split-sequence "" strings :test 'equal)
98
(list
109
;; values
11-
(prog1-let (map (make-hash-table :test 'equal))
10+
(prog1-let1 map (make-hash-table :test 'equal)
1211
(dolist (s connections)
1312
(setf (gethash (subseq s 0 3) map)
1413
(parse-integer (subseq s 5)))))
1514
;; inputs
16-
(prog1-let (map (make-hash-table :test 'equal))
15+
(prog1-let map (make-hash-table :test 'equal)
1716
(dolist (s initial-wires)
1817
(destructuring-bind (in1 gate in2 _ output)
1918
(split-sequence:split-sequence #\Space s)
2019
(declare (ignore _))
2120
(setf (gethash in1 map) (list in1 gate in2 output)
2221
(gethash in2 map) (list in1 gate in2 output) ))))
2322
;; outputs
24-
(prog1-let (map (make-hash-table :test 'equal))
23+
(prog1-let map (make-hash-table :test 'equal)
2524
(dolist (s initial-wires)
2625
(destructuring-bind (in1 gate in2 _ output)
2726
(split-sequence:split-sequence #\Space s)
@@ -140,7 +139,7 @@
140139
(same-expansion? rand12 rand21)))))))))
141140

142141
(defun swap (outputs gate1 gate2 gate3 gate4 gate5 gate6 gate7 gate8)
143-
(prog1-let (copy (copy-hash-table outputs))
142+
(prog1-let1 copy (copy-hash-table outputs)
144143
(rotatef (gethash gate1 copy)
145144
(gethash gate2 copy))
146145
(rotatef (gethash gate3 copy)

src/utils.lisp

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
(defun make-counter (x &key (test 'eql))
113113
"Returns a HASH-TABLE mapping _unique_ elements of `x` to the number
114114
of times they occur in `x`."
115-
(prog1-let (map (make-hash-table :test test))
115+
(prog1-let map (make-hash-table :test test)
116116
(map nil (lambda (e) (incf (gethash e map 0))) x)))
117117

118118

vendor/quickutils.lisp

+17-4
Original file line numberDiff line numberDiff line change
@@ -1355,11 +1355,24 @@ without altering the original behavior.
13551355
(first args))
13561356

13571357

1358-
(defmacro prog1-let ((name result-form) &body body)
1359-
"Like PROG1, except it lets you bind the result of the `result-form` (i.e., the returned
1360-
form) to `name` (via LET) for the scope of `body`.
1358+
(defmacro prog1-let (name result-form &body body)
1359+
"Evaluates `result-form`, binds its value to `name`, executes `body`, and
1360+
finally return `name`. Similar to PROG1 but maintains the binding of
1361+
the result throughout `body`'s execution.
13611362
1362-
Inspired by ActiveSupport: Object#returning
1363+
Example:
1364+
1365+
(prog1-let x (list 1 2 3)
1366+
(setf (first x) 10) ; modifies the list
1367+
(print x)) ; prints (10 2 3)
1368+
=> (10 2 3) ; returns the modified list
1369+
1370+
(prog1-let x (make-hash-table)
1371+
(setf (gethash 'hello x) t) ; modifies the hash-table
1372+
(setf (gethash 'world x) t) ; modifies it again
1373+
=> #<HASH-TABLE :TEST EQL :COUNT 2 {700AB03913}> ; returns the initialized hash-table
1374+
1375+
Inspired by ActiveSupport's Object#returning from Ruby on Rails:
13631376
https://weblog.jamisbuck.org/2006/10/27/mining-activesupport-object-returning.html"
13641377
(prog1-let-expand name result-form body))
13651378

0 commit comments

Comments
 (0)