[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Limitation with lambda

You ask:

    For example, how would someone write a function generator that generates the
    sum of all squares or cubes or fourths, etc., based on an exponent?

How 'bout:

(define sum-of-powers 
  (lambda (power)
    (lambda (n)
      (sum-of (lambda (i)
                (expt i power))

(define sum-of
  (lambda (termfun nterms)
    (if (= nterms 0)
        (+ (termfun nterms) 
	   (sum-of termfun (- nterms 1))))))

;;; e.g.

((sum-of-powers 3) 5)
;Value: 225

Does this solve your problem?  If not, call me on the phone and I will
try to debug you.  My phone is (617) 253-5874.