eminent101 · 2022-08-01 21:16
I have this table -
| Formula | Value |
|------------------+-------|
| (+ 10 20) | |
| (* 10 20) | |
| (+ (* 10 20) 30) | |
Is there someway (`#+TBLFM:` line or something) to automatically populate Value column with results of formulas in Formula column? I want to automatically fill the table so that it looks like so -
| Formula | Value |
|------------------+-------|
| (+ 10 20) | 30 |
| (* 10 20) | 200 |
| (+ (* 10 20) 30) | 900 |
whudwl · 2022-08-01 21:30
You can define this function:
(defun my-eval-string (string)
"Evaluate elisp code stored in a string."
(eval (car (read-from-string string))))
Then use this
#+TBLFM: $2='(my-eval-string $1)
Maneatsdog · 2022-08-01 21:34
Use #+tblfm:$3='(calc-eval $2) something like this. Refer to the calc manual and this:
https://orgmode.org/manual/Advanced-features.html
ffellirm · 2022-08-03 14:50
For elisp formula, you could do this:
| Formula | Value |
|------------------+-------|
| (+ 10 20) | 30 |
| (* 10 20) | 200 |
| (+ (* 10 20) 30) | 230 |
#+TBLFM: $2='(eval $1);L
If you want formula in algebraic calc notation, you could do this:
| Formula | Value |
|------------+-------|
| 10 + 20 | 30 |
| 10 * 20 | 200 |
| 10*20 + 30 | 230 |
#+TBLFM: $2=$1
You can also use calc to do things like:
| var | value | progressive substitution |
|-----+-------+--------------------------|
| | | a * b + c |
| a | 10 | 10 b + c |
| b | 20 | 10 20 + c |
| c | 30 | 200 + 30 |
| | | 230 |
#+TBLFM: @3$3..@6$3=subst(@-1,$1,$2)