Incorrect LOOP statement #25

juanjosegarciaripoll opened this Issue Sep 2, 2012 · 5 comments


None yet

2 participants


The patch below is self-explanatory. Unfortunately, several Common Lisps out there allow the use of illegal and underspecified LOOP statements --- but beware that such statements are not Common Lisp and their outcome is undefined (in particular, ECL signals an error).

diff --git a/src/math.lisp b/src/math.lisp
index 9d428c7..955d6f7 100644
--- a/src/math.lisp
+++ b/src/math.lisp
@@ -8,6 +8,20 @@ denominator."
(type integer a b))
(assert (and (>= a 0)
(>= b 0)))

  • (do ((c a (- d (* q c)))
  • (d b c)
  • (u_c 1 (- u_d (* q u_c)))
  • (v_c 0 (- v_d (* q v_c)))
  • (u_d 0 u_c)
  • (v_d 1 v_c))
  • ((= c 0)
  • (values d u_d v_d))
  • (setq c (floor d c)))
  • ;; The following form is not ANSI Common Lisp
  • ;; A FOR statement cannot follow an UNTIL statement because the ordering
  • ;; of evaluation for such a combination is NOT defined. Moreover, the
  • ;; grammar for LOOP forbids it.
  • #+(or) (loop for c = a then (- d (* q c)) and d = b then c

Thanks for the patch. For future patches, please actually remove the incorrect code, rather than just providing an alternative and commenting out the offending form. A pull request would be even better.

@eadmund, does @juanjosegarciaripoll's translation of LOOP into DO look correct to you?


After looking at this more closely, this patch cannot be correct. Q is not defined in the new loop.


Hopefully this time github will not screw my text. The patch here
corrects the problems of my original patch (one typo and the lack of a binding for Q). I tested it with SBCL so that the new function reproduces the undefined behavior of the original one.


Fixed in commit fc2ac2e. Thanks for the fix.

@froydnj froydnj closed this Sep 29, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment