From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: Embedded elisp formulas, was: Spreadsheet and weighted means Date: Wed, 01 Oct 2008 12:45:34 -0700 Message-ID: <871vz0t7z5.fsf_-_@gmail.com> References: <87wsh7w589.fsf@selenimh.orion.org> <9136F031-BBCD-4A80-A117-6047C5D3F777@uva.nl> <87y718nu0l.fsf@selenimh.orion.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kl7do-0006lS-6r for emacs-orgmode@gnu.org; Wed, 01 Oct 2008 15:45:44 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kl7dl-0006l5-S0 for emacs-orgmode@gnu.org; Wed, 01 Oct 2008 15:45:42 -0400 Received: from [199.232.76.173] (port=46216 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kl7dl-0006l2-J9 for emacs-orgmode@gnu.org; Wed, 01 Oct 2008 15:45:41 -0400 Received: from wf-out-1314.google.com ([209.85.200.168]:41951) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Kl7dl-00017M-4N for emacs-orgmode@gnu.org; Wed, 01 Oct 2008 15:45:41 -0400 Received: by wf-out-1314.google.com with SMTP id 28so709917wfc.24 for ; Wed, 01 Oct 2008 12:45:38 -0700 (PDT) In-Reply-To: (Carsten Dominik's message of "Wed, 1 Oct 2008 21:26:37 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Carsten Dominik Cc: emacs-orgmode@gnu.org Carsten Dominik writes: [...] > Well, you can do this by leaving the formatting to the function > instead of the formula under the table: > > > (defun my-wmean (values weights) > (let ((vsum 0) (wsum 0)) > (while (and values weights) > (setq v (pop values) w (pop weights)) > (unless (equal "" v) > (setq vsum (+ vsum (* (string-to-number w) (string-to-number v))) > wsum (+ wsum (string-to-number w))))) > (if (= vsum 0) "" (format "%.1f" (/ vsum wsum))))) > > > The you could use this as your equation: > > | | Coeff. | 0.2 | 0.5 | 1 | > |-----------+--------+--------+--------+--------| > | Name | | Test 1 | Test 2 | Test 3 | > |-----------+--------+--------+--------+--------| > | Student A | 10.0 | 15 | 12 | 8 | > | Student B | 12.7 | | 16 | 11 | > | Student C | | | | | > #+TBLFM: $2='(my-wmean '($3..$5) '(@1$3..@1$5));E This raises an issue I've been running into recently, If I have a multi-line elisp function (I guess same issue would apply for multi-line shell commands) that I want to use from an org file (for example to compute table columns), is there a way to save and load the function from the org file? I've tried multiline [[elisp: ]] links but they don't work well, maybe something like... [[eval-source]] #+BEGIN_SOURCE elisp #+END_SOURCE Thanks -- Eric