The Little Schemer evens-only*&co

前端 未结 4 1543
失恋的感觉
失恋的感觉 2020-12-29 10:23

I\'m having difficulty understanding what\'s going on with The Little Schemer\'s evens-only*&co example on page 145.

Here\'s the code:



        
4条回答
  •  悲哀的现实
    2020-12-29 10:39

    The answer by Jon O. is a really great in-depth explanation of underlying concepts. Though for me (and hopefully, for some other people too), understanding of concepts like this is a lot more easier when they have a visual representation.

    So, I have prepared two flow-charts (similar to ones I did for multirember&co, untangling what is happening during the call of evens-only*&co

    given l is:

    '((9 1 2 8) 3 10 ((9 9) 7 6) 2) 
    

    and col is:

    (define the-last-friend
        (lambda (newl product sum)
            (cons sum (cons product newl))
        )
    )
    

    One flow-chart, reflecting how variables relate in different steps of recursion: Second flow-chart, showing the actual values, being passed:

    My hope is, that this answer will be a decent addition to the Jon's explanation above.

提交回复
热议问题