我想循环这个,直到nr-of-bread是2怎么做?
(when (and (>= money price-of-bread) (< nr-of-bread 2))
(set! nr-of-bread (+ nr-of-bread 1)) (set! money (- money price-of-bread)))
答案 0 :(得分:1)
实现这一目标的最佳方法是使用名为let
的尾递归:
(let loop ((nr-of-bread 0)
(rest money))
(if (and (>= rest price-of-bread) (< nr-of-bread 2))
(loop (add1 nr-of-bread) (- rest price-of-bread))
nr-of-bread))