Lecture 2A | MIT 6.001 Structure and Interpretation, 1986
Why Stack Overflow recommends it
Stack Overflow users link it when working through SICP exercises and need the lecture's explanation of higher-order functions, fixed points and average-damp, often while porting the examples to PHP or Scala.
Recommended by 1 people across 1 different months, 2010 to 2014.
What it is
Lecture 2A of the classic MIT 6.001 course from 1986, covering higher-order procedures in Scheme. Gerald Jay Sussman teaches procedures that take and return other procedures, with examples such as sums, fixed points, square roots and average damping.
What people said
Recommends Karoly Horvath · 2013-09 · Stack Overflow · on “What's wrong with this Newton's Method implementation in Scheme?”
There are probably several problems, I found these: (newtons-method2 (f next (- n 1)) -> (f next (- n 1)) this is evaluating f with parameters next and n-1 , but you want to pass all 3 as parameters: (newtons-method2 f next (- n 1)) Be careful with parentheses, they fundamentally alter what the program does. Just because they balance, doesn't mean the program does anything meaningful. 0.5 for delta is a huge value, and likely will cause problems when calculating the approximations. how about 0.00001? Learn to do proper indentation, so arguments line up below each other. Again, this is related to parentheses. It's almost impossible to read your code. Also, here's a nice implementation with ex
Cites Bill the Lizard · 2010-12 · Stack Overflow · on “Testing before you code”
Lately I've been thinking that this aspect of TDD is the same as the concept of programming by "wishful thinking" that I've read about in Structure and Interpretation of Computer Programs [LINK] . For example, in lecture 2A [this video] of the MIT course taught by the authors, the following example is given for computing square roots as a function of fixed points: (define (sqrt x) (fixed-point (lambda (y) (average (/ x y) y)) 1)) This is shown before the fixed-point procedure is defined. You don't really need the definition to understand that you can use a fixed-point procedure to compute square roots. Once you see how you're going to use it, you can go about defining it. (define (fixed-point f s
Cites user4035 · 2013-06 · Stack Overflow · on “Can't implement SICP AVERAGE-DAMP in PHP”
I was watching SICP 2a lecture: [this video] around 32:30 Gerald Jay Sussman introduces AVERAGE-DAMP procedure. It takes a procedure and returns a procedure, returning an average of it's argument and the first procedure, applied to the argument. In Scheme it looks like this: (define average-damp (lambda (f) (lambda (x) (average (f x) x)))) I decided to rewrite it in PHP: function average_damp($f) { return function ($x) { $y = $f($x);//here comes the error - $f undefined return ($x + $y) / 2; }; } And then tried with a simple procedure: function div_by2($x) { return $x / 2; } $fun = average_damp("div_by2"); $fun(2); This stuff should return an average between 2 and (2/2) = (2 + 1)/2 = 3/2. But $f
Cites runners3431 · 2014-08 · Stack Overflow · on “What is fixed point?”
I'm rewatching some of the earlier lectures on SICP [LINK] . The notion of a fixed-point is a bit confusing to me. The fixed-point procedure: should I be thinking about it this way, "it's the way to find a fixed-point of a given function." So given f(2) = 2 ? Also why is it stated in this lecture [this video] , that a new function y that maps to x / y is a fixed point?
Cites blue-sky · 2014-08 · Stack Overflow · on “How to invoke a function which takes function parameters?”
Watching the SICP course [this video] I have converted some of the lisp code to Scala : def sumInt(a: Int, b: Int): Int = { //> sumInt: (a: Int, b: Int)Int if(a > b) 0 else a + sumInt(1 + a, b) } sumInt(3, 5) //> res0: Int = 12 def sumSquares(a: Int, b: Int): Int = { //> sumSquares: (a: Int, b: Int)Int if(a > b) 0 else (a * a) + sumSquares(1 + a, b) } sumSquares(2, 3) //> res1: Int = 13 To make a more generic function which accepts the functions as parameters to compute the squares instead of coding them within the function I've added : def sum(term: Int => Int, a: Int, next: Int => Int, b: Int): Int = { if(a > b) 0 else { val toAdd1 = term(a) val toAdd2 = toAdd1 + sum(term, next(a), next, b) toA