Why are higher-order functions considered powerful abstraction mechanisms?

Correct answer: They allow the expression of general programming patterns as concepts by accepting functions as arguments or returning them as values.

Explanation

This question gets to the heart of Section 1.3, explaining that the ability to treat functions as data (passing them to and returning them from other functions) allows programmers to abstract and name common computational patterns.

Other questions

Question 1

What are the three fundamental mechanisms every powerful programming language has for combining simple ideas to form more complex ones?

Question 2

What is the value of the JavaScript expression `(3 * 5) + (10 - 6);`?

Question 3

What does the JavaScript interpreter use to keep track of name-object associations, such as a value assigned to a name using `const`?

Question 4

What is the two-step procedure that the interpreter follows to evaluate an operator combination?

Question 5

What is the simplest form of a function declaration shown in the text?

Question 6

According to the substitution model, what is the first step in evaluating the application `f(5)` where `f` is declared as `function f(a) { return sum_of_squares(a + 1, a * 2); }`?

Question 7

What is the key difference between applicative-order evaluation and normal-order evaluation?

Question 8

What is the general form of a conditional expression in JavaScript as described in the text?

Question 9

In the logical composition operation `expression1 && expression2`, what is this syntactic form assumed to be syntactic sugar for?

Question 10

What is the fundamental difference between declarative knowledge and imperative knowledge in the context of computer science, as illustrated by the square root example?

Question 11

In Newton's method for finding the square root of a number x, if you have a guess y, how do you get a better guess?

Question 12

What is the value of `f(5)` for the function `function f(a) { return sum_of_squares(a + 1, a * 2); }`, where `sum_of_squares(x, y)` returns `square(x) + square(y)` and `square(x)` returns `x * x`?

Question 13

In the context of the `sqrt` example, what is the primary benefit of decomposing the problem into separate functions like `is_good_enough` and `improve`?

Question 14

What is the term for a name within a function declaration, such as a parameter, that doesn't matter what it is called as long as it's used consistently?

Question 15

What is the discipline called where free names in a function are taken to refer to bindings made by enclosing function declarations?

Question 16

What is the difference between a recursive process and an iterative process, as described with the factorial examples?

Question 17

What property must a language implementation have to execute an iterative process described by a recursive function in constant space?

Question 18

In the tree-recursive process for computing Fibonacci numbers, such as `fib(5)`, what resource grows exponentially with the input `n`?

Question 19

What is the value of `A(2, 4)` for the Ackermann's function defined in Exercise 1.10?

Question 20

If a process requires R(n) resources for a problem of size n, what does it mean for R(n) to have an order of growth of Theta(f(n))?

Question 21

What is the order of growth in terms of space for the iterative factorial process?

Question 22

By using successive squaring, the `fast_expt` function reduces the number of steps for exponentiation from Theta(n) to what order of growth?

Question 23

How many multiplications are required by `fast_expt` to compute an exponentiation for n = 1000?

Question 24

Euclid's Algorithm for finding the greatest common divisor (GCD) of two integers a and b is based on which recursive equation?

Question 25

According to Lamé's Theorem, if Euclid's Algorithm requires k steps to compute the GCD of a pair of numbers, the smaller number in the pair must be greater than or equal to what?

Question 26

The primality test based on Fermat's Little Theorem has what order of growth?

Question 27

What is the defining characteristic of a probabilistic algorithm like the Fermat test?

Question 28

What is a Carmichael number?

Question 30

The higher-order function `sum` takes four arguments. What are they?

Question 31

Using the `integral` function defined as `integral(cube, 0, 1, 0.01)`, where `cube` is the cubing function, what is the approximate value computed?

Question 32

What syntactic form is introduced in Section 1.3.2 to create functions without needing to declare them with a name?

Question 33

What is the value of the expression `((x, y, z) => x + y + square(z))(1, 2, 3);`, assuming `square(z)` returns `z * z`?

Question 34

In the half-interval method for finding a root of a function f, if you have an interval `(a, b)` where `f(a) < 0 < f(b)`, and the midpoint `x` has `f(x) > 0`, what is the new interval for the search?

Question 35

What is a fixed point of a function f?

Question 36

What is the approximate fixed point of the cosine function, starting with an initial guess of 1?

Question 37

The technique of `average damping` is introduced to aid the convergence of fixed-point searches. Given a function `f`, what function does average damping consider instead?

Question 38

What does the `average_damp` function return as its value?

Question 39

How is Newton's method formulated in terms of finding a fixed point?

Question 40

What are the 'rights and privileges' that define an element having first-class status in a programming language?

Question 41

What is the value returned by `double(double(double))(inc)(5);` as defined in Exercise 1.41, where `inc` adds 1 and `double(f)` applies `f` twice?

Question 42

Using the `compose` function from Exercise 1.42, what is the result of `compose(square, inc)(6);`?

Question 43

What is the result of `repeated(square, 2)(5);` as defined in Exercise 1.43, where `repeated(f, n)` returns the nth repeated application of f?

Question 44

What is the value of the expression `1 - 5 / 2 * 4 + 3;` considering JavaScript's operator precedence and associativity?

Question 45

In the `count_change` example, the number of ways to make change for amount `a` using `n` kinds of coins is expressed recursively. What are the two components that are added together?

Question 46

In Exercise 1.5, Ben Bitdiddle tests whether an interpreter uses applicative-order or normal-order evaluation with `test(0, p())`, where `p()` is a non-terminating function. What will he observe with an applicative-order interpreter?

Question 47

Alyssa P. Hacker rewrites the `sqrt_iter` function using a function `conditional` instead of the `? :` syntax. Why does her new implementation fail to compute square roots?

Question 48

What does the function `sum(cube, a, inc, b)` from Section 1.3.1 compute, where `cube` cubes a number and `inc` increments by 1?

Question 49

In the function `f_3(x, y)` in Section 1.3.2, which uses `const` to declare local names `a` and `b`, what is the scope of these names?

Question 50

The golden ratio phi (approximately 1.618) is a fixed point of which transformation `x -> ...`?