~ chicken-core (chicken-5) f945fd844bf6e24527d5dd085cdba7c0e9f57cd7
commit f945fd844bf6e24527d5dd085cdba7c0e9f57cd7 Author: Peter Bex <peter@more-magic.net> AuthorDate: Wed Feb 11 22:02:45 2015 +0100 Commit: Peter Bex <peter@more-magic.net> CommitDate: Sun May 31 14:20:16 2015 +0200 Improve error messages in lcm by enforcing that the checks done by gcd are performed first, which has the location available diff --git a/library.scm b/library.scm index 4218aa2c..e1d83657 100644 --- a/library.scm +++ b/library.scm @@ -1991,7 +1991,8 @@ EOF (##sys#slot next 1)) ) ) ) ) ) (define (##sys#lcm x y) - (abs (quotient (* x y) (##sys#internal-gcd 'lcm x y)) )) + (let ((gcd (##sys#internal-gcd 'lcm x y))) ; Ensure better error message + (abs (quotient (* x y) gcd) ) ) ) (define (lcm . ns) (if (null? ns) @@ -2000,9 +2001,9 @@ EOF (next (##sys#slot ns 1))) (if (null? next) (if (integer? head) (abs head) (##sys#error-bad-integer head 'lcm)) - (let ((n2 (##sys#slot next 0))) - (loop (quotient (##sys#*-2 head n2) - (##sys#internal-gcd 'lcm head n2)) + (let* ((n2 (##sys#slot next 0)) + (gcd (##sys#internal-gcd 'lcm head n2))) + (loop (quotient (##sys#*-2 head n2) gcd) (##sys#slot next 1)) ) ) ) ) ) ;; This simple enough idea is fromTrap