1

I have this source block and table in an org-file.

#+NAME: testlisp #+begin_src elisp :var testvariable="default string" (progn (message testvariable) ;use the variable in some way "return string" ) #+END_SRC #+NAME: testtable | return string | #+TBLFM: $1='(org-sbe "testlisp" ("testvariable" "1")) 

I tried several ways to call the source block with sbe and overwrite the content of testvariable. But it always produces #ERROR for me when I pass a string. Puzzling to me, it does not produce error when I pass a number (also when put in quotes) but the variable content is still the default value.

How can I pass a static string as a variable to the block with an org-sbe call from TBLFM?

1 Answer 1

1

Try this:

#+NAME: testlisp #+begin_src elisp :var testvariable="default string" (progn (if (string= testvariable "1") "yes" "no") ) #+END_SRC #+RESULTS: testlisp : no #+NAME: testtable | yes | #+TBLFM: $1='(org-sbe "testlisp" (testvariable $"1")) 

org-sbe is a macro and a rather peculiar one at that: read its doc string with C-h f org-sbe very carefully and be ready to experiment (you might want to submit a bug to the Org mode mailing list, asking for the doc string of org-sbe to be improved). In particular, it says:

By default, string variable names are interpreted as references to source-code blocks

so you should not enclose the variable name in quotes; and it also says:

"$" will also force interpreting string value literally: $"value" will refer to a string, not a source block name.

so you have to say $"1".

2
  • Another case of "should have read the docs more carefully"… thanks for the patience to still point out the solution so kindly :) Commented Sep 21 at 21:30
  • I think this is one case where having read the doc once or twice is still not enough - hence the suggestion to open a bug report. Commented Sep 22 at 1:37

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.