Questions tagged [the-little-schemer]

**The Little Schemer**, a book on recursive programming by Daniel P. Friedman and Matthias Felleisen

The Little Schemer (original title: The Little Lisper) is a book by Daniel P. Friedman and Matthias Felleisen, designed to introduce the principles of recursive programming to an audience who may have no prior experience of programming or mathematics. All the examples are in the Scheme language but it is not intended as an introduction to Scheme (although it is based on lecture notes from an "Introduction to Scheme" mini course) and only uses that subset of the language necessary to implement solutions to the various tasks set in the book.

67 questions
8
votes
4 answers

Check if list is flat in Haskell

In The Little Schemer there is a function to check, whether the list is flat: (define lat? (lambda (l) (cond ((null? l) #t) ((atom? (car l)) (lat? (cdr l))) (else #f)))) I'm trying to write the same recursive function in…
Mirzhan Irkegulov
  • 17,660
  • 12
  • 105
  • 166
7
votes
2 answers

Is lat? a primitive function in Scheme?

Suppose l is defined as follows: > (define l (list 1 2 3)) l is now bound to a list of atoms. Little Schemer introduces a simple function called lat? which evaluates to #t or #f depending on the argument's classification as a list of atoms. For…
David Shaked
  • 3,171
  • 3
  • 20
  • 31
6
votes
4 answers

Scheme implementations - what does it mean?

I'm a beginning student in CS, and my classes are mostly in Java. I'm currently going through "Little Schemer" as a self study, and in the process of finding out how to do that I have found numerous references to "implementations" of Scheme. My…
JDelage
  • 13,036
  • 23
  • 78
  • 112
6
votes
1 answer

Little Schemer: length0 and mk-length

The little schemer gives the following on page 165 as still the function length0. 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…
user782220
  • 10,677
  • 21
  • 72
  • 135
6
votes
3 answers

Why am I getting an unbound error for "atom?"

I'm trying to go through "The Little Lisper" and already running into snags in the first chapter. I'm relatively new to Emacs (which has fueled my interest in learning Lisp and clojure). I downloaded the Mit-scheme app, and am working the exercises…
Tavore
  • 73
  • 6
5
votes
4 answers

What's the reason for using lambda expressions to define functions in Scheme?

I am reading the The Little Schemer book by Daniel Friedman. I don't understand why every function in the book is written with a lambda expression. (define fun1 (lambda (x1 x2) (+ x1 x2))) (define (fun2 x1 x2) (+ x2 x2)) The two functions…
richard.g
  • 3,585
  • 4
  • 16
  • 26
5
votes
2 answers

The mechanism of anonymous function to call itself in Scheme?

I'm reading The Little Schemer and feel confused about the following code: ((lambda (len) (lambda (l) (cond ((null? l) 0) (else (+ 1 (len (cdr l))))))) eternity) (define eternity (lambda (x) …
liu
  • 937
  • 1
  • 9
  • 15
5
votes
1 answer

The Little Schemer 4th Edition: rember function discussion

On page 41 after simplification of the rember function, there is a question-respond that I don't understand very well. Q: So why don't we simplify right away? R: Because then a function's structure does not coincide with its argument's structure.…
jolisper
  • 309
  • 3
  • 8
4
votes
3 answers

Flatten a list using only the forms in "The Little Schemer"

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…
Harry Spier
  • 1,395
  • 16
  • 30
4
votes
2 answers

mini-kanren what is the difference between cond-a cond-u and cond-e?

I have tried to use an implementation of mini-kanren in clojure. But been struggling to understand the difference between cond-a cond-u and cond-e. I seem to be quite clear about cond-e but understanding of cond-a and cond-u is quiet bad. cond-e…
4
votes
2 answers

why second argument to cons must be a list

I'm reading the book called the little schemer. Before read that, i've finished reading first three chapter of SICP. My question is that why second argument to cons must be a list. However, (cons a b) works for all values a and b and (car (cons a…
ray
  • 145
  • 9
4
votes
2 answers

The result of cons in "The Little Schemer"

On page 178, there is a question: what is the value of (cons rep-car (cons (cons rep-quote (cons (cons rep-a (cons rep-b (cons rep-c (quote ())))) (quote…
user1506414
4
votes
3 answers

how to understand this continuation?

(let ([x (call/cc (lambda (k) k))]) (x (lambda (ignore) "hi"))) => "hi" How can I write the executing steps of this continuation?
abelard2008
  • 1,984
  • 1
  • 20
  • 35
3
votes
1 answer

Is there an example of the "align" function from The Little Schemer?

In chapter 9 of The Little Schemer: (define align (lambda (pora) (cond ((atom? pora) pora) ((a-pair? (first pora)) (align (shift pora))) (else (build (first pora) (align (second pora))))))) Most of…
wang kai
  • 1,673
  • 3
  • 12
  • 21
3
votes
3 answers

Scheme: When I cons two atoms I am getting a dot in the middle. Why?

When I do a cons on two atoms, I am getting a . in between. 1]=>(cons 'one 'two) ;Value 1: (one . two) Why I am getting the . operator. Does it have any meaning? I am using mit-scheme. I have seen this stackoverflow link but not clear. UPDATE: The…
Sreekumar R
  • 573
  • 6
  • 24