From: c4t0 <c4t0@riseup.net>
To: emacs-orgmode@gnu.org
Subject: source blocks DAG evaluation
Date: Sun, 21 Mar 2021 23:00:46 -0300 [thread overview]
Message-ID: <87k0q0ymk1.fsf@riseup.net> (raw)
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.
next reply other threads:[~2021-03-22 2:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-22 2:00 c4t0 [this message]
2021-03-22 2:44 ` source blocks DAG evaluation Thomas S. Dye
2021-03-22 13:41 ` c4t0
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k0q0ymk1.fsf@riseup.net \
--to=c4t0@riseup.net \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).