the-little-schemer

Flatten a list using only the forms in “The Little Schemer”

吃可爱长大的小学妹 提交于 2019-11-26 19:12:18
I'm going through The LIttle Schemer to learn Scheme (as an old C programmer) and as an exercise I tried to write a procedure to flatten a list using only the forms in The Little Schemer; I.e., define , lambda , cond , car , cdr , and , or , etc., but not append . I thought it would be easy but I haven't been able to come up with a solution. How can I do this ? I have a version that uses only "first-principles" operations and is efficient (does not require more than one pass through any of the lists, unlike append -based solutions). :-) It does this by defining two simple building blocks (

Y combinator discussion in “The Little Schemer”

偶尔善良 提交于 2019-11-26 07:58:23
问题 So, I\'ve spent a lot of time reading and re-reading the ending of chapter 9 in The Little Schemer , where the applicative Y combinator is developed for the length function. I think my confusion boils down to a single statement that contrasts two versions of length (before the combinator is factored out): A: ((lambda (mk-length) (mk-length mk-length)) (lambda (mk-length) (lambda (l) (cond ((null? l) 0 ) (else (add1 ((mk-length mk-length) (cdr l)))))))) B: ((lambda (mk-length) (mk-length mk