emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] input data for babel blocks


From: Alan Schmitt
Subject: Re: [O] input data for babel blocks
Date: Tue, 01 Oct 2013 17:16:49 +0200
User-agent: mu4e 0.9.9.5; emacs 24.3.1

address@hidden writes:

> You're close. The noweb ref should be a named src block which is
> executed, not expanded, so, (note the named shell source block and the
> parens in the noweb reference):
>
> #+name: testing
> #+BEGIN_SRC sh :results raw
> echo "["
> ls *.org | sed 's/$/;/'
> echo "]"
> #+END_SRC
>
> #+BEGIN_SRC ocaml :noweb yes
> let x =
> <<testing()>>
> in x
> #+END_SRC

Thanks a lot, that was the missing piece!

So, for the record, here is a way to convert a table as a list of tuples
for use in ocaml. Thanks again to everyone for the help in getting
there.

--8<---------------cut here---------------start------------->8---
#+name: mydata
| x | 1 | 1.4 |
| y | 2 | 4.5 |
| z | 3 | 7.0 |

#+name: table_to_tuple
#+BEGIN_SRC emacs-lisp :results raw :var v='()
  (message 
   (concat "["
           (mapconcat
            (lambda (vlist) 
              (concat "("
                      (mapconcat 
                       (lambda (val) (format "%S" val))
                       vlist
                       ", ")
                      ")"))
            v
            "; ")
           "]"))
#+END_SRC

#+BEGIN_SRC ocaml :noweb yes
let x =
<<table_to_tuple(mydata)>>
in x
#+END_SRC

#+RESULTS:
: - : (string * int * float) list =
: [("x", 1, 1.4); ("y", 2, 4.5); ("z", 3, 7.)]
--8<---------------cut here---------------end--------------->8---



reply via email to

[Prev in Thread] Current Thread [Next in Thread]