Okay, I am new with scheme/racket/lisp. I am practicing creating my own functions, syntax, and recursion, so I want to make my own foldl
and foldr
functions that do exactly what the predefined versions do. I can't do it because I just don't understand how these functions work. I have seen similar questions on here but I still don't get it. Some examples broken down would help! Here is my (incorrect) process:
(foldl - 0 '(1 2 3 4))
I do 0 -(4-3-2-1)
and get 2 which is the right answer
(foldl - 0 '(4 3 2 1))
I do 0-(1-2-3-4)
and get 8 but it should be -2.
(foldr - 0 '(1 2 3 4))
I do 0-(1-2-3-4)
and get 8 again, but it should be -2.
(foldr - 0 '(4 3 2 1))
I do 0-(4-3-2-1)
and get 2 which is the right answer.
What am I doing wrong?