SICP Video Lecture 2

I have a problem with this example

(define (+ xy) (if (= x 0) y (+ (-1+ x) (1+ y)))) 

What is the problem with -1 + and 1+, when I evaluate it, I get this result

  • DrScheme: -1+: this function is not defined
  • racket: id reference undefined: -1 +

but i write this instead and it works

 (define (add xy) (if (= x 0) y (+ (- x 1) (+ y 1)))) 
+6
source share
2 answers

For racket:

  • Use add1 instead of 1+
  • Use sub1 instead of -1+ or 1-

The problem is that none of these names is standard, so you cannot reliably use them in all implementations of the Scheme. :-)

+12
source

You can fix this by adding SICP support to DrRacket.

http://www.neilvandyke.org/racket-sicp/

Another problem let me know.

+2
source

Source: https://habr.com/ru/post/898878/


All Articles