the-little-schemer

How do collector functions work in Scheme?

末鹿安然 提交于 2019-12-08 17:48:07
问题 I am having trouble understanding the use of collector functions in Scheme. I am using the book "The Little Schemer" (by Daniel P. Friedman and Matthias Felleisen). A comprehensive example with some explanation would help me massively. An example of a function using a collector function is the following snippet: (define identity (lambda (l col) (cond ((null? l) (col '())) (else (identity (cdr l) (lambda (newl) (col (cons (car l) newl)))))))) ... with an example call being (identity '(a b c)

Little Schemer: length0 and mk-length

最后都变了- 提交于 2019-12-07 17:42:29
问题 The little schemer gives the following on page 165 as still the function length 0 . But how does this work? It looks like the length lambda is being passed to the mk-length lambda , which evaluates the length lambda with the length lambda itself passed as an argument. So then, when (length (cdr l)) at the bottom is evaluated length is just the length lambda itself. But the length lambda takes two parameters curried: length and l . So how can (length (cdr l)) make sense then? ((lambda (mk

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

Little Schemer: length0 and mk-length

筅森魡賤 提交于 2019-12-06 01:49:32
The little schemer gives the following on page 165 as still the function length 0 . But how does this work? It looks like the length lambda is being passed to the mk-length lambda , which evaluates the length lambda with the length lambda itself passed as an argument. So then, when (length (cdr l)) at the bottom is evaluated length is just the length lambda itself. But the length lambda takes two parameters curried: length and l . So how can (length (cdr l)) make sense then? ((lambda (mk-length) (mk-length mk-length)) (lambda (length) (lambda (l) (cond ((null? l) 0) (else (add1 (length (cdr l)

The Little Schemer - Where to start?

醉酒当歌 提交于 2019-12-04 16:03:49
问题 I just cracked open The Little Schemer, and I feel like I'm missing something. The first question asks "Is it true that this is an atom?", but I do not see any definition of what an atom is. I suppose I can derive what an atom is by the answers to the questions, but then it goes on to ask what is the car of l, and what is the cdr of l, and I have no idea what is being asked. Is the purpose of the book to discover what the questions mean by reading the answers, or is there some basic knowledge

Which environment, IDE or interpreter to put in practice Scheme?

戏子无情 提交于 2019-12-03 12:10:12
问题 I've been making my way through The Little Schemer and I was wondering what environment, IDE or interpreter would be best to use in order to test any of the Scheme code I jot down for myself. 回答1: Racket (formerly Dr Scheme) has a nice editor, several different Scheme dialects, an attempt at visual debugging, lots of libraries, and can run on most platforms. It even has some modes specifically geared around learning the language. 回答2: I would highly recommend both Chicken and Gauche for

The Little Schemer - Where to start?

时光总嘲笑我的痴心妄想 提交于 2019-12-03 10:05:34
I just cracked open The Little Schemer, and I feel like I'm missing something. The first question asks "Is it true that this is an atom?", but I do not see any definition of what an atom is. I suppose I can derive what an atom is by the answers to the questions, but then it goes on to ask what is the car of l, and what is the cdr of l, and I have no idea what is being asked. Is the purpose of the book to discover what the questions mean by reading the answers, or is there some basic knowledge that I need before I tackle this book? If the latter, can someone point me to where I might acquire

What is ' (apostrophe) in Lisp / Scheme?

拜拜、爱过 提交于 2019-12-03 06:27:55
问题 I am on day 1 hour 1 of teaching myself Scheme. Needless to say, I don't understand anything. So I'm reading The Little Schemer and using this thing: http://sisc-scheme.org/sisc-online.php as an interpreter. I need to use ' in for example (atom? 'turkey) to avoid an "undefined variable" error. The ' , according to the book, is a Common Lisp thing. I have two questions: Is the interpreter I mentioned above a good one? Can you recommend another? I need one that will go well with The Little

Which environment, IDE or interpreter to put in practice Scheme?

拜拜、爱过 提交于 2019-12-03 02:49:47
I've been making my way through The Little Schemer and I was wondering what environment, IDE or interpreter would be best to use in order to test any of the Scheme code I jot down for myself. infinitetape Racket ( formerly Dr Scheme ) has a nice editor, several different Scheme dialects, an attempt at visual debugging, lots of libraries, and can run on most platforms. It even has some modes specifically geared around learning the language. I would highly recommend both Chicken and Gauche for scheme. PLT Scheme (DrScheme) is one of the best IDEs out there, especially for Scheme. The package you

Why all the lambdas in The Little Schemer?

倾然丶 夕夏残阳落幕 提交于 2019-12-02 20:37:31
After learning a bit of Scheme from SICP, I started reading The Little Schemer (which I find quite entertaining) and am about one fourth done. I noticed that I can write many (most? all?) solutions without using lambda whereas The Little Schemer always uses them. For example, the very first definition is (define atom? (lambda (x) (and (not (pair? x)) (not (null? x))))) which, unless I am mistaken, can be written more simply as (define (atom? x) (and (not (pair? x)) (not (null? x)))) Am I missing something fundamental if I write lambda-less solutions? Originally, define had a single syntax, to