Skip to content

Allow LOOP WHILE/UNTIL to be relocated to variable clauses #1693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/lisp/kernel/lsp/loop2.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -884,9 +884,16 @@ collected result will be returned as the value of the LOOP."
(defun loop-construct-return (form)
`(return-from ,(car *loop-names*) ,form))

(defun loop-pseudo-body (form)
(cond ((or *loop-emitted-body* *loop-inside-conditional*)
(push form *loop-body*))
(t
(push form *loop-before-loop*)
(push form *loop-after-body*))))

(defun loop-emit-body (form)
(setq *loop-emitted-body* t)
(push form *loop-body*))
(loop-pseudo-body form))

(defun loop-emit-final-value (&optional (form nil form-supplied-p))
(when form-supplied-p
Expand Down Expand Up @@ -1122,7 +1129,7 @@ collected result will be returned as the value of the LOOP."
(when (loop-tequal (car *loop-source-code*) :end)
(loop-pop-source))
(when it-p (setq form `(setq ,it-p ,form)))
(loop-emit-body
(loop-pseudo-body
`(if ,(if negatep `(not ,form) form)
,then
,@else))))))
Expand Down Expand Up @@ -1296,7 +1303,9 @@ collected result will be returned as the value of the LOOP."

(defun loop-do-while (negate kwd &aux (form (loop-get-form)))
(loop-disallow-conditional kwd)
(loop-emit-body `(,(if negate 'when 'unless) ,form (go end-loop))))
(loop-pseudo-body `(,(if negate 'when 'unless)
,form
(go end-loop))))


(defun loop-do-with ()
Expand Down
Loading