[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Orgmode] Embedded elisp formulas, was: Spreadsheet and weighted mea
From: |
Eric Schulte |
Subject: |
Re: [Orgmode] Embedded elisp formulas, was: Spreadsheet and weighted means |
Date: |
Wed, 01 Oct 2008 12:45:34 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
Carsten Dominik <address@hidden> 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) '(@address@hidden));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