[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Orgmode] Re: question about chaining function calls in org-babel
From: |
Dan Davison |
Subject: |
[Orgmode] Re: question about chaining function calls in org-babel |
Date: |
Wed, 04 Aug 2010 22:08:36 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
Hi I.S.,
Inquisitive Scientist <address@hidden> writes:
> Dear Experts,
>
> I think org-babel is awesome but I'm having some trouble chaining
> together multiple function calls.
>
> Specifically, I would like to do something like the following
> #+tblname: fancier
> | mean |
> |--------|
> | #ERROR |
> #+TBLFM: @2$1='(sbe "python-mean" (x (sbe "tbl-example-data" (seed 4) (size
> (sbe "square" (x 4))))))
> but it doesn't work.
OK, first off, personally I would use a dedicated src block to construct
the complex chain of calls. So your most complex example can be done with
#+tblname:
| mean |
|---------------|
| 7.52617964952 |
#+TBLFM: @2$1='(sbe "chain")
#+srcname: chain
#+begin_src emacs-lisp :var x=python-mean(x=tbl-example-data(seed=4,
size=square(x=4)))
x
#+end_src
[...]
> Try to do something even fancier and it doesn't work:
> #+tblname: fancier
> | mean |
> |------|
> | |
> #+TBLFM: @2$1='(sbe "python-mean" (x
> "tbl-example-data(seed=4,size=square(4))"))
This one works if we name the argument to square:
#+tblname: fancier
| mean |
|---------------|
| 7.52617964952 |
#+TBLFM: @2$1='(sbe "python-mean" (x
"tbl-example-data(seed=4,size=square(x=4))"))
Beyond that, your examples feature one sbe nested inside another. For
example
| mean |
|--------|
| #ERROR |
#+TBLFM: @2$1='(sbe "python-mean" (x (sbe "tbl-example-data" (seed 4) (size
16))))
I *believe* that there is no expectation for this to work, because sbe
is an elisp function (well, a macro), and not a source block. In other
words, the first sbe is expecting a source block reference, whereas what
it gets is this lisp form:
(sbe "tbl-example-data" (seed 4) (size 16))
My guess is that sbe does not undertake to evaluate a lisp form
occurring in that context. But I admit that I still find these
complicated macros more or less incomprehensible, so we could do with
Eric's input here.
As for debugging, all I know of is to place print statements inside the
macro.
The docstring says
,----
| (defmacro sbe (source-block &rest variables)
| "Return the results of calling SOURCE-BLOCK with VARIABLES.
| Each element of VARIABLES should be a two
| element list, whose first element is the name of the variable and
| second element is a string of its value.
| [...]
| NOTE: by default string variable names are interpreted as
| references to source-code blocks. To force interpretation of a
| cell's value as a string,
| [...]
`----
Dan
>
> Try to do something even fancier with sbe and it doesn't work.
> #+tblname: fancier
> | mean |
> |------|
> | |
> #+TBLFM: @2$1='(sbe "python-mean" (x (sbe "tbl-example-data" (seed 4) (size
> square(4)))))
>
> One more try:
> #+tblname: fancier
> | mean |
> |--------|
> | #ERROR |
> #+TBLFM: @2$1='(sbe "python-mean" (x (sbe "tbl-example-data" (seed 4) (size
> (sbe "square" (x 4))))))
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> address@hidden
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode