r...@rickster.com 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