sum & lsum



-----maxima-bounces at math.utexas.edu wrote: -----

>Let?f(i):=??i^2
>
>then?sum(f,?1,?10) or??integrate(f,?1,10) is??clear.

An alternative to the varied methods used by lsum, sum, makelist, and
others for evaluation is to build a Maxima lambda form and apply it;
example:

;; Not a serious proposal--this function lacks error checking.

(defmspec $makelist (x)
  (pop x)
  (let* ((e (pop x))
  (k (pop x))
  (lo (meval (pop x)))
  (hi)
  (acc nil) (n) (f `((lambda) ((mlist) ,k) ,e)))

    (cond (x
    (setq hi (meval (pop x)))
    (setq n (sub hi lo))
    (if (not (integerp n)) (merror "ouch"))
    (while (>= n 0)
      (push (mfuncall f (add lo n)) acc)
      (decf n))
    (push '(mlist) acc))

   ((or ($listp lo) ($setp lo))
    (setq lo (cdr lo))
    (dolist (lk lo)
      (push (mfuncall f lk) acc))
    (setq acc (nreverse acc))
    (push '(mlist) acc))

   (t (merror "growl")))))

Barton