Skip to content
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

Merged
merged 11 commits into from
Feb 2, 2019

Conversation

c252
Copy link
Member

@c252 c252 commented Jan 26, 2019

Implemented euclidean GCD algorithm in scheme. Added scheme to book.json. Tested with ChezScheme 9.5 and ChickenScheme 4.12.

@Gathros Gathros added the Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) label Jan 27, 2019
@c252
Copy link
Member Author

c252 commented Feb 2, 2019

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.

Copy link
Member

@berquist berquist left a 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...

contents/euclidean_algorithm/code/scheme/euclidalg.ss Outdated Show resolved Hide resolved
@@ -0,0 +1,16 @@
(define (euclid-sub a b)
(if (or (negative? a) (negative? b))
Copy link
Member

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 defines 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)
Copy link
Contributor

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)]

Copy link
Member Author

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

@berquist
Copy link
Member

berquist commented Feb 2, 2019

There is extra whitespace in the first few lines of the cond. The else should also be in square brackets like the other statements.

Copy link
Contributor

@Trashtalk217 Trashtalk217 left a 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!

@berquist berquist merged commit 93eed1c into algorithm-archivists:master Feb 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants