> (cond->if '(cond ((> x y) (- x y)) ((< x y) (- y x)) (else 0))) (if (> x y) (- x y) (if (< x y) (- y x) 0)) >You may assume that every cond expression has an else part.
(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. For example,
* This webpage is located at http://cs.unm.edu/~williams/cs257/homework4s07.html