Skip to content

Commit 66327f8

Browse files
committed
Allow LOOP DO/WHILE to be relocated to variable clauses
1 parent 3ffbc28 commit 66327f8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/lisp/kernel/lsp/loop2.lisp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -884,9 +884,16 @@ collected result will be returned as the value of the LOOP."
884884
(defun loop-construct-return (form)
885885
`(return-from ,(car *loop-names*) ,form))
886886

887+
(defun loop-pseudo-body (form)
888+
(cond ((or *loop-emitted-body* *loop-inside-conditional*)
889+
(push form *loop-body*))
890+
(t
891+
(push form *loop-before-loop*)
892+
(push form *loop-after-body*))))
893+
887894
(defun loop-emit-body (form)
888895
(setq *loop-emitted-body* t)
889-
(push form *loop-body*))
896+
(loop-pseudo-body form))
890897

891898
(defun loop-emit-final-value (&optional (form nil form-supplied-p))
892899
(when form-supplied-p
@@ -1122,7 +1129,7 @@ collected result will be returned as the value of the LOOP."
11221129
(when (loop-tequal (car *loop-source-code*) :end)
11231130
(loop-pop-source))
11241131
(when it-p (setq form `(setq ,it-p ,form)))
1125-
(loop-emit-body
1132+
(loop-pseudo-body
11261133
`(if ,(if negatep `(not ,form) form)
11271134
,then
11281135
,@else))))))
@@ -1296,7 +1303,9 @@ collected result will be returned as the value of the LOOP."
12961303

12971304
(defun loop-do-while (negate kwd &aux (form (loop-get-form)))
12981305
(loop-disallow-conditional kwd)
1299-
(loop-emit-body `(,(if negate 'when 'unless) ,form (go end-loop))))
1306+
(loop-pseudo-body `(,(if negate 'when 'unless)
1307+
,form
1308+
(go end-loop))))
13001309

13011310

13021311
(defun loop-do-with ()

0 commit comments

Comments
 (0)