简体   繁体   中英

org-babel sbe syntax

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

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 Cc ' will let you see them more clearly as well as highlight cell references to ensure you're selecting the right regions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM