3
3
; ; Description - Applicative iteration
4
4
; ; Author - Tim Bradshaw (tfb at lostwithiel)
5
5
; ; Created On - Sat Oct 7 00:23:24 2000
6
- ; ; Last Modified On - Sat Mar 11 16:51:22 2023
6
+ ; ; Last Modified On - Wed Mar 20 08:41:14 2024
7
7
; ; Last Modified By - Tim Bradshaw (tfb at pendeen.fritz.box)
8
- ; ; Update Count - 18
8
+ ; ; Update Count - 19
9
9
; ; Status - Unknown
10
10
; ;
11
11
; ; $Id$
14
14
; ;;; * Applicative iteration (don't need this in CMUCL)
15
15
; ;;
16
16
17
- ; ;; iterate.lisp is copyright 1997-2000, 2021, 2023 by me, Tim
17
+ ; ;; iterate.lisp is copyright 1997-2000, 2021, 2023, 2024 by me, Tim
18
18
; ;; Bradshaw, and may be used for any purpose whatsoever by anyone. It
19
19
; ;; has no warranty whatsoever. I would appreciate acknowledgement if
20
20
; ;; you use it in anger, and I would also very much appreciate any
21
21
; ;; feedback or bug fixes.
22
22
; ;;
23
- ; ;; The improvements to all this code in 2023, as well as the new
24
- ; ;; ITERATE*, ITERATING & ITERATING* are due to Zyni: thank you.
23
+ ; ;; The improvements to all this code in 2023 & 2024 , as well as the
24
+ ; ;; new ITERATE*, ITERATING & ITERATING* are due to Zyni: thank you.
25
25
; ;;
26
26
27
27
(defpackage :org.tfeb.hax.iterate
33
33
(provide :org.tfeb.hax.iterate )
34
34
35
35
(defun extract-ignore/other-decls (decls/forms)
36
- ; ; See utilities. Bit this is not the same: it returns all ignores and others as two values
37
- ; ; others as two values.
38
- (do* ((ignores ' ())
39
- (others ' ())
40
- (tail decls/forms (rest tail))
41
- (this (first tail) (first tail)))
42
- ((or (null tail) (not (consp this))
43
- (not (eql (first this) ' declare)))
44
- (values (nreverse ignores) (nreverse others)))
45
- (if (and (consp (second this))
46
- (eql (first (second this)) ' ignore))
47
- (push this ignores)
48
- (push this others))))
36
+ ; ; See utilities. But this is not the same: it returns all ignores
37
+ ; ; and others as two values What's returned is the bodies of two
38
+ ; ; DECLARE forms.
39
+ (let ((ignores ' ())
40
+ (others ' ()))
41
+ (dolist (d/f decls/forms)
42
+ (unless (and (consp d/f)
43
+ (eql (car d/f) ' declare))
44
+ (return ))
45
+ (dolist (d (rest d/f))
46
+ (if (and (consp d) (eql (car d) ' ignore))
47
+ (push d ignores)
48
+ (push d others))))
49
+ (values (nreverse ignores)
50
+ (nreverse others))))
49
51
50
52
(defun expand-iterate (name bindings body starred)
51
53
(unless (every (lambda (binding)
67
69
binding)
68
70
(list
69
71
(first binding))))
70
- bindings))
71
- (argvals
72
- (mapcar (lambda (binding)
73
- (typecase binding
74
- (symbol
75
- nil )
76
- (list
77
- (case (length binding)
78
- ((1 )
79
- nil )
80
- ((2 )
81
- (second binding))))))
82
72
bindings)))
83
- (if (not starred)
84
- ` (labels ((, name , argnames
85
- ,@ body))
86
- (, name ,@ argvals))
87
- (multiple-value-bind (ignores others) (extract-ignore/other-decls body)
88
- (declare (ignore others))
89
- ` (labels ((, name , argnames
73
+ (multiple-value-bind (ignores others) (extract-ignore/other-decls body)
74
+ (declare (ignore ignores))
75
+ ` (, (if starred ' let* ' let) , bindings
76
+ (declare ,@ others)
77
+ (labels ((, name , argnames
90
78
,@ body))
91
- (let* , (mapcar #' list argnames argvals)
92
- ,@ ignores
93
- (, name ,@ argnames)))))))
79
+ (, name ,@ argnames))))))
94
80
95
81
(defmacro iterate (name bindings &body body)
96
82
" Scheme-style named-LET: parallel binding
@@ -181,13 +167,13 @@ This is like LET*: initial values can depend on preceeding variables."
181
167
(let ((secret-name (make-symbol (symbol-name name))))
182
168
(multiple-value-bind (ignores others) (extract-ignore/other-decls body)
183
169
` (labels ((, secret-name , argnames
184
- ,@ ignores ,@ others
170
+ ( declare ,@ ignores ,@ others)
185
171
(flet ((, name (&key ,@ (mapcar #' list argnames argsteps))
186
172
(, secret-name ,@ argnames)))
187
173
(declare (inline , name))
188
174
,@ body)))
189
175
(let* , (mapcar #' list argnames argvals)
190
- ,@ others
176
+ ( declare ,@ others)
191
177
(, secret-name ,@ argnames))))))))
192
178
193
179
(defmacro iterating (name bindings &body body)
@@ -203,7 +189,7 @@ preceeding variables and step forms see the old values of variables."
203
189
(expand-iterating name bindings body nil ))
204
190
205
191
(defmacro iterating* (name bindings &body body)
206
- " Applicative iteration macro with optional step forms: sequentisl binding
192
+ " Applicative iteration macro with optional step forms: sequential binding
207
193
208
194
This is like ITERATE but each binding can be (var init/step) or (var
209
195
init step). The local function has approproate keyword arguments
0 commit comments