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
3
votes
1 answer

Is the scope of primitive functions in The Little Schemer incorrect?

Consider the following s-expression: ((lambda (car) (car (quote (a b c)))) cdr) In most scheme implementations I've tried, this evaluates to (b c) because cdr is passed to the lambda, which names it car, taking precedence over the primitive…
Jeremy Huiskamp
  • 5,186
  • 5
  • 26
  • 19
3
votes
2 answers

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

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) …
3
votes
2 answers

Scheme: Why is there the need to use a cond here?

I tried to write a (simple, i.e. without eqan?) one? function like such: (define one? (lambda (n) ((= 1 n)))) But the above doesn't work though because when I call it like such: (one? 1) I get greeted with this error: procedure application:…
Andreas Grech
  • 105,982
  • 98
  • 297
  • 360
3
votes
2 answers

Syntax changes from the examples in 'The Little Schemer' to the real Scheme

I have recently started following the examples from The Little Schemer and when trying out the examples in DrScheme, I have realised that there are some minor syntax changes from the examples in the book to what I can write in DrScheme. First of…
Andreas Grech
  • 105,982
  • 98
  • 297
  • 360
3
votes
1 answer

Translating the Q and P function from The Little Schemer into Common Lisp?

In Chapter 9 of the Little Schemer, the Author presents the following two functions (define Q (lambda (str n) (cond ((zero? (remainder (first$ str ) n)) (Q (second$ str ) n)) (t (build (first$ str ) (lambda (…
hawkeye
  • 34,745
  • 30
  • 150
  • 304
3
votes
4 answers

Remove superfluous else from cond statement?

I'm currently reading the 4th edition of "The Little Schemer". One early exercise is to create a function insertR which inserts an value to the right of a given value in a list. The book eventually arrives at the following definition: (define…
Andreas Brinck
  • 51,293
  • 14
  • 84
  • 114
3
votes
3 answers

The Little Schemer: stuck on multiinsertLR&co example

I was able to grok the multirember&co function after some work, but I can't really make much sense out of the following multiinsertLR&co code (p. 143): (define multiinsertLR&co (lambda (new oldL oldR lat col) (cond ((null? lat) (col…
dtg
  • 1,803
  • 4
  • 30
  • 44
2
votes
2 answers

Why does "The Little Schemer" insist that the second argument to `cons` must be a list?

"The Little Schemer": The Law of Cons ... The second argument to cons must be a list. Also, "The Little Schemer": What is (cons s l) where s is 'a and l is 'b No answer. Why? But if I actually do (cons 'a 'b) I get '(a . b) which I know is…
joseville
  • 685
  • 3
  • 16
2
votes
3 answers

Performance Impact of Creating Enclosed Procedure in Scheme During Recursion

I'm making my way through the book The Little Schemer to start to learn to think in Lisp. As you get into it and really cover the use of lambdas, the 'remove' procedure is written in the following general form, which returns a remove procedure for…
2
votes
2 answers

Little Schemer: why wrap (mk-length mk-length) into a function?

In The Little Schemer book, in Chapter 9, while building a length function for arbitrary long input, the following is suggested (on pages 170-171), that in the following code snippet (from page 168 itself): ((lambda (mk-length) (mk-length…
user8554766
2
votes
1 answer

Why does this work in DrRacket but not in Racket from the console

(define pick (lambda (num lat) (cond ((null? lat) (quote())) ((= (sub1 num) 0) (car lat)) (else (pick (sub1 num) (cdr lat)))))) (define brees (quote (a b c d e touchdown g h i))) (pick 6…
eric.christensen
  • 3,191
  • 4
  • 29
  • 35
2
votes
1 answer

Racket (Scheme) Error: expected the name of the symbol after the quote, but found a part

I run this code (The Little Schemer) in Dr. Racket Verion 5.3.6: (define rember (lambda (a lat) (cond ((null? lat) (quote ())) (else (cond ((eq? (car lat) a) (cdr lat)) (else (cons (car lat) (rember a (cdr lat))))))))) and it…
2
votes
1 answer

How to do this length≤1 more than once?

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 …
2
votes
1 answer

what guide should I get from shift, align and shuffle?

In the beginning part of Chapter 9 in "The Little Schemer" , there are several examples such as looking, shift, align, and shuffle, (define looking (lambda (a lat) (keep-looking a (pick 1 lat) lat))) (define shift (lambda (pair) …
abelard2008
  • 1,984
  • 1
  • 20
  • 35
2
votes
1 answer

Testing whether two pairs (cons cells) are the same

The following function from pg 150 of the Seasoned Schemer establishes whether two lists have the same identity (i.e. occupy the same memory) by mutating each list's cdr and then checking whether the change has affected both: (define same? (lambda…
planarian
  • 2,047
  • 18
  • 18