http-redirectemacsorg-modeorg-babel

Redirect sereral functions outputs to results


When work in source code of python,

#+BEGIN_SRC python :session test :results output
print('testing1')
print('testing2')
#+END_SRC

#+RESULTS:
: testing1
: testing2

Set :results as output and then get 2 results,

Try elisp

#+begin_src emacs-lisp  :results output
(+ 21 35 12 7)
(* 25 4 12)
#+end_src

#+RESULTS:

How could get elisp codes redirect outputs to results


Solution

  • Those source blocks have different behaviour -- your python code prints to stdout while the elisp just evaluates expressions.

    An equivalent elisp block might be

    #+BEGIN_SRC elisp :results output
    (princ (+ 21 35 12 7))
    (print (* 25 4 12))
    #+END_SRC
    
    #+RESULTS:
    : 75
    : 1200
    

    If you want to capture the results of both expressions, you could wrap them in a list,

    #+BEGIN_SRC elisp :results value verbatim
    (list (+ 1 1) (* 2 2))
    #+END_SRC
    
    #+RESULTS:
    : (2 4)
    
    #+BEGIN_SRC python :session test :results value verbatim
    1 + 1, 2 + 2
    #+END_SRC
    
    #+RESULTS:
    : (2, 4)