4. Define the function (none-diff? lst num) where lst is a list of numbers and num is a number. none-diff? returns #t (i.e. true) if every number in lst is even if num is even or odd if num is odd. For instance; (none-diff? ‘(6 2 4) 3) is #f (i.e. false) since 3 is odd and not even one number in lst is, and (none-diff? ‘(1 3 5) 9) is #t, since no element of lst is not odd, as 9 is.
(define none-diff?
(lambda (lst num)
(define fold
Copyright By PowCoder代写 加微信 powcoder
(lambda (fn lst)
开t kgmucnticretamt.fi
(if (even? num)
(fold and (map even? lst))
(fold and (map odd? lst))
(if (null? (cdr lst)) (car lst)
(fn (car lst) (fold fn (cdr lst))) ✗
atmt.X-t.dineactlzjht3.ir
5. Define the function (commutative? lst funclst) where lst is a list of data and func is a list of binary functions. commutative? applies each function in the list to each two adjacent values in lst in one order, then the other. If the resulting value is the same for all tests, commutative? appends #t to a list or #f otherwise. For instance; (commutative? ‘(1 2 3 4) (list + *)) should return the list
“(#t #t)”, however (commutative? ‘(1 2 3 4) (list + -)) should return the list “(#t #f)”.
(define commutative? (lambda (vallst fnlst)
(if (null? fnlst) ‘()
(cons (and (appPairs vallst (car fnlst))) (commutative? vallst (cdr fnlst) ))
(define appPairs
(lambda (vallist fn)
(if (null? (cdr vallst) #t
(if (null? (cddr vallst)) #t
(and (= (fn (car lst) (cadr lst)) (fn (cadr lst) (car lst))) (appPairs (cdr vallst) fn) ) )) ))
6. Define the function (computable? lst) where lst is a list of functions and data. computable? should check if the first element of lst is a function and every other element is either data, or a computable? list and if so, it should return #t, else #f. For instance: (computable? (list + 1 2)) should return #t and (computable? (list – (list + 9 8) 4 (list / 1 ) 9) ) should return #t, however (computable? (list 1 2 4) ) and (computable? (list + (list – * 3) 9) ) should both return #f. You do not need to compute the functions or check if the data is an appropriate number of arguments. You only need to verify the format.
(define computable? (lambda (lst)
(if (null? lst) ‘()
(if (and (procedure? (car lst)) (not (null? (cddr lst))) (map
(cdr lst) )
(lambda (x) (if (list? x) (computable x)
(or (symbol? x) (number? x)) )
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com