emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Dan Davison <davison@stats.ox.ac.uk>
To: Darlan Cavalcante Moreira <darcamo@gmail.com>
Cc: etimecowboy <etimecowboy@googlemail.com>, emacs-orgmode@gnu.org
Subject: Re: Re: org-babel matlab example
Date: Tue, 14 Sep 2010 16:40:48 +0100	[thread overview]
Message-ID: <87r5gwbaf3.fsf@stats.ox.ac.uk> (raw)
In-Reply-To: <4c8e1c34.14c2640a.1e85.21cc@mx.google.com> (Darlan Cavalcante Moreira's message of "Sun, 12 Sep 2010 11:58:28 -0300")

Darlan Cavalcante Moreira <darcamo@gmail.com> writes:

> Can I leave a suggestion here?
> Maybe a header argument
> ,----
> | :return variableName
> `----
> could be interesting in org babel. This would make babel behavior more
> uniform in all supported languages and avoid the necessity of adding code
> "only to make babel work".

Hi Darlan,

Thanks (and sorry if you've made this suggestion previously, which I
seem to recall). I can see that this would be particularly natural for
matlab/octave in which (aIui) function definitions require specifying
the name of the variable whose value is to be returned. In other
languages which I've encountered, return values are determined by either
"return" statements, or the value of the last statement in the function,
or both of these mechanisms. So if we were to apply your suggestion to
all languages, one could argue that it would permit un-natural code in
languages other than matlab/octave. As you say, we do want things to be
uniform across languages, but perhaps there is an argument for
restricting your suggestion to matlab/octave?

Dan

>
> --
> Darlan
>
> At Sun, 12 Sep 2010 08:45:40 +0100 (BST),
> etimecowboy <etimecowboy@googlemail.com> wrote:
>> 
>> From: Dan Davison <davison@stats.ox.ac.uk>
>> Subject: Re: org-babel matlab example
>> Date: Sat, 11 Sep 2010 12:23:17 -0400
>> 
>> > Dan Davison <davison@stats.ox.ac.uk> writes:
>> > 
>> >> etimecowboy <etimecowboy@googlemail.com> writes:
>> >>
>> >>> Hi everybody,
>> >>>
>> >>> I am learning to use org-babel to evaluate in-line Matlab code block,
>> >>> but I cannot make it works when I press the "C-c C-c", nor "C-c C-v
>> >>> e".
>> >>
>> >> What happens when you try C-c C-c or C-c C-v e ? There is an issue with
>> >> matlab and octave: they return the value of the last /unassigned/
>> >> computation
>> > 
>> > A better way to say this is: they return the value of the special
>> > variable "ans". So whatever you do, at the end of the block you need to
>> > ensure that "ans" has the value that you want returned.
>> > 
>> > I've updated the Worg page on Matlab and Octave:
>> > 
>> > http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-octave-matlab.php
>> > 
>> > Dan
>> > 
>> > 
>> >>, so simply ending the code block with a variable name "x" is
>> >> not enough. Could you try one of the following schemes please, and let
>> >> us know if that solves it:
>> >>
>> >> #+begin_src matlab :exports results
>> >> n = [1:10];
>> >> x = 5*n+4;
>> >> ans = x
>> >> #+end_src
>> >>
>> >> #+begin_src matlab :exports results
>> >> n = [1:10];
>> >> x = 5*n+4;
>> >> x + 0
>> >> #+end_src
>> >>
>> >>
>> >>> The export of code works, but the results was not there. My in-line code is like this:
>> >>
>> >> There was a little typo in your original block: the keyword is
>> >> ":exports" with an s.
>> >>
>> >> Dan
>> >>
>> >>>
>> >>> #+begin_src matlab :export results
>> >>> n = [1:10];
>> >>> x = 5*n+4;
>> >>> x
>> >>> #+end_src
>> >>>
>> >>> Is there someone can provide me a working example? Thanks a lot.
>> >>>
>> >>>
>> >>> -----------------------------
>> >>>
>> >>> etimecowboy@gmail.com
>> >>>
>> >>>       _.,----,._
>> >>>     .:'        `:.
>> >>>   .'              `.
>> >>>  .'                `.
>> >>>  :                  :
>> >>>  `    .'`':'`'`/    '
>> >>>   `.   \  |   /   ,'
>> >>>     \   \ |  /   /
>> >>>      `\_..,,.._/'
>> >>>       {`'-,_`'-}
>> >>>       {`'-,_`'-}
>> >>>       {`'-,_`'-}
>> >>>        `YXXXXY'
>> >>>          ~^^~
>> >>>
>> >>> _______________________________________________
>> >>> 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
>> >>
>> >> _______________________________________________
>> >> 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
>> 
>> Dear Dan,
>> 
>> I have checked the Worg page you updated and tried your example. It works! The ans variable is the secret! Thanks a lot. I suggest org should provide some examples in its user's guide, not only on the topic of Babel but also Table, Hyperlink, Picture, and etc.
>> 
>> -----------------------------
>> 
>> etimecowboy@gmail.com
>> 
>>       _.,----,._
>>     .:'        `:.
>>   .'              `.
>>  .'                `.
>>  :                  :
>>  `    .'`':'`'`/    '
>>   `.   \  |   /   ,'
>>     \   \ |  /   /
>>      `\_..,,.._/'
>>       {`'-,_`'-}
>>       {`'-,_`'-}
>>       {`'-,_`'-}
>>        `YXXXXY'
>>          ~^^~
>> 
>> _______________________________________________
>> 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

  reply	other threads:[~2010-09-14 15:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-11  9:18 org-babel matlab example etimecowboy
2010-09-11 15:29 ` Dan Davison
2010-09-11 16:23   ` Dan Davison
2010-09-12  7:45     ` etimecowboy
2010-09-12 14:58       ` Darlan Cavalcante Moreira
2010-09-14 15:40         ` Dan Davison [this message]
2010-09-14 18:19           ` Achim Gratz
2010-09-14 20:14             ` Achim Gratz
2010-09-14 18:23           ` Darlan Cavalcante Moreira
2010-09-16  3:35             ` etimecowboy
2010-09-16  6:32               ` Dan Davison

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r5gwbaf3.fsf@stats.ox.ac.uk \
    --to=davison@stats.ox.ac.uk \
    --cc=darcamo@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=etimecowboy@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).