Hi,
Is it possible to have a dependency hierarchy of source blocks?
i.e.: in C, if you use libA from a compilation unit and that
library needs libB, you don't need to include it in main.c
-> main.c
#include "libB.h"
-> libB.c
#include "libA.h"
you don't need to:
-> main.c
#include "libB.h"
#include "libA.h"
because library headers are closed under inclusion.
I haven't succeeded in doing the same in org-mode. Even after
populating org-babel-library-of-babel.
Using #+call just doesn't work. Using :var is better, evaluates
all, but there appears to lack session support, it doesn't check
for cycles and it feels a little hacky
With #+call I need to do it like this:
#+name: libA
#+begin_src scheme :results none
(define hi "hello")
#+end_src
#+name: libB
#+begin_src scheme :results none
(define greetings (string-append hi ", " "to all the people!"))
#+end_src
here is my "main" I need to C-c C-c in each #+call line and
write the :session that the code block uses in each one, and do
it in the correct order. If I C-c C-c in libB first it won't
eval because 'hi' is not defined.
#+call: libB[:session example]
#+call: libA[:session example]
#+begin_src scheme :session example :results output
(display greetings)
#+end_src
source blocks can be #+call(ed) but aren't closed under #+call
(a source block can be called but then the callee won't)
instead I would like to :
#+name: libA
#+begin_src scheme :results none
(define hi "hello")
#+end_src
#+call: libA
#+name: libB
#+begin_src scheme :results none
(define greetings (string-append hi ", " "to all the people!"))
#+end_src
#+call: libB
#+begin_src scheme :session example :results output
(display greetings)
#+end_src
- there shouldn't be needed to C-c C-c in the #+call line,
evaluating the source block alone should suffice.
- there shouldn't be a need to write the :session
- it should use the session of the user evaled block, unless
specified otherwise
In the other hand, using :var with a dummy variable:
#+name: libA
#+begin_src scheme :results none
(define hi "hello")
#+end_src
#+name: libB
#+begin_src scheme :results none :var _=libA
(define greetings (string-append hi ", " "to all the people!"))
#+end_src
#+HEADER: :var _=libB
#+begin_src scheme :session example :results output
(display greetings)
#+end_src
It evals libA then libB and finally the (display greetings)
code.
But it fails, because the :session example is ignored. Even if I
add a :session example to every source block (which would be
really bad, sessión must be decided by the consumer) it doesn't
work. I think that is because :var expects a value, so it just
opens a new session to evaluate code every time.
Besides if there are any dependency cycles, it just fails with:
Lisp nesting exceeds ‘max-lisp-eval-depth’
So if I'm right and there is not an implemented way to do this,
how can we do it? Adding session support for :var? constructing
a DAG of #+calls and then evaluating in order? maybe using a new
header?
COD.