开发者

Scheme function that sum number u and list x u+x1+x2

Im new to Scheme and trying to make function that is (in f u x), u is integer, x is a list and f binary function. The scheme expression (in + 3 '(1 2 3)) should return 3+1+2+3=9.

I have this but if i do (in + 3 '(1 2)) it return 3 not 6. What am i doing wrong?

(define (in f u x)
  (define (h x u)
    (if (nul开发者_StackOverflow社区l? x)
        u
        (h (cdr x) (f u (car x)))))
  (h x 0))


From what I understand of what your in function is supposed to do, you can define it this way:

(define in fold)   ; after loading SRFI 1

:-P

(More seriously, you can look at my implementation of fold for some ideas, but you should submit your own version for homework.)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜