From: Torsten Wagner <torsten.wagner@gmail.com>
To: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: [babel] How-to realise a simplified usage scenario?
Date: Fri, 25 Feb 2011 16:21:13 +0900 [thread overview]
Message-ID: <4D675869.9030004@gmail.com> (raw)
Hi,
I tried to use org-babel (particular with python) several times.
However, I always struggled with the amount of options and it take me
long time to get it right.
I would like to describe my personal perfect scenario and hope that some
of those points could find a way into babel.
Basically, I would like to use org-babel for some kind of literate
programming. It has not to produce publishing ready manuscripts (maybe,
this might be a final goal). Basically, I would like to keep my more
technically notes together with my calculations. Basically I want
something like this
---------------- Example--------------------------
* My problem
This is my problem description and I might use all kind of org-madness
to describe it, add todos, deadlines, tag it, add tables and links, etc.
At the beginning I might call some initialisation code
#+begin_src sessionname
#!/usr/bin/env python
#import modules
import numpy as py
from myreadfile import *
# global variables
constant1 = 5
loaddata("data")
y=5
#+end_src
After even more org-mode text, I come to the point to do some calculus
#+begin_src sessionname :export
def myfunction(x=1):
# x is a parameter
c1 = 1e-4
c2 = 3
c3 = 1e6
b = 3
return c1*x**3+c2*x**2+c3*x**x+b
#+end_src
I just continue writing to say what I just did. Now I want to state that
myfunction result in <<var_sessioname[%2.3g]{myfunction(10)}>>. Which
gives me the return value of myfunction for x = 10 and formats it into
scientific notation. I also could write <<var_sessionname{y}>> which
would be replaced by the standard integer representation 5.
Sure I could write <<var_sessionname[%2.3g]{myfunction(y)}>> as well to
get the result of my function for the variable y which I defined in the
first code block. I could even create a new variable on the fly
<<src_sessionname{z=5}>> print it z= <<var_sessionname{z}>> and show the
result for myfunction: <<var_sessionname{myfunction(z)}>>.
I could even switch to another language (however, I doubt that this is
often the case). Either by direct replacement and taking care of the
formatting manually
#+begin_src elisp_session
#!/usr/bin/emacs --script
(setq a 3)
(setq b <<var_sessioname{y}>>)
(message "%+3.5f" (* a b))
#+end_src
or (esp. for more complex inputs) by additional use of helper functions
defined for the target language
#+begin_src elisp_session
#!/usr/bin/emacs --script
(setq a 3)
(setq b (<<var_sessioname[elisp:integer]{y}>>))
(message "%+3.5f" (* a b))
#+end_src
which would take care to place it in the source code block with the
correct target syntax.
--------------------End Example-------------------------------
The key-points are:
* All code blocks belong to a session to allow sharing namespace
* The entire code is still written in a way to execute it "stand-alone"
if tangled, the tangle operation could replace var_sessionname commands
by appropriate print commands in the target language. Functions are real
valid functions of the target language.
* no need to specify the language over and over again since it can be
found by reading the shebang for each session
* var_sessionname commands define were to place output of the target
language and how to format it. Formatting and output could be realized
in the native target language which then returns an appropriate
raw-orgmode string. This would even allow complex scenarios like
embedding a plot created in the target language without the need for the
user to know about that.
* C-c C-c somewhere in a code block refresh the entire session.
Honestly, I had to much problems with python errors due to old running
sessions which were only partially updated and a confused python
interpreter. Keep it simple, close any old session, open a new, rerun
the code. If source code gets to long and computation takes to much time
people might consider to split it into different sessions.
* Tangeling the code could be a org-export function with options to save
it in a file, open it in a buffer or execute it e.g., in ipython
In a similar way like for other exports C-c C-e 1 c (c for code export)
would tangle only the session to which the code under the pointer
belongs and C-c C-e c exports all sessions in different buffers, etc.
* Parts of the source code blocks which should appear in export are
simply marked :export all other will not be exported no resuls will be
exported unlike they are explicit called via the var_sessioname command.
I'm aware that babel can do some of the above points already. However,
at least for python is is still very rough sometimes.
I like babel and I really would like to express my grateful thanks to
the developers but I really have a hard time to use it and would like to
see some more simplified usage.
Hope I have hit a few good points...
Torsten
next reply other threads:[~2011-02-25 7:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-25 7:21 Torsten Wagner [this message]
2011-02-26 0:47 ` [babel] How-to realise a simplified usage scenario? Eric Schulte
2011-02-28 9:43 ` Torsten Wagner
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D675869.9030004@gmail.com \
--to=torsten.wagner@gmail.com \
--cc=emacs-orgmode@gnu.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.