Question

Can anyone give examples of using the sbe function in ob-table.el? I must be missing something because I haven't been able to get it to work with straight-up elisp.

#+name: add1(x=1) :results silent
#+begin_src python
return x + 1
#+end_src

This works:

| 1 | 2 | 3 | 4 |
#+TBLFM: @1$4='(sbe add1 (x $3))

But this does not:

#+begin_src emacs-lisp
(sbe add1 (x 2))
#+end_src

error: Wrong type argument: sequencep, 2

Changing 2 to a list just aggravates it further:

#+begin_src emacs-lisp
(sbe add1 (x (list 2))
#+end_src

error: Wrong type argument: buffer-or-string-p, 2

Was it helpful?

Solution

If I'm understanding your question correctly you're trying to use your named source block outside of tables to call for results.

First of all, your :results silent belongs on the #+begin_src line and not the #+name (only relevant if you ever evaluate that block directly). I'm switching to emacs-lisp from python simply because I don't have python on this machine so can't evaluate the block otherwise, the function remains equivalent.

#+name: add1(x=1)
#+begin_src emacs-lisp :results silent
  (+ x 1)
#+end_src

In Org Tables the proper command is the one you used: #+tblfm: @1$4='(sbe add1 (x $3))

When using code blocks outside of tables you have to use #+CALL: instead (see Evaluating Code Blocks).

For example:

#+CALL: add1(x=2)

#+RESULTS: add1(x=2)
: 3

#+CALL: add1(4)

#+RESULTS: add1(4)
: 5

#+call: add1(add1(2))

#+RESULTS: add1(add1(2)
: 4

Edit (Adding in answer from comment):

If you simply want to clean up your formulas and be better able to read through them to make changes, the formula editor C-c ' will let you see them more clearly as well as highlight cell references to ensure you're selecting the right regions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top