;to compute the number of elements in a list.
(define (myListLength Lst)
(if (null? Lst)
0
(+ 1 (myListLength (cdr Lst) ))
)
)
;to compute the sum of elements in a list of numbers
(define (myListSum Lst)
(if (null? Lst)
0
(+ (car Lst) (myListSum (cdr Lst) ))
)
)
I am taking a Scheme class and I was doing well up until this point. My professor handed out some examples and i am having serious trouble understanding them.
I don't get how these functions work?? I don't understand how it is going threw the entire list like a loop but its a IF statement?
I also don't understand how +1 can be added to list since its not a number.
Any insight on this would be greatly appreciated.
(define (myListLength Lst)
(if (null? Lst)
0
(+ 1 (myListLength (cdr Lst) ))
)
)
;to compute the sum of elements in a list of numbers
(define (myListSum Lst)
(if (null? Lst)
0
(+ (car Lst) (myListSum (cdr Lst) ))
)
)
I am taking a Scheme class and I was doing well up until this point. My professor handed out some examples and i am having serious trouble understanding them.
I don't get how these functions work?? I don't understand how it is going threw the entire list like a loop but its a IF statement?
I also don't understand how +1 can be added to list since its not a number.
Any insight on this would be greatly appreciated.