[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Unit conversions and symbolic mathematics with Babel
From: |
Alan Schmitt |
Subject: |
Re: [O] Unit conversions and symbolic mathematics with Babel |
Date: |
Wed, 03 Sep 2014 09:19:26 +0200 |
User-agent: |
Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.3 (darwin) |
On 2014-09-03 08:54, address@hidden (H. Dieter Wilhelm) writes:
> But what is missing is to assign variables within a source block
>
>
> #+BEGIN_SRC calc :var L1 = "5 mm"
> L2 := cvun( L1, m)
> #+END_SRC
>
>
> Unfortunately this is not working. Do you have an idea how to
> implement this?
It seems that you could use block chaining. Here is an extract of some
code I use to compute stats for my book keeping:
#+name: monthly_average
#+begin_src emacs-lisp :var starty=2014 :var startm=3 :var amount=100
(let* ((tm (decode-time))
(cmonth (nth 4 tm))
(cyear (nth 5 tm))
(nbmonths (+ (* 12 (- cyear starty)) (- cmonth startm))))
(calc-eval "round($ / $$, 2)" nil amount nbmonths))
#+end_src
#+name: ledger_average
#+begin_src emacs-lisp :var b="Quotidien" :var sy=2014 :var sm=3 :var
sd="2014-03-01" :var p="Expenses:"
(let* ((per (format "from %d-%d-01 to this month" sy sm))
(a (org-sbe call_ledger (bucket (eval b)) (prefix (eval p)) (period
(eval per)))))
(org-sbe monthly_average (amount (eval a)) (starty (eval sy)) (startm (eval
sm))))
#+end_src
The last line of the second block calls the first block to do its
computation. The first block does not have to be in emacs-lisp, but
I don't know calc well enough to do it directly in calc.
Best,
Alan
--
OpenPGP Key ID : 040D0A3B4ED2E5C7
signature.asc
Description: PGP signature