680 questions
1
vote
2
answers
158
views
SICP exercise 1.19, transformations
From Structure and Implementation of Computer Programs, second edition:
Exercise 1.19: There is a clever algorithm for computing the Fibonacci numbers in a logarithmic number of steps.Recall the
...
1
vote
0
answers
136
views
Can we check whether one *alleged* directed binary tree contains a cycle in O(1) space?
This is from sicp although a bit different:
Exercise 3.18. Write a procedure that examines a list and determines whether it contains a cycle, that is, whether a program that tried to find the end of ...
1
vote
0
answers
63
views
Is it necessary to use lazy evaluation instead of stream for lazy tree with Scheme language?
This is from one footnote in SICP:
Note that these lazy lists are even lazier than the streams of chapter 3: The car of the list, as well as the cdr, is delayed. ^[41]
[41] This permits us to create ...
1
vote
2
answers
83
views
Why can we use first-class expression in place of first-class function?
This is from this CS 61A notes about SICP p80~82 about ucblogo (a dialect of Logo, which derived from Lisp):
Second, Logo has first-class expressions; you can run a list that you get as an argument.
...
1
vote
0
answers
67
views
Can we modify R7RS implementation of the derived expression type `do` to finish SICP exercise 4.9?
This is one follow-up question of this QA where how syntax-rules works has been known owing to Shawn. As someone told me before, one different question although somewhat related should be posted as ...
0
votes
0
answers
146
views
How to implement one anonymous loop form like do in the evaluator as a derived expression using Scheme?
This is from SICP exercise 4.9.
Exercise 4.9. Many languages support a variety of iteration constructs, such as do, for, while, and until. In Scheme, iterative processes can be expressed in terms of ...
1
vote
1
answer
76
views
Redefining the special form after the usage of that special form in one func definition has no effects to that definition in Scheme
I am reading SICP section 3.5.1 where it gives the implementation of primitive procedures provided in MIT/GNU Scheme.
I tried to load these implementations without considering the order since they are ...
1
vote
0
answers
82
views
Why do fully-functional map, filter, and fold-right/fold-left need environment model?
This is one follow-up question of this QA. The comments there focus on how to implement map etc in C++ but doesn't say much about "relationship between environment model" and map etc.
SICP ...
0
votes
2
answers
160
views
Is environment model necessary for higher-order procedures?
When learning SICP, 6.001 lec15 has:
A good understanding of the environment model tells me why (IMHO) C++ will never have a fully-functional map, filter, and fold-right/fold-left procedures that are ...
0
votes
1
answer
61
views
Getting wrong answer for cube-root procedure in Scheme [closed]
I wrote this code to compute the cube root of a number in Scheme:
(define (square x) (* x x))
(define (abs x) (if (< x 0) (- x) x))
(define (cube x) (* x x x))
(define (cube-root-itr guess x)
(...
1
vote
1
answer
83
views
How to make `set!` change the variable in `let` (Scheme)?
Recently when I self-learnt MIT 6.5151 course, I have read SICP 1 to 2.1 as ps0 requires (also read 2.2.1 as CS 61A notes requires) and then Software Design for Flexibility (SDF) Prologue, chapter 1 ...
0
votes
1
answer
107
views
Why does Scheme use the procedural representation of pairs?
I am reading SICP. It says in 2.1.3:
That is, the operations satisfy the condition that, for any objects x and y, if z is (cons x y) then (car z) is x and (cdr z) is y. ... Here are the definitions:
...
3
votes
1
answer
77
views
When can we safely use the Randomized algorithm considering probability?
Recently when reading SICP, one footnote says:
Numbers that fool the Fermat test are called Carmichael numbers, and little is known about them other than that they are extremely rare. There are 255 ...
1
vote
2
answers
147
views
`1.0+1e-100=1.` in MIT-scheme
I am reading SICP and read this recitation about chapter 1. I use MIT/GNU Scheme as MIT course 6.5151 (6.905) does with version 12.1.
I am stuck at Problem 3.
Write a procedure that computes e.
I ...
0
votes
0
answers
94
views
Is there some error-case in this answer? for SICP 1.7
I'm a beginner with SICP.
For SICP 1.7, I assume this solution has some problem when '(improve guess x)' keeps returning different values compared to 'guess'.
But I can't find an error case for this ...