[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] input data for babel blocks
From: |
Eric Schulte |
Subject: |
Re: [O] input data for babel blocks |
Date: |
Tue, 01 Oct 2013 05:58:02 -0600 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Alan Schmitt <address@hidden> writes:
> Hi Charles,
>
> address@hidden writes:
>
>> Lacking that, another alternative to the approach you have crafted is to
>> use elisp src blocks to set up the commands needed to create the objects,
>> and then place the results of executing the elisp src block in the src
>> block of your favored language using noweb, for example
>>
>> #+BEGIN_SRC mylang :noweb yes
>> <<elisp-conversion-to-mylang("arg1","arg2")>>
>> #+END_SRC
>>
>> might convert 'arg2' to an object of the desired type named 'arg1' in a
>> 'mylang' src block.
>
> This looks like a very powerful approach, but it's a bit beyond my
> understanding of babel (which is limited) and noweb (whose existence I
> just discovered after reading http://orgmode.org/manual/noweb.html).
>
> The way I understand it is:
> - there is somewhere in the file a "elisp-conversion-to-mylang"
> function;
> - upon export or evaluation or tangling, it will be expanded in the body
> of the source block;
> - it will then be evaluated in the source block.
>
> What I don't understand is:
> - how to define this function;
It is not a function name, it is a code block name. See the noweb
section of the Org-mode manual for more information.
>
> - will it be evaluated as a "mylang" function or as a function in the
> language it is defined?
>
> In other words, do we have "evaluate elisp-conversion-to-mylang in its
> language then substitute the results in the noweb block" or "substitute
> the function in the noweb block then evaluate it"?
>
see above
>
> If you have an example that uses different languages, I'd love to look
> at it. I'll then try to write an example for ocaml.
>
#+name: data
| x | 2 |
| y | 4 |
#+name: table-as-array
#+begin_src sh :var data=data :results verbatim
echo "$data"|sed 's/\s/ /;s/^/ [/;s/$/]/;1 s/^\s\+/(setf it [/; $
s/$/])/'
#+end_src
#+RESULTS: table-as-array
: (setf it [[x 2]
: [y 4]])
#+begin_src emacs-lisp :noweb yes
<<table-as-array(data)>>
(aref (aref it 1) 1)
#+end_src
#+RESULTS:
: 4
Hope this Helps,
>
> Thanks,
>
> Alan
>
--
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D