From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: question about chaining function calls in org-babel Date: Wed, 04 Aug 2010 22:08:36 -0400 Message-ID: <87tyn9erq3.fsf@stats.ox.ac.uk> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=46959 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ogpsw-0004Ry-GE for emacs-orgmode@gnu.org; Wed, 04 Aug 2010 22:08:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Ogpsu-0007zY-Sb for emacs-orgmode@gnu.org; Wed, 04 Aug 2010 22:08:42 -0400 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:60697) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Ogpsu-0007zE-JU for emacs-orgmode@gnu.org; Wed, 04 Aug 2010 22:08:40 -0400 In-Reply-To: (Inquisitive Scientist's message of "Wed, 4 Aug 2010 20:19:16 -0400") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Inquisitive Scientist Cc: emacs-orgmode@gnu.org Hi I.S., Inquisitive Scientist 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. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode