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.)
精彩评论