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
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
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
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
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
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
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
> --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 #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 --]
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
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
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
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
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