emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Modify a variable before it is passed to babel (or exported)?


From: Ken Mankoff
Subject: [O] Modify a variable before it is passed to babel (or exported)?
Date: Mon, 16 Sep 2019 10:21:41 -0700
User-agent: mu4e 0.9.18; emacs 26.2

I'd like to modify a variable with a babel block before another block sees the 
variable. For example, I always want to add one to a variable:

#+NAME: add-one
#+BEGIN_SRC bash :results verbatim :var data=0
data=$(( data + 1 ))
echo $data
#+END_SRC

#+RESULTS: add_one
: 1

Test it:

#+CALL: add_one(data=42)

#+RESULTS:
: 43

Can I use =add_one= to modify data passed elsewhere?

For example, given 

#+NAME: table
| 42 |

I'm having trouble defining a =print_table= function that prints 43, using the 
=add_one= either via :prologue or <<noweb>> or some other method. Preferably 
prologue because then the add_one function could be in a different language.


I can get halfway to what I want with a :post option, but need this to be a 
:pre or :prologue. Example using :post

#+NAME: python_using_add_one
#+BEGIN_SRC python :results output values :post add-one(data=*this*) 
print(42)
#+END_SRC

#+RESULTS: python_using_add_one
: 43

Any suggestions how to use this feature with :pre or :prologue?

Thanks,

  -k



reply via email to

[Prev in Thread] Current Thread [Next in Thread]