* Modify a variable before it is passed to babel (or exported)?
@ 2019-09-16 17:21 Ken Mankoff
2019-09-16 20:02 ` Ken Mankoff
0 siblings, 1 reply; 2+ messages in thread
From: Ken Mankoff @ 2019-09-16 17:21 UTC (permalink / raw)
To: org-mode-email
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Modify a variable before it is passed to babel (or exported)?
2019-09-16 17:21 Modify a variable before it is passed to babel (or exported)? Ken Mankoff
@ 2019-09-16 20:02 ` Ken Mankoff
0 siblings, 0 replies; 2+ messages in thread
From: Ken Mankoff @ 2019-09-16 20:02 UTC (permalink / raw)
To: org-mode-email
Hello,
I solved this with (org-sbe). For example, using "add-one" and "table" from the original email
#+Name: test-add-one
#+BEGIN_SRC python :results output values :var data=(org-sbe add-one (data table))
print(data)
#+END_SRC
#+RESULTS: test-add-one
: 43
Or
src_elisp{(org-sbe add-one (data table))} {{{results(=43=)}}}
-k.
On 2019-09-16 at 10:21 -07, Ken Mankoff <mankoff@gmail.com> wrote...
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-09-16 20:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-16 17:21 Modify a variable before it is passed to babel (or exported)? Ken Mankoff
2019-09-16 20:02 ` Ken Mankoff
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).