* [BABEL] Output with octave @ 2010-07-23 16:59 d.tchin 2010-07-23 23:12 ` Eric S Fraga 0 siblings, 1 reply; 13+ messages in thread From: d.tchin @ 2010-07-23 16:59 UTC (permalink / raw) To: emacs-orgmode Hi I use babel to use with octave language. I use it and define a session so as to have interaction with octave process. It is great to have interaction with octave and check the action of the code easily. I have problem to get output back in org mode file. I try the following code : --8<---------------cut here---------------start------------->8--- #+tblname: test | 1 | 2 | 3 | #+source: outtest #+begin_src octave :session *out* :var vec=test :results output vecb=vec; vecb #+end_src --8<---------------cut here---------------end--------------->8--- You will get following output #+results: outtest : vec = : : 1 2 3 : octave.exe> vecb = : : 1 2 3 As you see I get two outputs : vec variable and vecb (with octave prompt). It is what I expected, excepted vec output. With :results value --8<---------------cut here---------------start------------->8--- #+tblname: test | 1 | 2 | 3 | #+source: outtest #+begin_src octave :session *out* :var vec=test :results value vecb=vec; vecb #+end_src --8<---------------cut here---------------end--------------->8--- I get the following output #+results: outtest : org_babel_eoe In the octave process, I check that it the last intruction. But what I would expect is to get last instruction vecb. I certainly miss something. Could someone help me on this ? ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [BABEL] Output with octave 2010-07-23 16:59 [BABEL] Output with octave d.tchin @ 2010-07-23 23:12 ` Eric S Fraga 2010-07-26 14:25 ` d.tchin 2010-08-01 18:18 ` Dan Davison 0 siblings, 2 replies; 13+ messages in thread From: Eric S Fraga @ 2010-07-23 23:12 UTC (permalink / raw) To: d.tchin; +Cc: emacs-orgmode [-- Attachment #1: Type: text/plain, Size: 2023 bytes --] On Fri, 23 Jul 2010 16:59:43 +0000 (UTC), d.tchin <d.tchin@voila.fr> wrote: > > Hi > > I use babel to use with octave language. I use it and > define a session so as to have interaction with > octave process. > > It is great to have interaction with octave and > check the action of the code easily. > > I have problem to get output back in org mode file. > I try the following code : > > > --8<---------------cut here---------------start------------->8--- > #+tblname: test > | 1 | 2 | 3 | > > #+source: outtest > #+begin_src octave :session *out* :var vec=test :results output > vecb=vec; > vecb > #+end_src > > --8<---------------cut here---------------end--------------->8--- > > You will get following output > > #+results: outtest > : vec = > : > : 1 2 3 > : octave.exe> vecb = > : > : 1 2 3 > > As you see I get two outputs : vec variable and vecb (with octave prompt). > It is what I expected, excepted vec output. > > With :results value > > --8<---------------cut here---------------start------------->8--- > #+tblname: test > | 1 | 2 | 3 | > > > > #+source: outtest > #+begin_src octave :session *out* :var vec=test :results value > vecb=vec; > vecb > #+end_src > > --8<---------------cut here---------------end--------------->8--- > > I get the following output > > > #+results: outtest > : org_babel_eoe > > In the octave process, I check that it the last intruction. But > what I would expect is to get last instruction vecb. > > I certainly miss something. Could someone help me on this ? I don't think you are missing anything obvious as for the ":results value" case, I get the same thing. In fact, for ":results output", I don't actually get any output! I'm not sure why. I wonder if there is a dependence on the version of Octave? I'm using a fairly old version (3.0.x instead of 3.2.x). : Org-mode version 7.01trans (release_7.01g.24.g6b5cf) : GNU Emacs 23.2.1 (i486-pc-linux-gnu, GTK+ Version 2.20.0) : of 2010-05-16 on raven, modified by Debian [-- Attachment #2: Type: text/plain, Size: 75 bytes --] -- Eric S Fraga GnuPG: 8F5C 279D 3907 E14A 5C29 570D C891 93D8 FFFC F67D [-- Attachment #3: Type: text/plain, Size: 201 bytes --] _______________________________________________ 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 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [BABEL] Output with octave 2010-07-23 23:12 ` Eric S Fraga @ 2010-07-26 14:25 ` d.tchin 2010-08-01 18:18 ` Dan Davison 1 sibling, 0 replies; 13+ messages in thread From: d.tchin @ 2010-07-26 14:25 UTC (permalink / raw) To: emacs-orgmode Eric S Fraga <ucecesf <at> ucl.ac.uk> writes: > > I don't think you are missing anything obvious as for the ":results > value" case, I get the same thing. In fact, for ":results output", I > don't actually get any output! I'm not sure why. I wonder if there > is a dependence on the version of Octave? I'm using a fairly old > version (3.0.x instead of 3.2.x). > I use following version of Octave : GNU Octave, version 3.2.0 Copyright (C) 2009 John W. Eaton and others. This is free software; see the source code for copying conditions. There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, type `warranty'. Octave was configured for "i686-pc-mingw32". ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [BABEL] Output with octave 2010-07-23 23:12 ` Eric S Fraga 2010-07-26 14:25 ` d.tchin @ 2010-08-01 18:18 ` Dan Davison 2010-08-01 20:07 ` Re: [BABEL] Output with octave + [PATCH] x2 Juan 2010-08-02 9:30 ` [BABEL] Output with octave d.tchin 1 sibling, 2 replies; 13+ messages in thread From: Dan Davison @ 2010-08-01 18:18 UTC (permalink / raw) To: Eric S Fraga; +Cc: emacs-orgmode, d.tchin Eric S Fraga <ucecesf@ucl.ac.uk> writes: > On Fri, 23 Jul 2010 16:59:43 +0000 (UTC), d.tchin <d.tchin@voila.fr> wrote: >> >> Hi >> >> I use babel to use with octave language. I use it and >> define a session so as to have interaction with >> octave process. >> >> It is great to have interaction with octave and >> check the action of the code easily. >> >> I have problem to get output back in org mode file. >> I try the following code : >> >> >> --8<---------------cut here---------------start------------->8--- >> #+tblname: test >> | 1 | 2 | 3 | >> >> #+source: outtest >> #+begin_src octave :session *out* :var vec=test :results output >> vecb=vec; >> vecb >> #+end_src >> >> --8<---------------cut here---------------end--------------->8--- >> >> You will get following output >> >> #+results: outtest >> : vec = >> : >> : 1 2 3 >> : octave.exe> vecb = >> : >> : 1 2 3 >> >> As you see I get two outputs : vec variable and vecb (with octave prompt). >> It is what I expected, excepted vec output. The inclusion of the prompt is undesirable, and that is now on a to-fix list. But the ":results value" problems are more serious: >> >> With :results value >> >> --8<---------------cut here---------------start------------->8--- >> #+tblname: test >> | 1 | 2 | 3 | >> >> >> >> #+source: outtest >> #+begin_src octave :session *out* :var vec=test :results value >> vecb=vec; >> vecb >> #+end_src >> >> --8<---------------cut here---------------end--------------->8--- >> >> I get the following output >> >> >> #+results: outtest >> : org_babel_eoe OK, perhaps you or other octave users could advise us on how to proceed here, as neither Eric Schulte nor I know octave. Note that this works: #+begin_src octave :session *out* :var vec=test vecb=vec; vecb+0 #+end_src #+results: : 1.00000000e+00 2.00000000e+00 3.00000000e+00 octave evaluation in org works as follows: - The user code is evaluated - The value of the variable 'ans' is written to disk and imported into org And the octave manual tells us that 'ans' is: ,---- | The most recently computed result that was not explicitly assigned to a variable `---- The trouble seems to be that the final expression 'vecb' doesn't count as a computation, and so doesn't change the value of ans. So the current workaround is to say "when using octave, you must end your block with a computation, rather than a simple statement of a variable name." Can someone suggest a better solution? Dan p.s. Or you could do this #+begin_src octave :session *out* :var vec=test vecb=vec; ans=vecb #+end_src #+begin_src octave :session *out* :var vec=test vecb=vec; ans=vecb ans #+end_src >> >> In the octave process, I check that it the last intruction. But >> what I would expect is to get last instruction vecb. >> >> I certainly miss something. Could someone help me on this ? > > I don't think you are missing anything obvious as for the ":results > value" case, I get the same thing. In fact, for ":results output", I > don't actually get any output! I'm not sure why. I wonder if there > is a dependence on the version of Octave? I'm using a fairly old > version (3.0.x instead of 3.2.x). > > : Org-mode version 7.01trans (release_7.01g.24.g6b5cf) > : GNU Emacs 23.2.1 (i486-pc-linux-gnu, GTK+ Version 2.20.0) > : of 2010-05-16 on raven, modified by Debian ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Re: [BABEL] Output with octave + [PATCH] x2 2010-08-01 18:18 ` Dan Davison @ 2010-08-01 20:07 ` Juan 2010-08-01 20:22 ` Re: [BABEL] Output with octave [PATCH] Juan Pechiar 2010-08-01 22:19 ` [BABEL] Output with octave + [PATCH] x2 Dan Davison 2010-08-02 9:30 ` [BABEL] Output with octave d.tchin 1 sibling, 2 replies; 13+ messages in thread From: Juan @ 2010-08-01 20:07 UTC (permalink / raw) To: Dan Davison; +Cc: emacs-orgmode, d.tchin Hi, I'm starting to work with ob-octave and found several problems: The first, for which I have a fix (see patch below) is that octave's output was passed on as a string instead of being interpreted as a table: 8<------------------------------------------------------------ diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el index 8e99f86..d0d16fe 100644 --- a/lisp/ob-octave.el +++ b/lisp/ob-octave.el @@ -181,7 +181,7 @@ value of the last statement in BODY, as elisp." (org-babel-eval cmd (format org-babel-octave-wrapper-method body tmp-file tmp-file)) - (org-babel-eval-read-file tmp-file)))))) + (org-babel-octave-import-elisp-from-file tmp-file)))))) (defun org-babel-octave-evaluate-session (session body result-type &optional matlabp) 8<------------------------------------------------------------ Now this works: 8<------------------------------------------------------------ #+source: test_output #+begin_src octave :results value vector [[1 2 3];[4 5 6]] #+end_src #+results: test_output | 1.00000000e+00 | 2.00000000e+00 | 3.00000000e+00 | | 4.00000000e+00 | 5.00000000e+00 | 6.00000000e+00 | 8<------------------------------------------------------------ (before the patch you'd get a single table element with something like "1 2 3\n 4 5 6\n" inside). The second problem is that if I use octave table output as input to another block, it gets interpreted as a string instead of a vector: 8<------------------------------------------------------------ #+results: test_output | 1.25000000e+00 | #+source: check_input #+begin_src octave :var input=test_output() :results output ischar( input ) size( input ) #+end_src #+results: check_input : input = 1.25000000e+00 : ans = 1 : ans = : 1 14 8<------------------------------------------------------------ This has to do with the EXP notation. The 'e+00' suffix makes the whole table into a string. The problem is with "%S" in the formatting inside org-babel-octave-var-to-octave. The following patch seems to fix it (and makes it possible to work with complex numbers inside the tables):: 8<------------------------------------------------------------ diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el index 8e99f86..4329c7f 100644 --- a/lisp/ob-octave.el +++ b/lisp/ob-octave.el @@ -120,7 +120,7 @@ Converts an emacs-lisp variable into a string of octave code specifying a variable of the same value." (if (listp var) (concat "[" (mapconcat #'org-babel-octave-var-to-octave var ", ") "]") - (format "%S" var))) + (format "%s" var))) (defun org-babel-prep-session:octave (session params &optional matlabp) "Prepare SESSION according to the header arguments specified in PARAMS." 8<------------------------------------------------------------ A third problem is with org-babel-octave-var-to-octave. For example: : (org-babel-octave-var-to-octave '( ( 1 2 3 ) ( 4 5 6 ) )) : -> "[[1, 2, 3], [4, 5, 6]]" This is not a 2x3 matrix, but a 1x6 vector: : octave-3.2.3:1> [[1,2,3],[4,5,6]] : ans = : 1 2 3 4 5 6 a semicolon ';' or '\n' is needed between rows instead of a comma. To sum up: - 2 patches for prepare-session and importing the results back as org-tables (I don't know if these patches break anything). - 1 problem with matrix notation in org-babel-octave-var-to-octave. I'll try to provide a patch for this today. I'm not working with sessions, so I have not yet tested the original problem reported with 'org_babel_eoe' showing up as result. Regards, .j. On Sun, Aug 01, 2010 at 02:18:40PM -0400, Dan Davison wrote: > Eric S Fraga <ucecesf@ucl.ac.uk> writes: > > On Fri, 23 Jul 2010 16:59:43 +0000 (UTC), d.tchin <d.tchin@voila.fr> wrote: > >> I have problem to get output back in org mode file. ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: Re: [BABEL] Output with octave [PATCH] 2010-08-01 20:07 ` Re: [BABEL] Output with octave + [PATCH] x2 Juan @ 2010-08-01 20:22 ` Juan Pechiar 2010-08-04 4:18 ` Dan Davison 2010-08-01 22:19 ` [BABEL] Output with octave + [PATCH] x2 Dan Davison 1 sibling, 1 reply; 13+ messages in thread From: Juan Pechiar @ 2010-08-01 20:22 UTC (permalink / raw) To: Dan Davison; +Cc: emacs-orgmode, d.tchin Hi, Below is a single PATCH for the 3 issues: - passing tables with EXP or complex notation to octave - correct formatting of matrixes into octave - interpretation of octave output as table Regards, .j. 8<------------------------------------------------------------ diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el index 8e99f86..bf7fdd3 100644 --- a/lisp/ob-octave.el +++ b/lisp/ob-octave.el @@ -119,8 +119,9 @@ end") Converts an emacs-lisp variable into a string of octave code specifying a variable of the same value." (if (listp var) - (concat "[" (mapconcat #'org-babel-octave-var-to-octave var ", ") "]") - (format "%S" var))) + (concat "[" (mapconcat #'org-babel-octave-var-to-octave var + (if (listp (car var)) "; " ",")) "]") + (format "%s" var))) (defun org-babel-prep-session:octave (session params &optional matlabp) "Prepare SESSION according to the header arguments specified in PARAMS." @@ -181,7 +182,7 @@ value of the last statement in BODY, as elisp." (org-babel-eval cmd (format org-babel-octave-wrapper-method body tmp-file tmp-file)) - (org-babel-eval-read-file tmp-file)))))) + (org-babel-octave-import-elisp-from-file tmp-file)))))) (defun org-babel-octave-evaluate-session (session body result-type &optional matlabp) 8<------------------------------------------------------------ On Sun, Aug 01, 2010 at 05:07:27PM -0300, Juan wrote: > I'm starting to work with ob-octave and found several problems: > > The first, for which I have a fix (see patch below) is that octave's > output was passed on as a string instead of being interpreted as a table: > The second problem is that if I use octave table output as input to > another block, it gets interpreted as a string instead of a vector: > This has to do with the EXP notation. The 'e+00' suffix makes the > whole table into a string. The problem is with "%S" in the formatting > inside org-babel-octave-var-to-octave. > A third problem is with org-babel-octave-var-to-octave. > > For example: > > : (org-babel-octave-var-to-octave '( ( 1 2 3 ) ( 4 5 6 ) )) > : -> "[[1, 2, 3], [4, 5, 6]]" > > This is not a 2x3 matrix, but a 1x6 vector: > > : octave-3.2.3:1> [[1,2,3],[4,5,6]] > : ans = > : 1 2 3 4 5 6 > > a semicolon ';' or '\n' is needed between rows instead of a comma. ^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [BABEL] Output with octave [PATCH] 2010-08-01 20:22 ` Re: [BABEL] Output with octave [PATCH] Juan Pechiar @ 2010-08-04 4:18 ` Dan Davison 2010-08-04 15:15 ` d.tchin 0 siblings, 1 reply; 13+ messages in thread From: Dan Davison @ 2010-08-04 4:18 UTC (permalink / raw) To: Juan Pechiar; +Cc: emacs-orgmode, d.tchin Hi Juan and d.tchin, One thing I'd like to ask for advice about is the behaviour of tabular data structures containing strings. For example #+begin_src octave ans = [['a','b'];['c','d']] #+end_src #+results: : acbd I don't know if my syntax above is correct, but it seems to me that this is a 2x2 table of some sort and so it would seem natural to me for that to return | a | b | | c | d | however, if you look at the code we are using below, you'll see that ischar() returns 1 for this object and so it gets written as a string. Can you suggest how we should alter the octave/matlab code below? Or perhaps people don't use tabular data structures containing strings in these languages? if ischar(ans), fid = fopen('%s', 'w'); fprintf(fid, '%%s\\n', ans); fclose(fid); else, dlmwrite('%s', ans, '\\t') end" Dan Juan Pechiar <pechiar@computer.org> writes: > Hi, > > Below is a single PATCH for the 3 issues: > - passing tables with EXP or complex notation to octave > - correct formatting of matrixes into octave > - interpretation of octave output as table > > Regards, > .j. > > 8<------------------------------------------------------------ > > diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el > index 8e99f86..bf7fdd3 100644 > --- a/lisp/ob-octave.el > +++ b/lisp/ob-octave.el > @@ -119,8 +119,9 @@ end") > Converts an emacs-lisp variable into a string of octave code > specifying a variable of the same value." > (if (listp var) > - (concat "[" (mapconcat #'org-babel-octave-var-to-octave var ", > ") "]") > - (format "%S" var))) > + (concat "[" (mapconcat #'org-babel-octave-var-to-octave var > + (if (listp (car var)) "; " ",")) "]") > + (format "%s" var))) > > (defun org-babel-prep-session:octave (session params &optional > matlabp) > "Prepare SESSION according to the header arguments specified in > PARAMS." > @@ -181,7 +182,7 @@ value of the last statement in BODY, as elisp." > (org-babel-eval > cmd > (format org-babel-octave-wrapper-method body tmp-file > tmp-file)) > - (org-babel-eval-read-file tmp-file)))))) > + (org-babel-octave-import-elisp-from-file tmp-file)))))) > > (defun org-babel-octave-evaluate-session > (session body result-type &optional matlabp) > > 8<------------------------------------------------------------ > > On Sun, Aug 01, 2010 at 05:07:27PM -0300, Juan wrote: >> I'm starting to work with ob-octave and found several problems: >> >> The first, for which I have a fix (see patch below) is that octave's >> output was passed on as a string instead of being interpreted as a table: > > >> The second problem is that if I use octave table output as input to >> another block, it gets interpreted as a string instead of a vector: > > >> This has to do with the EXP notation. The 'e+00' suffix makes the >> whole table into a string. The problem is with "%S" in the formatting >> inside org-babel-octave-var-to-octave. > > >> A third problem is with org-babel-octave-var-to-octave. >> >> For example: >> >> : (org-babel-octave-var-to-octave '( ( 1 2 3 ) ( 4 5 6 ) )) >> : -> "[[1, 2, 3], [4, 5, 6]]" >> >> This is not a 2x3 matrix, but a 1x6 vector: >> >> : octave-3.2.3:1> [[1,2,3],[4,5,6]] >> : ans = >> : 1 2 3 4 5 6 >> >> a semicolon ';' or '\n' is needed between rows instead of a comma. > > _______________________________________________ > 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 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [BABEL] Output with octave [PATCH] 2010-08-04 4:18 ` Dan Davison @ 2010-08-04 15:15 ` d.tchin 0 siblings, 0 replies; 13+ messages in thread From: d.tchin @ 2010-08-04 15:15 UTC (permalink / raw) To: emacs-orgmode Dan Davison <davison <at> stats.ox.ac.uk> writes: > > Hi Juan and d.tchin, > > One thing I'd like to ask for advice about is the behaviour of tabular > data structures containing strings. For example > > #+begin_src octave > ans = [['a','b'];['c','d']] > #+end_src > > #+results: > : acbd > > I don't know if my syntax above is correct, but it seems to me that this > is a 2x2 table of some sort and so it would seem natural to me for that > to return > > | a | b | > | c | d | > > however, if you look at the code we are using below, you'll see that > ischar() returns 1 for this object and so it gets written as a > string. Can you suggest how we should alter the octave/matlab code > below? Or perhaps people don't use tabular data structures containing > strings in these languages? > > if ischar(ans), fid = fopen('%s', 'w'); fprintf(fid, '%%s\\n', ans); fclose (fid); > else, dlmwrite('%s', ans, '\\t') > end" > > Dan > I use typeinfo defined in Octave to see what kind of object Octave would consider as output. You can see that [["a',"b"];["c","d"]] is considered as string and not a matrix. And the output in Octave is ans = ab cd See tests below done with character and number. Hope that can help. --8<---------------cut here---------------start------------->8--- * Output typeinfo ** Character #+begin_src octave typeinfo("a") #+end_src #+results: : string #+begin_src octave ["c","d"] #+end_src #+results: : cd #+begin_src octave [["a","b"];["c","d"]] #+end_src #+results: : acbd #+begin_src octave typeinfo([["a","b"];["c","d"]]) #+end_src #+results: : string ** Number #+begin_src octave typeinfo(1) #+end_src #+results: : scalar #+begin_src octave [1,2] #+end_src #+results: : 1.00000000e+000 2.00000000e+000 #+begin_src octave typeinfo([1,2]) #+end_src #+results: : matrix #+begin_src octave ([[1,2];[3,4]]) #+end_src #+results: : 1.00000000e+000 2.00000000e+000 : 3.00000000e+000 4.00000000e+000 #+begin_src octave typeinfo([[1,2];[3,4]]) #+end_src #+results: : matrix --8<---------------cut here---------------end--------------->8--- ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [BABEL] Output with octave + [PATCH] x2 2010-08-01 20:07 ` Re: [BABEL] Output with octave + [PATCH] x2 Juan 2010-08-01 20:22 ` Re: [BABEL] Output with octave [PATCH] Juan Pechiar @ 2010-08-01 22:19 ` Dan Davison 2010-08-01 22:55 ` [BABEL] Octave issues Juan 1 sibling, 1 reply; 13+ messages in thread From: Dan Davison @ 2010-08-01 22:19 UTC (permalink / raw) To: Juan; +Cc: emacs-orgmode, d.tchin Juan <Pechiar@computer.org> writes: > Hi, > > I'm starting to work with ob-octave and found several problems: Hi Juan, Thanks very much. I've applied your patch with one minor change: (format "%s" (or var "nil")) However, is there a better way to receive an elisp nil value in octave? > I'm not working with sessions, so I have not yet tested the original > problem reported with 'org_babel_eoe' showing up as result. Sorry to pursue you for more help, but that problem is not limited to sessions. A very simple demonstration of it is #+begin_src octave x = 5 x #+end_src #+results: : /usr/share/octave/packages/3.2 This happens because neither of these two lines of code alter the value of 'ans' (I presume the value we are seeing is something from octave's start-up sequence). Contrast this with #+begin_src octave x = 5 x+0 #+end_src #+results: : 5.00000000e+00 Any idea of the best way forward? Dan > > Regards, > .j. > > > > On Sun, Aug 01, 2010 at 02:18:40PM -0400, Dan Davison wrote: >> Eric S Fraga <ucecesf@ucl.ac.uk> writes: >> > On Fri, 23 Jul 2010 16:59:43 +0000 (UTC), d.tchin <d.tchin@voila.fr> wrote: >> >> I have problem to get output back in org mode file. > > _______________________________________________ > 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 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [BABEL] Octave issues 2010-08-01 22:19 ` [BABEL] Output with octave + [PATCH] x2 Dan Davison @ 2010-08-01 22:55 ` Juan 2010-08-01 23:32 ` Dan Davison 0 siblings, 1 reply; 13+ messages in thread From: Juan @ 2010-08-01 22:55 UTC (permalink / raw) To: Dan Davison; +Cc: emacs-orgmode, d.tchin On Sun, Aug 01, 2010 at 06:19:30PM -0400, Dan Davison wrote: > Juan <Pechiar@computer.org> writes: > Thanks very much. I've applied your patch with one minor change: > > (format "%s" (or var "nil")) > > However, is there a better way to receive an elisp nil value in octave? [] can be used for an empty matrix. What is the use-case for nil here? > > I'm not working with sessions, so I have not yet tested the original > > problem reported with 'org_babel_eoe' showing up as result. > > Sorry to pursue you for more help, but that problem is not limited to > sessions. A very simple demonstration of it is Apparently 'ans' won't help much; it only contains results of operations, not assignments. : The `ans' variable always contains the result of the last computation, : where the output wasn't assigned to any variable. The code `a = cos : (pi)' will assign the value -1 to the variable `a', but will not : change the value of `ans'. However, the code `cos (pi)' will set the : value of `ans' to -1. I cannot find an alternative way of getting the result from the last statement. You can assign to 'ans' however, so it could be an inconvenient requirement to either end the source block with a computation or with an assignment to 'ans'. Yuk! #+begin_src x = 42 ans = x #+end_src Another option, equally inconvenient, is to add a header option with the name of the variable to return (in case it is not 'ans'): #+begin_src :outvar x x = 42 3 * 3 # this doesn't matter #+end_src Another much more fragile option would be to actually parse the end of the code block looking for computation vs. assignment. This one will never work! Regards, .j. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [BABEL] Octave issues 2010-08-01 22:55 ` [BABEL] Octave issues Juan @ 2010-08-01 23:32 ` Dan Davison 0 siblings, 0 replies; 13+ messages in thread From: Dan Davison @ 2010-08-01 23:32 UTC (permalink / raw) To: Juan; +Cc: emacs-orgmode, d.tchin Juan <pechiar@computer.org> writes: > On Sun, Aug 01, 2010 at 06:19:30PM -0400, Dan Davison wrote: >> Juan <Pechiar@computer.org> writes: > >> Thanks very much. I've applied your patch with one minor change: >> >> (format "%s" (or var "nil")) >> >> However, is there a better way to receive an elisp nil value in octave? > > [] can be used for an empty matrix. > > What is the use-case for nil here? I don't have one to hand. I mistakenly thought that (format "%s" nil) resulted in error, but I see now that is not true, so both are equivalent. > >> > I'm not working with sessions, so I have not yet tested the original >> > problem reported with 'org_babel_eoe' showing up as result. >> >> Sorry to pursue you for more help, but that problem is not limited to >> sessions. A very simple demonstration of it is > > Apparently 'ans' won't help much; it only contains results of > operations, not assignments. > > : The `ans' variable always contains the result of the last computation, > : where the output wasn't assigned to any variable. The code `a = cos > : (pi)' will assign the value -1 to the variable `a', but will not > : change the value of `ans'. However, the code `cos (pi)' will set the > : value of `ans' to -1. > > I cannot find an alternative way of getting the result from the last > statement. > > You can assign to 'ans' however, so it could be an inconvenient > requirement to either end the source block with a computation or with > an assignment to 'ans'. Yuk! I'm thinking that this is how it's going to have to be though. We have a comparable requirement in python, where you must use a 'return' statement in external evaluation mode. So it's looking to me like in matlab and octave, just as you say, you either have to end with a computation, or you have to otherwise ensure that 'ans' contains the value you want at the end of your code. And that's true in sessions and external. (The difference is that in python you *can* access the last value, but only in the interactive session mode of the interpreter.) > > #+begin_src > x = 42 > ans = x > #+end_src > > Another option, equally inconvenient, is to add a header option with > the name of the variable to return (in case it is not 'ans'): > > #+begin_src :outvar x > x = 42 > 3 * 3 # this doesn't matter > #+end_src I was going to say that I don't think we want to go there, as we would want to make such a feature available for all languages. But I can see that this might be quite natural in octave (and matlab?) because it reflects the syntax for defining functions. But in any case this is, as you indicate, just a generalisation of the above. > > Another much more fragile option would be to actually parse the end of > the code block looking for computation vs. assignment. This one will > never work! I agree! (I guess it might be do-able in languages that can parse themselves) Dan > > Regards, > .j. > > _______________________________________________ > 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 ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [BABEL] Output with octave 2010-08-01 18:18 ` Dan Davison 2010-08-01 20:07 ` Re: [BABEL] Output with octave + [PATCH] x2 Juan @ 2010-08-02 9:30 ` d.tchin 2010-08-04 4:15 ` Dan Davison 1 sibling, 1 reply; 13+ messages in thread From: d.tchin @ 2010-08-02 9:30 UTC (permalink / raw) To: emacs-orgmode Hi, Dan Davison <davison <at> stats.ox.ac.uk> writes: > > Eric S Fraga <ucecesf <at> ucl.ac.uk> writes: > > > On Fri, 23 Jul 2010 16:59:43 +0000 (UTC), d.tchin <d.tchin <at> voila.fr> wrote: > >> > >> With :results value > >> > >> --8<---------------cut here---------------start------------->8--- > >> #+tblname: test > >> | 1 | 2 | 3 | > >> > >> > >> > >> #+source: outtest > >> #+begin_src octave :session *out* :var vec=test :results value > >> vecb=vec; > >> vecb > >> #+end_src > >> > >> --8<---------------cut here---------------end--------------->8--- > >> > >> I get the following output > >> > >> > >> #+results: outtest > >> : org_babel_eoe > > OK, perhaps you or other octave users could advise us on how to proceed > here, as neither Eric Schulte nor I know octave. Note that this works: > > #+begin_src octave :session *out* :var vec=test > vecb=vec; > vecb+0 > #+end_src > > #+results: > : 1.00000000e+00 2.00000000e+00 3.00000000e+00 > > octave evaluation in org works as follows: > - The user code is evaluated > - The value of the variable 'ans' is written to disk and imported into > org > > And the octave manual tells us that 'ans' is: > > ,---- > | The most recently computed result that was not explicitly assigned to a variable > `---- > > The trouble seems to be that the final expression 'vecb' doesn't count > as a computation, and so doesn't change the value of ans. > > So the current workaround is to say "when using octave, you must end > your block with a computation, rather than a simple statement of a > variable name." > > Can someone suggest a better solution? > > Dan > > p.s. Or you could do this > > #+begin_src octave :session *out* :var vec=test > vecb=vec; > ans=vecb > #+end_src > > #+begin_src octave :session *out* :var vec=test > vecb=vec; > ans=vecb > ans > #+end_src > Thank you for the help. I will use it as it works clearly clearly well. Following exchange you have with Juan Pechiar related to the way the output is displayed, I would like to submit the following examples : First test : --8<---------------cut here---------------start------------->8--- #+tblname: test | 1 | 2 | 3 | #+source: outtest #+begin_src octave :session *out* :var vec=test :results value vector vecb=[vec]; ans=vecb; #+end_src --8<---------------cut here---------------end--------------->8--- The output is the following : #+results: outtest | 1.00000000e+000 2.00000000e+000 3.00000000e+000 | It is considered as one character and each element are not clearly splitted in table. Certainly handled as string as Juan Pechiar. Second test : --8<---------------cut here---------------start------------->8--- #+tblname: test | 1 | 2 | 3 | #+source: outtestb #+begin_src octave :session *out* :var vec=test :results value vector vecb=[vec;vec]; ans=vecb; #+end_src --8<---------------cut here---------------end--------------->8--- The output is the following : #+results: outtestb | 1.00000000e+000 | 2.00000000e+000 | 3.00000000e+000 | | 1.00000000e+000 | 2.00000000e+000 | 3.00000000e+000 | This time output is splitted in a table as it should be ? ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [BABEL] Output with octave 2010-08-02 9:30 ` [BABEL] Output with octave d.tchin @ 2010-08-04 4:15 ` Dan Davison 0 siblings, 0 replies; 13+ messages in thread From: Dan Davison @ 2010-08-04 4:15 UTC (permalink / raw) To: d.tchin; +Cc: emacs-orgmode Hi, d.tchin <d.tchin@voila.fr> writes: > Hi, > > Dan Davison <davison <at> stats.ox.ac.uk> writes: > >> >> Eric S Fraga <ucecesf <at> ucl.ac.uk> writes: >> >> > On Fri, 23 Jul 2010 16:59:43 +0000 (UTC), d.tchin <d.tchin <at> voila.fr> > wrote: [...] >> So the current workaround is to say "when using octave, you must end >> your block with a computation, rather than a simple statement of a >> variable name." >> >> Can someone suggest a better solution? >> >> Dan >> >> p.s. Or you could do this >> >> #+begin_src octave :session *out* :var vec=test >> vecb=vec; >> ans=vecb >> #+end_src >> >> #+begin_src octave :session *out* :var vec=test >> vecb=vec; >> ans=vecb >> ans >> #+end_src >> > > > Thank you for the help. I will use it as it works clearly clearly well. > > Following exchange you have with Juan Pechiar related to the way the output > is displayed, I would like to submit the following examples : > > First test : > > > #+tblname: test > | 1 | 2 | 3 | > > #+source: outtest > #+begin_src octave :session *out* :var vec=test :results value vector > vecb=[vec]; > ans=vecb; > #+end_src > > > The output is the following : > > > #+results: outtest > | 1.00000000e+000 2.00000000e+000 3.00000000e+000 | > > > It is considered as one character and each element are not clearly > splitted in table. Certainly handled as string as Juan Pechiar. Thanks for that. It should be fixed now. I have changed octave and matlab so that they now write their data to file using dlmwrite rather than save -ascii. Dan > > > Second test : > > > #+tblname: test > | 1 | 2 | 3 | > > #+source: outtestb > #+begin_src octave :session *out* :var vec=test :results value vector > vecb=[vec;vec]; > ans=vecb; > #+end_src > > > The output is the following : > > #+results: outtestb > | 1.00000000e+000 | 2.00000000e+000 | 3.00000000e+000 | > | 1.00000000e+000 | 2.00000000e+000 | 3.00000000e+000 | > > This time output is splitted in a table as it should be ? > > > > > > > _______________________________________________ > 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 ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2010-08-04 15:15 UTC | newest] Thread overview: 13+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-07-23 16:59 [BABEL] Output with octave d.tchin 2010-07-23 23:12 ` Eric S Fraga 2010-07-26 14:25 ` d.tchin 2010-08-01 18:18 ` Dan Davison 2010-08-01 20:07 ` Re: [BABEL] Output with octave + [PATCH] x2 Juan 2010-08-01 20:22 ` Re: [BABEL] Output with octave [PATCH] Juan Pechiar 2010-08-04 4:18 ` Dan Davison 2010-08-04 15:15 ` d.tchin 2010-08-01 22:19 ` [BABEL] Output with octave + [PATCH] x2 Dan Davison 2010-08-01 22:55 ` [BABEL] Octave issues Juan 2010-08-01 23:32 ` Dan Davison 2010-08-02 9:30 ` [BABEL] Output with octave d.tchin 2010-08-04 4:15 ` 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).