* How do I chain babel blocks with arguments?
@ 2014-04-16 17:04 Alan Schmitt
2014-04-16 20:49 ` Charles Berry
2014-04-17 5:42 ` Eric Schulte
0 siblings, 2 replies; 14+ messages in thread
From: Alan Schmitt @ 2014-04-16 17:04 UTC (permalink / raw)
To: emacs-orgmode
Hello,
I have several babel blocks that each work well, but I'm now trying to
chain them to build some bigger functionality out of them. I'm having
trouble finding out how to pass arguments between blocks. Here is
a small example:
--8<---------------cut here---------------start------------->8---
#+name: test1
#+begin_src emacs-lisp :var x="foo"
x
#+end_src
#+name:test2
#+begin_src emacs-lisp :var z="bar" :var y=test1(x=z)
y
#+end_src
#+call: test2(z="baz")
--8<---------------cut here---------------end--------------->8---
Unfortunately this does not work: the evaluation of block `test2' fails
by telling me `z' does not exist.
How can I execute block `test1' from block `test2' by passing an
argument that is one from test2?
Thanks,
Alan
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How do I chain babel blocks with arguments?
2014-04-16 17:04 How do I chain babel blocks with arguments? Alan Schmitt
@ 2014-04-16 20:49 ` Charles Berry
2014-04-17 10:11 ` Alan Schmitt
2014-04-17 5:42 ` Eric Schulte
1 sibling, 1 reply; 14+ messages in thread
From: Charles Berry @ 2014-04-16 20:49 UTC (permalink / raw)
To: emacs-orgmode
Alan Schmitt <alan.schmitt <at> polytechnique.org> writes:
>
> Hello,
>
> I have several babel blocks that each work well, but I'm now trying to
> chain them to build some bigger functionality out of them. I'm having
> trouble finding out how to pass arguments between blocks. Here is
> a small example:
>
> --8<---------------cut here---------------start------------->8---
> #+name: test1
> #+begin_src emacs-lisp :var x="foo"
> x
> #+end_src
>
> #+name:test2
> #+begin_src emacs-lisp :var z="bar" :var y=test1(x=z)
> y
> #+end_src
>
> #+call: test2(z="baz")
> --8<---------------cut here---------------end--------------->8---
>
> Unfortunately this does not work: the evaluation of block `test2' fails
> by telling me `z' does not exist.
>
> How can I execute block `test1' from block `test2' by passing an
> argument that is one from test2?
This is not pretty, but it works:
#+name:test2
#+begin_src emacs-lisp :var z="bar"
(let ((y (org-sbe test1 (x (intern z)))))
y)
#+end_src
HTH,
Chuck
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How do I chain babel blocks with arguments?
2014-04-16 20:49 ` Charles Berry
@ 2014-04-17 10:11 ` Alan Schmitt
2014-04-17 10:24 ` Thorsten Jolitz
0 siblings, 1 reply; 14+ messages in thread
From: Alan Schmitt @ 2014-04-17 10:11 UTC (permalink / raw)
To: Charles Berry; +Cc: emacs-orgmode
Hello Charles,
On 2014-04-16 22:49, Charles Berry <ccberry@ucsd.edu> writes:
>> I have several babel blocks that each work well, but I'm now trying to
>> chain them to build some bigger functionality out of them. I'm having
>> trouble finding out how to pass arguments between blocks. Here is
>> a small example:
>>
>> --8<---------------cut here---------------start------------->8---
>> #+name: test1
>> #+begin_src emacs-lisp :var x="foo"
>> x
>> #+end_src
>>
>> #+name:test2
>> #+begin_src emacs-lisp :var z="bar" :var y=test1(x=z)
>> y
>> #+end_src
>>
>> #+call: test2(z="baz")
>> --8<---------------cut here---------------end--------------->8---
>>
>> Unfortunately this does not work: the evaluation of block `test2' fails
>> by telling me `z' does not exist.
>>
>> How can I execute block `test1' from block `test2' by passing an
>> argument that is one from test2?
>
> This is not pretty, but it works:
>
> #+name:test2
> #+begin_src emacs-lisp :var z="bar"
> (let ((y (org-sbe test1 (x (intern z)))))
> y)
> #+end_src
Thank you for the suggestion, but it returns a symbol and not the
string. In the more complex setting I'm playing with I need a string
there.
By the way, this is something that I really don't understand about sbe:
what is allowed as functions inside it? If I do the simple
--8<---------------cut here---------------start------------->8---
#+name:test2
#+begin_src emacs-lisp :var z="bar"
(let ((y (org-sbe test1 (x z))))
y)
#+end_src
--8<---------------cut here---------------end--------------->8---
then it fails, telling me 'z' does not exist. But for some reason,
adding "intern" lets 'z' get the "bar" value and be converted to the bar
symbol.
Is there documentation about what is allowed in sbe? (I had another
similar problem recently, see
http://thread.gmane.org/gmane.emacs.orgmode/84522).
Thanks,
Alan
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How do I chain babel blocks with arguments?
2014-04-17 10:11 ` Alan Schmitt
@ 2014-04-17 10:24 ` Thorsten Jolitz
2014-04-17 11:37 ` Alan Schmitt
0 siblings, 1 reply; 14+ messages in thread
From: Thorsten Jolitz @ 2014-04-17 10:24 UTC (permalink / raw)
To: emacs-orgmode
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>> #+name:test2
>> #+begin_src emacs-lisp :var z="bar"
>> (let ((y (org-sbe test1 (x (intern z)))))
>> y)
>> #+end_src
>
> Thank you for the suggestion, but it returns a symbol and not the
> string. In the more complex setting I'm playing with I need a string
> there.
w/o knowing what this thread is about (since I did not follow it) I
would say that all you need is
,----------------
| (symbol-name y)
`----------------
as last expression.
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How do I chain babel blocks with arguments?
2014-04-17 10:24 ` Thorsten Jolitz
@ 2014-04-17 11:37 ` Alan Schmitt
0 siblings, 0 replies; 14+ messages in thread
From: Alan Schmitt @ 2014-04-17 11:37 UTC (permalink / raw)
To: Thorsten Jolitz; +Cc: emacs-orgmode
On 2014-04-17 12:24, Thorsten Jolitz <tjolitz@gmail.com> writes:
> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>
>>> #+name:test2
>>> #+begin_src emacs-lisp :var z="bar"
>>> (let ((y (org-sbe test1 (x (intern z)))))
>>> y)
>>> #+end_src
>>
>> Thank you for the suggestion, but it returns a symbol and not the
>> string. In the more complex setting I'm playing with I need a string
>> there.
>
> w/o knowing what this thread is about (since I did not follow it) I
> would say that all you need is
>
> ,----------------
> | (symbol-name y)
> `----------------
>
> as last expression.
Thanks, this helped me much!
So the solution is to use "eval", which seems to be interpreted by
org-sbe:
--8<---------------cut here---------------start------------->8---
#+name: test1
#+begin_src emacs-lisp :var x="foo"
x
#+end_src
#+name: test2
#+begin_src emacs-lisp :var z="bar"
(let ((y (org-sbe test1 (x (eval z)))))
y)
#+end_src
#+results: test2
: bar
#+call: test2(z="baz")
#+results:
: baz
--8<---------------cut here---------------end--------------->8---
I still would really like what can (and cannot) be done with sbe, but
this should be enough to let me make progress.
Thanks again,
Alan
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How do I chain babel blocks with arguments?
2014-04-16 17:04 How do I chain babel blocks with arguments? Alan Schmitt
2014-04-16 20:49 ` Charles Berry
@ 2014-04-17 5:42 ` Eric Schulte
2014-04-18 6:43 ` Alan Schmitt
1 sibling, 1 reply; 14+ messages in thread
From: Eric Schulte @ 2014-04-17 5:42 UTC (permalink / raw)
To: Alan Schmitt; +Cc: emacs-orgmode
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> Hello,
>
> I have several babel blocks that each work well, but I'm now trying to
> chain them to build some bigger functionality out of them. I'm having
> trouble finding out how to pass arguments between blocks. Here is
> a small example:
>
> --8<---------------cut here---------------start------------->8---
> #+name: test1
> #+begin_src emacs-lisp :var x="foo"
> x
> #+end_src
>
> #+name:test2
> #+begin_src emacs-lisp :var z="bar" :var y=test1(x=z)
> y
> #+end_src
>
> #+call: test2(z="baz")
> --8<---------------cut here---------------end--------------->8---
>
> Unfortunately this does not work: the evaluation of block `test2' fails
> by telling me `z' does not exist.
>
> How can I execute block `test1' from block `test2' by passing an
> argument that is one from test2?
>
#+name: z
: bar
#+name: test1
#+begin_src emacs-lisp :var x="foo"
x
#+end_src
#+name:test2
#+begin_src emacs-lisp :var y=test1(x=z)
y
#+end_src
#+RESULTS: test2
: bar
Best, Eric
>
> Thanks,
>
> Alan
>
--
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How do I chain babel blocks with arguments?
2014-04-17 5:42 ` Eric Schulte
@ 2014-04-18 6:43 ` Alan Schmitt
2014-04-20 1:41 ` Eric Schulte
0 siblings, 1 reply; 14+ messages in thread
From: Alan Schmitt @ 2014-04-18 6:43 UTC (permalink / raw)
To: Eric Schulte; +Cc: emacs-orgmode
Hi Eric,
On 2014-04-17 07:42, Eric Schulte <schulte.eric@gmail.com> writes:
> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>
>> How can I execute block `test1' from block `test2' by passing an
>> argument that is one from test2?
>>
>
> #+name: z
> : bar
> #+name: test1
> #+begin_src emacs-lisp :var x="foo"
> x
> #+end_src
>
> #+name:test2
> #+begin_src emacs-lisp :var y=test1(x=z)
> y
> #+end_src
> #+RESULTS: test2
> : bar
Thank you for the suggestion, but I'm afraid it does not do what I want:
I cannot pass a different argument 'z' to test2 (called test4 in the
following snippet):
--8<---------------cut here---------------start------------->8---
#+name: z
: "bar"
#+name: test3
#+begin_src emacs-lisp :var x="foo"
x
#+end_src
#+name:test4
#+begin_src emacs-lisp :var y=test1(x=z)
y
#+end_src
#+results: test4
: "bar"
#+call: test4(z="BAZ")
#+results:
: "bar"
--8<---------------cut here---------------end--------------->8---
In this case, org-sbe works great, and I've been able to achieve what
I want. I still need to clean it up before describing it to the list.
Thanks again,
Alan
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How do I chain babel blocks with arguments?
2014-04-18 6:43 ` Alan Schmitt
@ 2014-04-20 1:41 ` Eric Schulte
2014-04-20 3:33 ` Xebar Saram
2014-04-22 6:53 ` Alan Schmitt
0 siblings, 2 replies; 14+ messages in thread
From: Eric Schulte @ 2014-04-20 1:41 UTC (permalink / raw)
To: Alan Schmitt; +Cc: emacs-orgmode, Eric Schulte
> --8<---------------cut here---------------start------------->8---
> #+name: z
> : "bar"
> #+name: test3
> #+begin_src emacs-lisp :var x="foo"
> x
> #+end_src
>
> #+name:test4
> #+begin_src emacs-lisp :var y=test1(x=z)
> y
> #+end_src
>
> #+results: test4
> : "bar"
>
> #+call: test4(z="BAZ")
^
The above line has an error, your "z" should be an "x".
Best,
--
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How do I chain babel blocks with arguments?
2014-04-20 1:41 ` Eric Schulte
@ 2014-04-20 3:33 ` Xebar Saram
2014-04-21 1:22 ` Eric Schulte
2014-04-22 6:53 ` Alan Schmitt
1 sibling, 1 reply; 14+ messages in thread
From: Xebar Saram @ 2014-04-20 3:33 UTC (permalink / raw)
To: Eric Schulte, tjolitz; +Cc: Alan Schmitt, emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1007 bytes --]
Hi guys
a related newbie question that occurred to me from reading this thread
(sorry for "crashing" the thread :)). if i understand correctly from the
above posts, is there a way to batch evaluate multiple org mode code blocks
at once?
My use case is using babel with R statistics where i have multiple code
blocks and would like to run 10-12 blocks together in a consecutive order,
is that possible? if so how is this done?
best
Z
On Sun, Apr 20, 2014 at 4:41 AM, Eric Schulte <schulte.eric@gmail.com>wrote:
> > --8<---------------cut here---------------start------------->8---
> > #+name: z
> > : "bar"
> > #+name: test3
> > #+begin_src emacs-lisp :var x="foo"
> > x
> > #+end_src
> >
> > #+name:test4
> > #+begin_src emacs-lisp :var y=test1(x=z)
> > y
> > #+end_src
> >
> > #+results: test4
> > : "bar"
> >
> > #+call: test4(z="BAZ")
> ^
> The above line has an error, your "z" should be an "x".
>
> Best,
>
> --
> Eric Schulte
> https://cs.unm.edu/~eschulte
> PGP: 0x614CA05D
>
>
[-- Attachment #2: Type: text/html, Size: 1742 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How do I chain babel blocks with arguments?
2014-04-20 3:33 ` Xebar Saram
@ 2014-04-21 1:22 ` Eric Schulte
0 siblings, 0 replies; 14+ messages in thread
From: Eric Schulte @ 2014-04-21 1:22 UTC (permalink / raw)
To: Xebar Saram; +Cc: emacs-orgmode, Alan Schmitt, tjolitz
Xebar Saram <zeltakc@gmail.com> writes:
> Hi guys
>
> a related newbie question that occurred to me from reading this thread
> (sorry for "crashing" the thread :)). if i understand correctly from the
> above posts, is there a way to batch evaluate multiple org mode code blocks
> at once?
> My use case is using babel with R statistics where i have multiple code
> blocks and would like to run 10-12 blocks together in a consecutive order,
> is that possible? if so how is this done?
>
Yes. See `org-babel-execute-buffer' and `org-babel-execute-subtree'.
Best,
>
> best
>
> Z
>
>
> On Sun, Apr 20, 2014 at 4:41 AM, Eric Schulte <schulte.eric@gmail.com>wrote:
>
>> > --8<---------------cut here---------------start------------->8---
>> > #+name: z
>> > : "bar"
>> > #+name: test3
>> > #+begin_src emacs-lisp :var x="foo"
>> > x
>> > #+end_src
>> >
>> > #+name:test4
>> > #+begin_src emacs-lisp :var y=test1(x=z)
>> > y
>> > #+end_src
>> >
>> > #+results: test4
>> > : "bar"
>> >
>> > #+call: test4(z="BAZ")
>> ^
>> The above line has an error, your "z" should be an "x".
>>
>> Best,
>>
>> --
>> Eric Schulte
>> https://cs.unm.edu/~eschulte
>> PGP: 0x614CA05D
>>
>>
--
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How do I chain babel blocks with arguments?
2014-04-20 1:41 ` Eric Schulte
2014-04-20 3:33 ` Xebar Saram
@ 2014-04-22 6:53 ` Alan Schmitt
2014-04-22 11:30 ` Eric Schulte
1 sibling, 1 reply; 14+ messages in thread
From: Alan Schmitt @ 2014-04-22 6:53 UTC (permalink / raw)
To: Eric Schulte; +Cc: emacs-orgmode
Hi Eric,
On 2014-04-20 03:41, Eric Schulte <schulte.eric@gmail.com> writes:
>> --8<---------------cut here---------------start------------->8---
>> #+name: z
>> : "bar"
>> #+name: test3
>> #+begin_src emacs-lisp :var x="foo"
>> x
>> #+end_src
>>
>> #+name:test4
>> #+begin_src emacs-lisp :var y=test1(x=z)
>> y
>> #+end_src
>>
>> #+results: test4
>> : "bar"
>>
>> #+call: test4(z="BAZ")
> ^
> The above line has an error, your "z" should be an "x".
I tried this change, and the argument is not taken into account:
--8<---------------cut here---------------start------------->8---
#+call: test4(x="BAZ")
#+results:
: "bar"
--8<---------------cut here---------------end--------------->8---
I'm not sure I mentioned it earlier, but I found a workaround using
`org-sbe'.
Thanks,
Alan
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How do I chain babel blocks with arguments?
2014-04-22 6:53 ` Alan Schmitt
@ 2014-04-22 11:30 ` Eric Schulte
2014-04-22 12:47 ` Alan Schmitt
0 siblings, 1 reply; 14+ messages in thread
From: Eric Schulte @ 2014-04-22 11:30 UTC (permalink / raw)
To: Alan Schmitt; +Cc: emacs-orgmode, Eric Schulte
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> Hi Eric,
>
> On 2014-04-20 03:41, Eric Schulte <schulte.eric@gmail.com> writes:
>
>>> --8<---------------cut here---------------start------------->8---
>>> #+name: z
>>> : "bar"
>>> #+name: test3
>>> #+begin_src emacs-lisp :var x="foo"
>>> x
>>> #+end_src
>>>
>>> #+name:test4
>>> #+begin_src emacs-lisp :var y=test1(x=z)
>>> y
>>> #+end_src
>>>
>>> #+results: test4
>>> : "bar"
>>>
>>> #+call: test4(z="BAZ")
>> ^
>> The above line has an error, your "z" should be an "x".
>
> I tried this change, and the argument is not taken into account:
>
> --8<---------------cut here---------------start------------->8---
> #+call: test4(x="BAZ")
>
> #+results:
> : "bar"
> --8<---------------cut here---------------end--------------->8---
>
Sorry, that's because the "x" should be "z". See the following.
--8<---------------cut here---------------start------------->8---
#+name: z
: "bar"
#+name: test3
#+begin_src emacs-lisp :var x="foo"
x
#+end_src
#+RESULTS: test3
: foo
#+name:test4
#+begin_src emacs-lisp :var y=test3(x=z)
y
#+end_src
#+results: test4
: "bar"
#+call: test4(y="BAZ")
#+RESULTS:
: BAZ
--8<---------------cut here---------------end--------------->8---
>
> I'm not sure I mentioned it earlier, but I found a workaround using
> `org-sbe'.
>
Yes, I had noticed, but simple argument passing is also sufficient.
Best,
>
> Thanks,
>
> Alan
--
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How do I chain babel blocks with arguments?
2014-04-22 11:30 ` Eric Schulte
@ 2014-04-22 12:47 ` Alan Schmitt
2014-04-24 1:16 ` Eric Schulte
0 siblings, 1 reply; 14+ messages in thread
From: Alan Schmitt @ 2014-04-22 12:47 UTC (permalink / raw)
To: Eric Schulte; +Cc: emacs-orgmode
Hi Eric,
On 2014-04-22 13:30, Eric Schulte <schulte.eric@gmail.com> writes:
> Sorry, that's because the "x" should be "z". See the following.
>
> #+name: z
> : "bar"
> #+name: test3
> #+begin_src emacs-lisp :var x="foo"
> x
> #+end_src
>
> #+RESULTS: test3
> : foo
>
> #+name:test4
> #+begin_src emacs-lisp :var y=test3(x=z)
> y
> #+end_src
>
> #+results: test4
> : "bar"
>
> #+call: test4(y="BAZ")
>
> #+RESULTS:
> : BAZ
I'm afraid I'm not being clear: I want to use the result of `test3' in
the computation done to test4. Intuitively, I want test4 to be something
like: "(lambda (x) (... (test3 x) ...))". This is why I was writing
a header of the form:
> #+begin_src emacs-lisp :var x="foo" :var y=test3(x)
where x would be given by the call to the block, and y would only be
used internally.
Thanks,
Alan
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: How do I chain babel blocks with arguments?
2014-04-22 12:47 ` Alan Schmitt
@ 2014-04-24 1:16 ` Eric Schulte
0 siblings, 0 replies; 14+ messages in thread
From: Eric Schulte @ 2014-04-24 1:16 UTC (permalink / raw)
To: Alan Schmitt; +Cc: emacs-orgmode
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> Hi Eric,
>
> On 2014-04-22 13:30, Eric Schulte <schulte.eric@gmail.com> writes:
>
>> Sorry, that's because the "x" should be "z". See the following.
>>
>> #+name: z
>> : "bar"
>> #+name: test3
>> #+begin_src emacs-lisp :var x="foo"
>> x
>> #+end_src
>>
>> #+RESULTS: test3
>> : foo
>>
>> #+name:test4
>> #+begin_src emacs-lisp :var y=test3(x=z)
>> y
>> #+end_src
>>
>> #+results: test4
>> : "bar"
>>
>> #+call: test4(y="BAZ")
>>
>> #+RESULTS:
>> : BAZ
>
> I'm afraid I'm not being clear: I want to use the result of `test3' in
> the computation done to test4. Intuitively, I want test4 to be something
> like: "(lambda (x) (... (test3 x) ...))". This is why I was writing
> a header of the form:
>
>> #+begin_src emacs-lisp :var x="foo" :var y=test3(x)
>
> where x would be given by the call to the block, and y would only be
> used internally.
>
I see, then sbe is probably the way to go.
Best,
>
> Thanks,
>
> Alan
--
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2014-04-24 1:24 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-16 17:04 How do I chain babel blocks with arguments? Alan Schmitt
2014-04-16 20:49 ` Charles Berry
2014-04-17 10:11 ` Alan Schmitt
2014-04-17 10:24 ` Thorsten Jolitz
2014-04-17 11:37 ` Alan Schmitt
2014-04-17 5:42 ` Eric Schulte
2014-04-18 6:43 ` Alan Schmitt
2014-04-20 1:41 ` Eric Schulte
2014-04-20 3:33 ` Xebar Saram
2014-04-21 1:22 ` Eric Schulte
2014-04-22 6:53 ` Alan Schmitt
2014-04-22 11:30 ` Eric Schulte
2014-04-22 12:47 ` Alan Schmitt
2014-04-24 1:16 ` Eric Schulte
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).