* What is output for org-babel? @ 2009-11-05 11:17 andrea Crotti 2009-11-05 14:26 ` Darlan Cavalcante Moreira 2009-11-08 15:05 ` "Martin G. Skjæveland" 0 siblings, 2 replies; 10+ messages in thread From: andrea Crotti @ 2009-11-05 11:17 UTC (permalink / raw) To: emacs-orgmode I'm with org-mode 6.31a, I was trying to get output in the exported files but I never see the output. So I investigate and for example this #+BEGIN_SRC python import os; os.listdir(os.getcwd()) #+END_SRC doesn't return any output while this #+BEGIN_SRC python "hello" #+END_SRC does and this: #+BEGIN_SRC python return "hello" #+END_SRC Again doesn't. I guess that the returned value is depending also on the language, but in general what's the rule? Another little thing, I have a file with many haskell source blocks. They are separated because they are different answers, but if they are loaded separately they don't work. So is there a way to take all the source code and load it at once? Something like more or less: (append-to-buffer "haskell-buf" (get-code "exercises.org")) ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: What is output for org-babel? 2009-11-05 11:17 What is output for org-babel? andrea Crotti @ 2009-11-05 14:26 ` Darlan Cavalcante Moreira 2009-11-06 12:13 ` andrea Crotti 2009-11-08 20:20 ` Dan Davison 2009-11-08 15:05 ` "Martin G. Skjæveland" 1 sibling, 2 replies; 10+ messages in thread From: Darlan Cavalcante Moreira @ 2009-11-05 14:26 UTC (permalink / raw) To: andrea Crotti; +Cc: emacs-orgmode COmments are inline. At Thu, 5 Nov 2009 11:17:39 +0000 (UTC), andrea Crotti <andrea.crotti.0@gmail.com> wrote: > > I'm with org-mode 6.31a, I was trying to > get output in the exported files but I never see the output. > > So I investigate and for example this > > #+BEGIN_SRC python > import os; os.listdir(os.getcwd()) > #+END_SRC This does not return anything for me either, but #+BEGIN_SRC python import os os.listdir(os.getcwd()) #+END_SRC works as expected. This is strange, since "import os; os.listdir(os.getcwd())" is valid and will work if typed in the python interpreter directly. > > doesn't return any output while this > > #+BEGIN_SRC python > "hello" > #+END_SRC > > does and this: > > #+BEGIN_SRC python > return "hello" > #+END_SRC > Again doesn't. I don't think this is suppose to work. As I understand org-babel send this code to python without any processing but you are not inside a python function. Therefore this is as if you have typed 'return "hello"' in the interpreter and it will result in an error. That's why no output is shown. Change "#+BEGIN_SRC python" to "#+BEGIN_SRC python :results output" and you will see the error. However, if the code is sent to the python interpreter as it is, then it bugs me why "import os; os.listdir(os.getcwd())" didn't work. - Darlan > I guess that the returned value is depending also on the language, > but in general what's the rule? > > Another little thing, I have a file with many haskell source blocks. > They are separated because they are different answers, > but if they are loaded separately they don't work. > So is there a way to take all the source code and load it at once? > > Something like more or less: > (append-to-buffer "haskell-buf" (get-code "exercises.org")) > > > > _______________________________________________ > Emacs-orgmode mailing list > Remember: use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: What is output for org-babel? 2009-11-05 14:26 ` Darlan Cavalcante Moreira @ 2009-11-06 12:13 ` andrea Crotti 2009-11-06 12:17 ` Carsten Dominik 2009-11-06 16:15 ` Thomas S. Dye 2009-11-08 20:20 ` Dan Davison 1 sibling, 2 replies; 10+ messages in thread From: andrea Crotti @ 2009-11-06 12:13 UTC (permalink / raw) To: emacs-orgmode Darlan Cavalcante Moreira <darcamo <at> gmail.com> writes: > > However, if the code is sent to the python interpreter as it is, then it > bugs me > why "import os; os.listdir(os.getcwd())" didn't work. I tried to look at the code of org-babel-python but it's a bit too complicated to understand how my body is manipulated... For the second question I made, it would be even better to have a mechanism that allows to insert logical parts of another buffer in my org-mode file. Something like #+INCLUDE file.hs::fun_def Where fun_def is the definition of a function. programming modes know how to split this kind of things, so also org-mode could now, right? ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Re: What is output for org-babel? 2009-11-06 12:13 ` andrea Crotti @ 2009-11-06 12:17 ` Carsten Dominik 2009-11-06 16:15 ` Thomas S. Dye 1 sibling, 0 replies; 10+ messages in thread From: Carsten Dominik @ 2009-11-06 12:17 UTC (permalink / raw) To: andrea Crotti; +Cc: emacs-orgmode Dear all, please remember to put [babel] into the subject line of messages that discuss features of org-babel. I would like to keep these messages on the list as well, but we should make filtering easy for people who are not interested in these discussions. - Carsten On Nov 6, 2009, at 1:13 PM, andrea Crotti wrote: > Darlan Cavalcante Moreira <darcamo <at> gmail.com> writes: > >> >> However, if the code is sent to the python interpreter as it is, >> then it >> bugs me >> why "import os; os.listdir(os.getcwd())" didn't work. > > I tried to look at the code of org-babel-python > but it's a bit too complicated to understand how my body > is manipulated... > > For the second question I made, it would be even > better to have a mechanism that allows to insert > logical parts of another buffer in my org-mode file. > > Something like > > #+INCLUDE file.hs::fun_def > > Where fun_def is the definition of a function. > programming modes know how to split this kind of things, so > also org-mode could now, right? > > > > _______________________________________________ > Emacs-orgmode mailing list > Remember: use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode - Carsten ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re:[babel] Re: What is output for org-babel? 2009-11-06 12:13 ` andrea Crotti 2009-11-06 12:17 ` Carsten Dominik @ 2009-11-06 16:15 ` Thomas S. Dye 1 sibling, 0 replies; 10+ messages in thread From: Thomas S. Dye @ 2009-11-06 16:15 UTC (permalink / raw) To: andrea Crotti; +Cc: emacs-orgmode On Nov 6, 2009, at 2:13 AM, andrea Crotti wrote: > Darlan Cavalcante Moreira <darcamo <at> gmail.com> writes: > >> >> However, if the code is sent to the python interpreter as it is, >> then it >> bugs me >> why "import os; os.listdir(os.getcwd())" didn't work. > > I tried to look at the code of org-babel-python > but it's a bit too complicated to understand how my body > is manipulated... > > For the second question I made, it would be even > better to have a mechanism that allows to insert > logical parts of another buffer in my org-mode file. > > Something like > > #+INCLUDE file.hs::fun_def > > Where fun_def is the definition of a function. > programming modes know how to split this kind of things, so > also org-mode could now, right? > > > > _______________________________________________ > Emacs-orgmode mailing list > Remember: use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode Hi Andrea, If I understand your question correctly, there might be several ways to achieve this with existing org-babel functions. Here are two that might work. 1) Establish a :session and make fun_def available there, or 2) Explore the possibilities offered by Library of Babel. This is something I haven't explored yet, but it appears to be designed for the problem you're describing. HTH, Tom ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: What is output for org-babel? 2009-11-05 14:26 ` Darlan Cavalcante Moreira 2009-11-06 12:13 ` andrea Crotti @ 2009-11-08 20:20 ` Dan Davison 2009-11-12 0:25 ` Dan Davison 1 sibling, 1 reply; 10+ messages in thread From: Dan Davison @ 2009-11-08 20:20 UTC (permalink / raw) To: Darlan Cavalcante Moreira; +Cc: emacs-orgmode, andrea Crotti Darlan Cavalcante Moreira <darcamo@gmail.com> writes: > COmments are inline. > > At Thu, 5 Nov 2009 11:17:39 +0000 (UTC), > andrea Crotti <andrea.crotti.0@gmail.com> wrote: >> >> I'm with org-mode 6.31a, I was trying to >> get output in the exported files but I never see the output. >> >> So I investigate and for example this >> >> #+BEGIN_SRC python >> import os; os.listdir(os.getcwd()) >> #+END_SRC > > This does not return anything for me either, but > #+BEGIN_SRC python > import os > os.listdir(os.getcwd()) > #+END_SRC > works as expected. This is strange, since "import os; os.listdir(os.getcwd())" > is valid and will work if typed in the python interpreter directly. This is a limitation of the current implementation of :results value evaluation. For now, while we work out a good solution, semi-colon separated statements on the same line (as well as multiline continuations) should be avoided when using :results value (the default). It does work with :results output: #+BEGIN_SRC python :results output import os; print os.listdir(os.getcwd()) #+END_SRC Thanks for pointing this problem out. Dan ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: What is output for org-babel? 2009-11-08 20:20 ` Dan Davison @ 2009-11-12 0:25 ` Dan Davison 0 siblings, 0 replies; 10+ messages in thread From: Dan Davison @ 2009-11-12 0:25 UTC (permalink / raw) To: Darlan Cavalcante Moreira; +Cc: emacs-orgmode, andrea Crotti Dan Davison <davison@stats.ox.ac.uk> writes: > Darlan Cavalcante Moreira <darcamo@gmail.com> writes: > <...> >>> So I investigate and for example this >>> >>> #+BEGIN_SRC python >>> import os; os.listdir(os.getcwd()) >>> #+END_SRC >> >> This does not return anything for me either, but >> #+BEGIN_SRC python >> import os >> os.listdir(os.getcwd()) >> #+END_SRC >> works as expected. This is strange, since "import os; os.listdir(os.getcwd())" >> is valid and will work if typed in the python interpreter directly. > > This is a limitation of the current implementation of :results value > evaluation. I've just pushed a change which fixes this and related problems. It introduces a change for python users: when using the default evaluation mode (':results value' non-session), if you want the source code block to return a value, you must now include the 'return' statement that would be required if you were writing a python function definition. On Worg I've added some more detailed documentation of exactly how the result is obtained in the four different cases (value/output, session/non-session), and I'm also pasting that below. Dan *** Evaluation results: output/value & session/non-session The following applies particularly to perl, python, R and ruby. Nature of Results: | | non-session | session | |--------+--------------------------+-------------------------------------| | value | value of last expression | value of last expression | | output | contents of stdout | concatenation of interpreter output | Note that in ':results value' (session and non-session), the result is imported into org-mode as a table (a one- or two-dimensional vector of strings or numbers) when appropriate. **** :results value (non-session) This is the default. Internally, the value is obtained by wrapping the code in a function definition in the external language, and evaluating that function. Therefore, code should be written as if it were the body of such a function. In particular, note that python does not automatically return a value from a function unless a =return= statement is present, and so a 'return' statement will usually be required in python :results value (non-session). This is the only one of the four evaluation contexts in which the code is automatically wrapped in a function definition. **** :results output (non-session) The code is passed to the interpreter as an external process, and the contents of the standard output stream is returned as text. (In certain languages this also contains the error output stream; this is an area for future work.) **** :results value (session) The code is passed to the interpreter running as an interactive emacs inferior process. The result returned is the result of the last evaluation performed by the interpreter. (This is obtained in a language-specific manner: the value of the variable =_= in python and ruby, and the value of =.Last.value= in R). **** :results output (session) The code is passed to the interpreter running as an interactive emacs inferior process. The result returned is the concatenation of the sequence of (text) output from the interactive interpreter. Notice that this is not necessarily the same as what would be sent to stdout if the same code were passed to a non-interactive interpreter running as an external process. For example, compare the following two blocks: #+begin_src python :results output print "hello" 2 print "bye" #+end_src #+resname: : hello : bye In non-session mode, the '2' is not printed and does not appear. #+begin_src python :results output :session print "hello" 2 print "bye" #+end_src #+resname: : hello : 2 : bye But in session mode, the interactive interpreter receives input '2' and prints out its value, '2'. (Indeed, the other print statements are unnecessary here). ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: What is output for org-babel? 2009-11-05 11:17 What is output for org-babel? andrea Crotti 2009-11-05 14:26 ` Darlan Cavalcante Moreira @ 2009-11-08 15:05 ` "Martin G. Skjæveland" 2009-11-08 15:19 ` "Martin G. Skjæveland" 2009-11-08 19:48 ` Dan Davison 1 sibling, 2 replies; 10+ messages in thread From: "Martin G. Skjæveland" @ 2009-11-08 15:05 UTC (permalink / raw) To: andrea Crotti; +Cc: emacs-orgmode andrea Crotti wrote: > I'm with org-mode 6.31a, I was trying to > get output in the exported files but I never see the output. Hi, not sure if this is related -- or helpful, but here goes! When I export the following file: ----------------start--------------- * lowercase #+begin_src python :exports results 2+2 #+end_src * uppercase #+BEGIN_SRC python :exports results 2+2 #+end_src ----------------end--------------- the results are (copied from pdf): ----------------start--------------- 1 lowercase 4 2 uppercase 2+2 ----------------end--------------- Writing "begin_src" in lowercase or uppercase makes a difference. I am not sure if this is a feature or a bug. Martin ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: What is output for org-babel? 2009-11-08 15:05 ` "Martin G. Skjæveland" @ 2009-11-08 15:19 ` "Martin G. Skjæveland" 2009-11-08 19:48 ` Dan Davison 1 sibling, 0 replies; 10+ messages in thread From: "Martin G. Skjæveland" @ 2009-11-08 15:19 UTC (permalink / raw) To: andrea Crotti; +Cc: emacs-orgmode Martin G. Skjæveland wrote: > andrea Crotti wrote: >> I'm with org-mode 6.31a, I was trying to >> get output in the exported files but I never see the output. > > Writing "begin_src" in lowercase or uppercase makes a difference. I am > not sure if this is a feature or a bug. Oh, forgot to mention: I can't make any of the snippets you sent work. Everything in the source blocks is exported as verbatim text, regardless of upper/lowercase, or :results output or not. Martin ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: What is output for org-babel? 2009-11-08 15:05 ` "Martin G. Skjæveland" 2009-11-08 15:19 ` "Martin G. Skjæveland" @ 2009-11-08 19:48 ` Dan Davison 1 sibling, 0 replies; 10+ messages in thread From: Dan Davison @ 2009-11-08 19:48 UTC (permalink / raw) To: Martin G. Skjæveland; +Cc: emacs-orgmode, andrea Crotti, Carsten Dominik "Martin G. Skjæveland" <martige@ifi.uio.no> writes: > andrea Crotti wrote: >> I'm with org-mode 6.31a, I was trying to >> get output in the exported files but I never see the output. > > Hi, > > not sure if this is related -- or helpful, but here goes! > > When I export the following file: > > ----------------start--------------- > * lowercase > #+begin_src python :exports results > 2+2 > #+end_src > > * uppercase > #+BEGIN_SRC python :exports results > 2+2 > #+end_src > ----------------end--------------- > > the results are (copied from pdf): > > ----------------start--------------- > 1 lowercase > 4 > > 2 uppercase > 2+2 > ----------------end--------------- > > Writing "begin_src" in lowercase or uppercase makes a difference. I am > not sure if this is a feature or a bug. Bug. However I'm not sure whether it is in org-mode or org-babel. In general in org-mode, begin_src and BEGIN_SRC are equivalent (true for all #+XXX directives I think). However, in this case the org-exp-blocks client (org-babel) associates 'src' with its own block exporter, but it says nothing about 'SRC'. So the solution could either be: (a) Bug in the org-exp-blocks client (org-babel). The client should explicitly hook up 'SRC' to its block pre-processor. (b) Bug in org-mode. Org-exp-blocks should call the block pre-processor for 'src' when it finds 'SRC' (and equivalently, if a client registers 'SRC', then 'src' should trigger it.) I'm leaning towards (b), seeing as we already have the case insensitivity in org-mode. Dan > > Martin > > > _______________________________________________ > Emacs-orgmode mailing list > Remember: use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2009-11-12 0:25 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-11-05 11:17 What is output for org-babel? andrea Crotti 2009-11-05 14:26 ` Darlan Cavalcante Moreira 2009-11-06 12:13 ` andrea Crotti 2009-11-06 12:17 ` Carsten Dominik 2009-11-06 16:15 ` Thomas S. Dye 2009-11-08 20:20 ` Dan Davison 2009-11-12 0:25 ` Dan Davison 2009-11-08 15:05 ` "Martin G. Skjæveland" 2009-11-08 15:19 ` "Martin G. Skjæveland" 2009-11-08 19:48 ` Dan Davison
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).