Re: [Orgmode][babel] How-to realise a simplified usage scenario?

2011-02-28 Thread Torsten Wagner

Hi Eric,

you are right. All this was just pseudo code to show how I guess it 
could look like not a request to implement it that way.
As I said I'm aware that many of the mentioned tasks could be done by 
org-babel already. I'm a (not very frequent) org-babel user of the first 
hour.
Please let me try to condense my first mail down to different points and 
introduce them one by one


* Introduce a new command or extend the inline src command to return 
values of the target language formatted in org-mode raw data. This 
command would be replaced by the raw-org-mode string on export.


Thus,
var_sessionname[%2.3g]{x} returns the variable x string with scientific 
notation.
var_sessionname[%2.3g,row]{list} returns a table row of values with 
scientific notation
var_sessionname[name: filename.png]{plot_object} saves plot_object into 
a file named filename.png and returns the following

[[file:filename.png]]

This would greatly help to use the results of the source code within the 
org-mode text. As you might see, it might be very nice and helpful to 
write a org-babel support module for the specific target language. e.g., 
python could have a modul org-babel and within this module a command 
org-babel(var) converts the type of variable into a org-mode raw string. 
It would be far more easy to do this in the target language which is 
aware of the nature of its own different objects.
Addtionaly this command can be threaded differently for tangling code. 
If code gets tangled, all commands are converted in approbate print 
commands. E.g. var_sessionname[%2.3g]{x} would be tangled to

print x = %2.3g % x

Hope this is more easy to parse :)

Torsten

CC.
I work on an example of Reproducible Research with org-babel and 
python. This should serve the purpose to explain what I want to do as 
well as serve as a template for my later me and others. As soon as I 
have something usable, I would like to send it to you (or post it here) 
to discuss possible changes. After that you might like to add it to the 
babel-worg website.


On 02/26/2011 09:47 AM, Eric Schulte wrote:

Hi Torsten,

I found this email extremely hard to parse.  Perhaps it would be easier
if you first read through the relevant section of the Org-mode manual
http://orgmode.org/manual/Working-With-Source-Code.html so that you are
aware of what features are already provided by Babel.  Then you could
share how your suggestions are different from the existing Babel
functionality, rather than as a brand new and largely overlapping set of
syntax and functionality.

I hope this request makes sense and is not unreasonable.

Thanks -- Eric

Torsten Wagnertorsten.wag...@gmail.com  writes:


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 invar_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 writevar_sessionname{y}  which
would be replaced by the standard integer representation 5.
Sure I could writevar_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 bvar_sessioname{y})
  

Re: [Orgmode][babel] How-to realise a simplified usage scenario?

2011-02-25 Thread Eric Schulte
Hi Torsten,

I found this email extremely hard to parse.  Perhaps it would be easier
if you first read through the relevant section of the Org-mode manual
http://orgmode.org/manual/Working-With-Source-Code.html so that you are
aware of what features are already provided by Babel.  Then you could
share how your suggestions are different from the existing Babel
functionality, rather than as a brand new and largely overlapping set of
syntax and functionality.

I hope this request makes sense and is not unreasonable.

Thanks -- Eric

Torsten Wagner torsten.wag...@gmail.com writes:

 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 

[Orgmode][babel] How-to realise a simplified usage scenario?

2011-02-24 Thread Torsten Wagner

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

___
Emacs-orgmode