Consider the following definition of the gcd_list function that, when completed, will compute the greatest common divisor of a list of numbers:

1.  var gcd_list = function (ns) {
2.      var gcd_list_cps = function (ns,k) {
3.           if ( ????? ) {
4.               return "Cannot ask for the gcd of the empty list";
5.           } else if ( ????? ) {
6.               return 1;
7.           } else if ( ????? ) {
8.               return k(fp.hd(ns));
9.           } else {
10.              return gcd_list_cps( fp.tl(ns),
11.                                   function (x) {
12.                                       return k(gcd( ????? ));
13.                                   });
14.          }
15.      };
16.      return gcd_list_cps(ns,function (x) { return x; });
17. };

The function above uses continuation-passing style. What should the question marks on line 7 be replaced with to ensure the function behaves this way?

fp.isNull(fp.tl(ns))
  • fp.isEq(fp.hd(ns),1)
  • fp.hd(ns), x
  • fp.isNull(ns)

Note that, in this case (line 8), we call the continuation for the first time to initiate the computation.

Recall that the only argument of the continuation is the result of the parts of the computation that have been completed so far. In this case, no computations have been completed yet.

The specific argument given to the continuation on the call on line 8 gives you a hint about the ordering of the computations and the answer to this question.