I am new to scheme. This is code sample from SICP course of MIT.
(define (+ x y)
(if (= x 0)
y
(+ (-1+ x) (1+ y))))
How do I convert this to Racket code? I want to convert to Racket because I am using DrRacket for running codes and I like that. It worked until now but complained about increment operators of scheme.
The errors I get are:
define-values: cannot change constant variable: +reference to undefined identifier: -1+
This will work fine in Racket:
Some comments:
+for the procedure will be troublesome, because it will clash with the primitive add operation in Scheme; it’s simpler if you use a different name, likeadd(this will fix the first error)-1+is not a procedure in Racket, replace it withsub1(this will fix the second error). Optionally, you could define an alias for this procedure, like this:(define -1+ sub1)1+is not a procedure in Racket, replace it withadd1. Optionally, you could define an alias for this procedure, like this:(define 1+ add1)(= x 0)you can write(zero? x)