Re: [O] babel: is it possible to cache #+call executed blocks

2012-08-03 Thread Eric Schulte
a...@arne-koehn.de (Arne Köhn) writes:

> co...@online.de (Jonas Hörsch) writes:
>
>> i'm looking for a possibilty to call lengthy codeblocks a few times with
>> different parameters, but would like the results to be cached.
>

Use #+call lines with the :cache header argument set.  With a recent
version of Org-mode the following should work as expected.

#+Title: An Example of Using the Cache Header Argument with Call Lines

A long running code block.
#+name: foo
#+begin_src emacs-lisp :var bar="baz"
  (sit-for 5)
  (message "bar=%S" bar)
#+end_src

#+RESULTS: foo
: bar="baz"

This returns immediately thanks to the cached result.
#+call: foo("qux") :cache yes

#+RESULTS[49bbb37e59694c557889ca8fd4b06fe0d4fb6b25]: foo("qux"):cache yes
: bar="qux"

This does not return immediately, because the block must execute.
#+call: foo("quxxx")

-- 
Eric Schulte
http://cs.unm.edu/~eschulte


Re: [O] babel: is it possible to cache #+call executed blocks

2012-08-03 Thread Arne Köhn
co...@online.de (Jonas Hörsch) writes:

> i'm looking for a possibilty to call lengthy codeblocks a few times with
> different parameters, but would like the results to be cached.

It's probably a bit late, but I stumbled over the same problem. Here is
how I dealt with it (it's not that pretty).

Instead of

,
|  #+call foofunc(bar=baz)
`

I wrote a emacs-lisp block doing the same:

,
| #+name: speak_world
| #+begin_src emacs-lisp :cache yes
|   (save-excursion
| (goto-char (org-babel-find-named-block "speak"))
| (org-babel-execute-src-block nil nil '((:var "say=world")))
|   )
| #+end_src
`

In contrast to #+call, this results in a cached result for foo_bar that
can be accessed later on.

The disadvantages:
 - the cached result will never be invalidated (since foo_bar doesn't
   change)
 - somehow the variable bar will not be "baz" but "baz=", I changed my
   code block to strip the trailing "=".

If someone could point out where this "=" comes from: please tell me!


Arne



[O] babel: is it possible to cache #+call executed blocks

2012-06-28 Thread Jonas Hörsch
Hello everyone,

i'm looking for a possibilty to call lengthy codeblocks a few times with
different parameters, but would like the results to be cached.

hopefully wiw becomes clear enough with a minimal example.

the code block speak, if directly evaluated, produces the correct result
hallo on the first run. all subsequent runs just return immediately,
until the code block is changed.

if one evaluates the #+call line, as expected the right result is
returned and the hash necessary for caching is added to #+RESULTS.
but subsequent evaluations always seem to evaluate the code block again,
i.e. one has to wait the 5 seconds.

is there a way to avoid this?

thanks,
jonas

#+begin_src org

* Test
#+name: speak
#+begin_src sh :var say="hallo" :results output :cache yes
echo $say
sleep 5
#+end_src

#+RESULTS[4370bde991d63488bcb6d297718919fcf2b4fa1f]: speak
: hallo

#+call: speak('welt') :cache yes

#+RESULTS[c393aea840734e972880a4a38512765d345e7125]: speak('welt'):cache yes
: welt

#+end_src