Reputation: 117
I have to use DrRacket for this problem but every time I run the code, I get this error message "gcd: this name was defined previously and cannot be re-defined". (also I choose the language as Advanced student [custom] in DrRacket. below is my code, its a recursive function to find the greatest common divisor:
(define (gcd n m)
(cond [(= m 0) n]
[else (gcd m (modulo n m))]))
(check-expect (gcd 0) 0)
(check-expect (gcd 12 8) 4)
(check-expect (gcd 6 12 8) 2)
Upvotes: 1
Views: 889
Reputation: 43842
The gcd
function is already provided as part of the Advanced Student language, as you can see in the documentation here. Unlike the full Racket language, the teaching languages do not permit defining functions with the same name as library functions. Note that if you remove your definition of gcd
, all your tests pass.
If this is homework, then you probably need to name your gcd
function something else. If the assignment requires that your function be named gcd
, then there’s probably an issue with the assignment.
Upvotes: 3