-
-
Notifications
You must be signed in to change notification settings - Fork 357
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
euclid algorithm in scheme #582
euclid algorithm in scheme #582
Conversation
I am pretty sure I fixed everything. I changed the (cond)s to (if)s, it makes it cleaner and a bit more consistent with the Common Lisp implementations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of the style is up to you (the only hard and fast rule IMO is no dangling parens, thank you for not doing that), and it runs under Guile and Chez and gives the right answer. Something is up with my Chicken install or I'm doing it wrong...
@@ -0,0 +1,16 @@ | |||
(define (euclid-sub a b) | |||
(if (or (negative? a) (negative? b)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line under each of the two define
s is the only one that shouldn't be aligned with the above subexpression: http://community.schemewiki.org/?scheme-style
(cond | ||
[(or (negative? a) (negative? b)) (euclid-sub (abs a) (abs b))] | ||
[(eq? a b) a] | ||
(if (> a b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be part of the first cond:
[(eq? a b) a]
[(> a b) (euclid-sub (- a b) b)]
[else (euclid-sub a (- b a)]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yeah that was my bad I meant to put that in the cond statement
There is extra whitespace in the first few lines of the cond. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, well done!
Implemented euclidean GCD algorithm in scheme. Added scheme to book.json. Tested with ChezScheme 9.5 and ChickenScheme 4.12.