5 ms·
Am I dreaming, or is this an example straight from SICP? (I remember something like this...) EDIT: Ok, so obviously not "straight" from SICP. But pretty close.
by AlexanderDhoore 13y ago
Am I dreaming, or is this an example straight from SICP? (I remember something like this...)
EDIT: Ok, so obviously not "straight" from SICP. But pretty close.
Chapter 1: "Example: Square Roots by Newton's Method" http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html#%_sec_1.1.7 http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html...
- lisper 13y agoWell, it can't be straight out of SICP because SICP uses Scheme and this code is in Haskell. And, in fact, if you did a straightforward translation of the Haskell code back into Scheme it wouldn't work. Figuring out why it doesn't work in Scheme but it does in Haskell is left as an exercise.
- obblekk 13y agoscheme lists aren't lazily generated?
- dmunoz 13y agoOf course, in later chapters SICP covers both streams [0] and lazy evaluation in the interpreter [1]. It's a really great book! I'm completely jealous of anyone who was introduced to CS via a serious studying of SICP. [0] https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html#%_sec_3.5 https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.htm... [1] https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-27.html#%_sec_4.2 https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-27.htm...
- crntaylor 13y agoSICP has something to do with square roots in the first chapter, although I don't think they do this particular refactoring. I first saw it (or something like it) in John Hughes' Why Functional Programming Matters. Which, by the way, is an excellent paper and totally worth reading. http://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pdf http://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pd...