0

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 (null? x)
        u
        (h (cdr x) (f u (car x)))))
  (h x 0))
C. K. Young
  • 219,335
  • 46
  • 382
  • 435
  • I recommend commenting your code. Then it would be easy to compare the comments with what the code actually does to see where it went wrong. – Gabe Sep 24 '11 at 14:38

1 Answers1

2

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.)

Community
  • 1
  • 1
C. K. Young
  • 219,335
  • 46
  • 382
  • 435
  • Thanku, i will not copy paste you solution, not what i do, just wanted to see if any one could give me hint or give me ideas of how i can solve this problem. You did Thanks. –  Sep 24 '11 at 15:27