From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: Problem whit with code evaluation Date: Thu, 19 Aug 2010 09:38:48 -0400 Message-ID: <8739uabu3b.fsf@stats.ox.ac.uk> References: <15801.1282194341@gamaville.dokosmarshall.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=35883 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Om5KY-0001B1-Ps for emacs-orgmode@gnu.org; Thu, 19 Aug 2010 09:38:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Om5KW-0004Wb-TO for emacs-orgmode@gnu.org; Thu, 19 Aug 2010 09:38:54 -0400 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:49702) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Om5KW-0004W0-Mi for emacs-orgmode@gnu.org; Thu, 19 Aug 2010 09:38:52 -0400 In-Reply-To: <15801.1282194341@gamaville.dokosmarshall.org> (Nick Dokos's message of "Thu, 19 Aug 2010 01:05:41 -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: nicholas.dokos@hp.com Cc: "Blanchette, Marco" , "emacs-orgmode@gnu.org" Nick Dokos writes: > Blanchette, Marco wrote: > >> Hmm... Thanks Dan. >> >> Do we have a different version of org-mode? I just pasted your code in emacs >> and try to execute it with M-x org-babel-execute-buffer RET without success. >> >> The emacs-lisp code works but the python and the R crashes with the >> following errors taken from the *Org-Babel Error* Output buffer >> >> Traceback (most recent call last): >> File "", line 5, in >> File "", line 3, in main >> NameError: global name 'x' is not defined >> Error in main() : object 'x' not found >> >> On 8/18/10 9:37 PM, "Dan Davison" wrote: >> >> > * The python example >> > #+source: square(x) >> > #+begin_src python >> > return x*x >> > #+end_src >> > >> > #+call: square(x=6) >> > >> > #+results: square(x=6) >> > : 36 >> > > > I think that's because the first source block cannot be evaluated: it > only makes sense when it is #+called. If you place the cursor in that > first source block and press C-c C-c, you get exactly the same error. If > you do the same on the #+call, it works. Since org-babel-execute-buffer > just steps through the buffer and executes every source block, it's not > too surprising that you get those errors. > > So I guess the question is whether org-babel-execute-buffer should be > smarter about which source blocks to execute. [By the way, lob/call lines were not exporting results correctly in any case; I've just pushed a fix.] Nick is right. So first a couple of workarounds: 1. For export, you can use ':exports none' or ':exports code' on the function blocks which cannot be executed on their own. 2. You can supply default arguments to function blocks, which permits them to be executed: #+source: square(x=0) But (1) doesn't solve the `org-babel-execute-buffer' issue, and (2) isn't a nice solution. I've pasted a version of your examples below which exports without error using workaround (1). It requires a fresh pull of Org from the git repo. So what is a good solution here? I may be missing an existing solution but two that come to mind are 1. Extend the existing :eval header arg, introducing a new value, say ':eval called' or ':eval passive' that says that while the block may not be executed itself, it may be called as a function. 2. Demand that such blocks use the keyword #+function: as opposed to #+source or #+srcname. I'm initially attracted to (2). Dan --8<---------------cut here---------------start------------->8--- #+babel: :exports both Examples take from [[http://orgmode.org/worg/org-contrib/babel/intro.php#sec-7]] * The python example #+source: square(x) #+begin_src python :exports code return x*x #+end_src #+call: square(x=6) * The elisp example of the fibonacci series using a table as argument #+tblname: fibonacci-inputs | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | | 2 | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | #+srcname: fibonacci-seq(fib-inputs=fibonacci-inputs) #+begin_src emacs-lisp :exports both (defun fibonacci (n) (if (or (= n 0) (= n 1)) n (+ (fibonacci (- n 1)) (fibonacci (- n 2))))) (mapcar (lambda (row) (mapcar #'fibonacci row)) fib-inputs) #+end_src * Then my own trial in R #+srcname: test(x, y) #+begin_src R :exports code p <- x*y #+end_src #+call: test(x=4, y=9) text inbetween to force line break. #+lob: test(x=3, y=8) --8<---------------cut here---------------end--------------->8--- > > Nick > > _______________________________________________ > 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