开发者

SICP Video Lecture 2

I have a problem with this example

(define (+ x y)
  (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 : reference to undefined identifier: -1+

but i write this instead and it works

(define (add x y)
  (if (= x 0)
      y
      (+ (- x 1) (+ y 1)))开发者_如何学编程)


For Racket:

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

The trouble is, none of those names are standard, so you can't reliably use them across all Scheme implementations. :-)


You can fix this by adding SICP support to DrRacket.

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

Anymore trouble let me know.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜