Is it possible to have, in the same org file, two code blocks in the same language that are run in different interpreters by specifying different options at the top of the code block?
The original question has been modified to concern running multiple versions of an executable, and not simply independent interpreters.
find-library I inspected the source of
ob-ruby, which includes this code:
(defvar org-babel-ruby-command "ruby" "Name of command to use for executing ruby code.")
I have seen references elsewhere for python using
org-babel-python-command, so it exists in some other languages, check the appropriate
ob-$lang support to see.
This allows the following to work:
#+begin_src emacs-lisp :results none (setq org-babel-python-command "python3") #+end_src #+begin_src python :results output import sys print(sys.version) #+end_src #+RESULTS: : 3.4.0 (default, Apr 11 2014, 13:05:11) : [GCC 4.8.2] #+begin_src emacs-lisp :results none (setq org-babel-python-command "python2") #+end_src #+begin_src python :results output import sys print(sys.version) #+end_src #+RESULTS: : 2.7.6 (default, Mar 22 2014, 22:59:56) : [GCC 4.8.2]
This could be combined with
:session python3 and
:session python2 to avoid calling elisp before each block. It does seem like there should be a simpler way to do this though.
I believe by default each block runs in an independent interpreter even if it's the same language. The behavior may be different for some languages. For instance, I'm not sure that emacs-lisp blocks support the session property.
#+BEGIN_SRC ruby a = "foo" #+END_SRC #+RESULTS: : foo #+BEGIN_SRC ruby a ||= "bar" #+END_SRC #+RESULTS: : bar #+BEGIN_SRC ruby :session foo a ||= "session foo" #+END_SRC #+RESULTS: : session foo #+BEGIN_SRC ruby :session foo a += " with bar" #+END_SRC #+RESULTS: : session foo with bar
The first two blocks use independent interpreters, but the third and fourth block share a session
:foo, so that they evaluate in the same interpreter.
The standard JS interpreter is
node, as defined in the variable
org-babel-js-cmd. To run a specific code block through a different interpreter pass the
:cmd option as in the following example.