anonymous-recursion

Little Schemer: write function that only supports lists of length ≤ 2

强颜欢笑 提交于 2019-12-06 02:49:55
In the book The little schemer , we find this function that only supports lists with length smaller than or equal to 1 : (((lambda (mk-length) ; A. (mk-length mk-length)) (lambda (mk-length) (lambda (l) (cond ((null? l ) 0) (else (add1 ((mk-length eternity ) (cdr l)))))))) '(1)) I want to study step by step, and want to write the similar function that supports only lists of length smaller than or equal to 2 . Please, don't answer this question by offering code like: (((lambda (mk-length) ; B. (mk-length mk-length)) (lambda (mk-length) (lambda (l) (cond ((null? l) 0 ) (else (add1((mk-length mk

How to do this length≤1 more than once?

大憨熊 提交于 2019-12-02 03:22:39
问题 I've spent a day reading page 166's length≤1 in the book The Little Schemer ; there's the following code: (((lambda (mk-length) (mk-length mk-length)) (lambda (mk-length) (lambda (l) (cond ((null? l) 0) (else (add1 ((mk-length eternity) (cdr l)))))))) l) where l is (apples) and eternity is as follows: (define eternity (lambda (x) (eternity x))) Page 166 (4th ed.) states that: When we apply mk-length once, we get length≤1 And then Could we do this more than once? But I do not know how to do

In Scheme, how do you use lambda to create a recursive function?

放肆的年华 提交于 2019-11-27 12:43:38
I'm in a Scheme class and I was curious about writing a recursive function without using define. The main problem, of course, is that you cannot call a function within itself if it doesn't have a name. I did find this example: It's a factorial generator using only lambda. ((lambda (x) (x x)) (lambda (fact-gen) (lambda (n) (if (zero? n) 1 (* n ((fact-gen fact-gen) (sub1 n))))))) But I can't even make sense of the first call, (lambda (x) (x x)): What exactly does that do? And where do you input the value you want to get the factorial of? This is not for the class, this is just out of curiosity.

In Scheme, how do you use lambda to create a recursive function?

这一生的挚爱 提交于 2019-11-26 18:13:16
问题 I'm in a Scheme class and I was curious about writing a recursive function without using define. The main problem, of course, is that you cannot call a function within itself if it doesn't have a name. I did find this example: It's a factorial generator using only lambda. ((lambda (x) (x x)) (lambda (fact-gen) (lambda (n) (if (zero? n) 1 (* n ((fact-gen fact-gen) (sub1 n))))))) But I can't even make sense of the first call, (lambda (x) (x x)): What exactly does that do? And where do you input