(define foo (lambda (<symbol>*) <tail wrt foo>))
where <symbol>* is zero or more symbols and an expression is <tail wrt foo> if it is not an application of foo:
<contains no foo applications>
(foo <contains no foo applications>*)
where <contains no foo applications> is an expression which contains no applications of foo,and <contains no foo applications>* is zero or more expressions which contain no applications of foo.
Write a function, tail-definition?, which takes an expression, expr, as an argument, and returns #t if the expression is a <tail definition> and #f otherwise. For example:
> (tail-definition? '(define fact (lambda (x acc) (if (= x 0) acc (fact (- x 1) (* x acc)))))) #t > (tail-definition? '(define fact (lambda (x) (if (= x 0) 1 (* x (fact (- x 1))))))) #f > (tail-definition? '(define member? (lambda (item ls) (and (not (null? ls)) (or (eq? item (car ls)) (member? item (cdr ls))))))) #t >Hint: Divide and conquer. Write helper-functions, tail-wrt? and no-applications-of?. Both take a function name, fname, and an expression, expr, as arguments. tail-wrt? returns #t if expr is tail with respect to fname and #f otherwise. no-applications-of? returns #t if there are no applications of fname in expr, and #f otherwise.
> ((curry-skip 0) 'foo) foo > (((curry-skip 1) 'foo) 'bar) bar > ((((curry-skip 2) 'foo) 'bar) 'baz) baz >
> (iterate-to-fixedpoint (lambda (x) (/ (+ x (/ 2 x)) 2)) (lambda (x y) (< (abs (- x y)) 0.00001)) 1.0) 1.41421 > (iterate-to-fixedpoint (lambda (x) (if (pair? x) (car x) x)) eq? '(((((a b) c) d) e f g) h)) a >
(define clock-tester (lambda () (let ((clock (clock-maker))) (letrec ((loop (lambda (seconds) (if (< seconds 3601) (begin (send clock 'tic!) (loop (add1 seconds))))))) (send clock 'hours! 11) (send clock 'minutes! 3) (send clock 'seconds! 47) (loop 0) (send clock 'display)))))If your clock is working correctly, it should display 00:03:48.