From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: Re: [BUG] org-babel-perl and formats Date: Fri, 09 Apr 2010 09:21:34 -0400 Message-ID: <87ochssqw1.fsf@stats.ox.ac.uk> References: <874ojm7py8.fsf@kotik.lan> <8739z6djv5.fsf@stats.ox.ac.uk> <87r5mpyoqi.fsf@dasa3.iem.pw.edu.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O0E9Z-0007oO-Ba for emacs-orgmode@gnu.org; Fri, 09 Apr 2010 09:21:46 -0400 Received: from [140.186.70.92] (port=51946 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O0E9V-0007ne-PJ for emacs-orgmode@gnu.org; Fri, 09 Apr 2010 09:21:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O0E9T-0003zm-Ih for emacs-orgmode@gnu.org; Fri, 09 Apr 2010 09:21:41 -0400 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:57642) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O0E9T-0003zX-BR for emacs-orgmode@gnu.org; Fri, 09 Apr 2010 09:21:39 -0400 In-Reply-To: <87r5mpyoqi.fsf@dasa3.iem.pw.edu.pl> (=?utf-8?Q?=22=C5=81ukas?= =?utf-8?Q?z?= Stelmach"'s message of "Fri, 09 Apr 2010 11:11:33 +0200") 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: =?utf-8?Q?=C5=81ukasz?= Stelmach Cc: emacs-orgmode@gnu.org =C5=81ukasz Stelmach writes: > Dan Davison writes: > >> =C5=81ukasz Stelmach writes: >>> I am not sure I will be able to spend some time on this so I'll share my >>> observation with you. org-babel-perl can't cope with perl formats, with >>> their endings to be precise. A format is defined by: >>> >>> format FORMAT_NAME =3D=20 >>> body of the format >>> . >>> >>> The problem is that formats *must* and with a single solitary dot or, to >>> be precise "\n.\n" sequence. org-babel-perl doesn't care about it and >>> puts "\t" befor the dot. >> >> Could you post an example? I don't believe we insert tab >> characters. I've never used a perl format before, but I just tried it >> and it seemed to work OK with C-c C-c: >> >> #+begin_src perl >> format STDOUT =3D >> @<<<<<< @|||||| @>>>>>> >> "left", "middle", "right" >> . >> write ; >> #+end_src >> >> #+results: >> : left middle right > > With the very same code i get > > Format not terminated at - line 11, at end of line > syntax error at - line 11, at EOF > Execution of - aborted due to compilation errors. Oops. Sorry =C5=81ukasz, my mistake. You are of course right, we were adding indentation to perl code (apparently I started with a copy of org-babel-python.el when I wrote org-babel-perl.el). That is fixed now. We got different results because I had set perl to :results output by default. For this particular block, you will also want to use :results output (see below). You pointed out that > > while strace shows the code being wrapped > > write(9, "\nsub main {\n\tformat STDOUT =3D\n\t@<<<<<< @|||||| @>>>>>>\n\= t\"left\", \"middle\", \"right\"\n\t.\n\twrite ;\n}\n@r =3D main;\nopen(o, = \">/tmp/perl-functional-results17170oCG\");\nprint o join(\"\\n\", @r), \"\= \n\"", 184) =3D 184 > > inside something really odd: > > sub main { > format STDOUT =3D > @<<<<<< @|||||| @>>>>>> > "left", "middle", "right" > . > write ; > } > @r =3D main; > open(o, ">/tmp/perl-functional-results17170oCG"); > print o join("\n", @r), "\n" Babel has two basic modes of execution: :results value :: The default, you get the value of the last expression, = interpreted as a list/table if possible. :results output :: You get stdout The wrapping-in-function-body stuff only happens with :results value. So by default, with the block above, you will get the counterintuitive outc= ome: #+results: | 1 | | 1 | The default outcome here is fairly baffling, and I imagine that perl users are often going to want the contents of stdout. This can be done globally with (setq org-babel-default-header-args:perl '((:results . "output"))) The trouble with that is that perl blocks will not communicate nicely with other blocks: #+source: a-number #+begin_src perl :results value 4 #+end_src #+begin_src emacs-lisp :var i=3Da-number() (+ i 1) #+end_src #+results: : 5 With :results output on the perl block, we get a Wrong type argument: number-or-marker-p, "" because the perl block returns textual output rather than interpreting the result as numeric. Dan > >> Incidentally, do you know the variable org-src-preserve-indentation? >> When I first read your email I thought that would be the answer. In fact >> it doesn't seem to be relevant, but I thought I would mention it anyway. > > Unfortunately it doesn't make any difference.