1

A homework problem needs me to calculate gcd of 2 numbers. But using the modulo keyword in the function for gcd gives the above error when run on Repl.it (online IDE).

I looked at other answers, but they don't exactly provide a solution to the problem. I tried to run the program using jdoodle.com (another online IDE) and it works perfectly there. So, I don't know why it won't work on Repl.

;; My gcd function

(define (gcd a b)
  (cond 
    [
      (= b 0) a
    ]

    [else 
      (gcd b (modulo a b))
    ]
  )
)

I would like to know why this doesn't work for Repl IDE and if there is any way how I can make it work there without simply switching to another website.

iamshnoo
  • 111
  • 1
  • 2
  • 10

1 Answers1

1

modulo function is not implemented in BiwaScheme used by repl.it. However good new is - mod function is! So, with some reasonable reformatting, this should work:

(define (gcd a b)
   (cond [(= b 0) a]
         [else (gcd b (mod a b))]))
rsm
  • 2,530
  • 4
  • 26
  • 33
  • 1
    I tried it out. `mod` indeed does work for repl. Thank you. – iamshnoo Apr 09 '19 at 15:14
  • 1
    Also, about the weird formatting I had used, I am new to Scheme, so I am just being extra careful with the brackets :) – iamshnoo Apr 09 '19 at 15:15
  • 1
    The reason why is that BiwaScheme follows R6RS which has `mod` and `mod0`, while OP tries `modulo` which is defined in the previous standard, R5RS. Other programming languages has incompatible major versions as well, eg. Python 2 vs 3. – Sylwester Apr 10 '19 at 22:34