Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!bu-cs!encore!mist From: pierson@mist (Dan Pierson) Newsgroups: comp.emacs Subject: Summing Columns Summary: elisp code Keywords: GNU Emacs, source Message-ID: <5158@xenna.Encore.COM> Date: 20 Mar 89 22:27:38 GMT Sender: news@Encore.COM Reply-To: pierson@mist (Dan Pierson) Organization: Encore Computer Corp Lines: 20 Several months ago someone asked for GNU Emacs code to sum a column of numbers. I needed such a thing today, so here it is: (defun sum-column (start end) "Display and return the sum of the integers in the rectangle delimited by START (point) and END (mark)." (interactive "d\nm") (let* ((str-nums (if (< start end) (extract-rectangle start end) (extract-rectangle end start))) (nums (mapcar '(lambda (x) (string-to-int x)) str-nums)) (sum (apply '+ nums))) (message "%d" sum) sum)) -- dan In real life: Dan Pierson, Encore Computer Corporation, Research UUCP: {talcott,linus,necis,decvax}!encore!pierson Internet: pierson@encore.com