From: Rami Chowdhury <neca...@gmail.com> Previously, tables (i.e. lists-of-lists) came through as arrays-of-arrays. Since OCaml arrays are required to be homogeneous in their types, this meant tables with heterogenous types within a row could not be handled. This change represents tables as arrays of tuples, which is more flexible, while preserving the previous behavior for lists.
* lisp/ob-ocaml.el (org-babel-ocaml-elisp-to-ocaml-tuple, org-babel-ocaml-elisp-to-ocaml-array, org-babel-elisp-to-ocaml): Send table rows as tuples --- lisp/ob-ocaml.el | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lisp/ob-ocaml.el b/lisp/ob-ocaml.el index 80df795..ad7df97 100644 --- a/lisp/ob-ocaml.el +++ b/lisp/ob-ocaml.el @@ -123,11 +123,23 @@ (org-babel-ocaml-elisp-to-ocaml (cdr pair)))) (org-babel--get-vars params))) +(defun org-babel-ocaml-elisp-to-ocaml-tuple (val &optional nested-renderer-f) + "Return OCaml evaluating to VAL, with elements rendered by NESTED-RENDERER-F." + (let ((renderer (or nested-renderer-f #'org-babel-ocaml-elisp-to-ocaml))) + (concat "(" (mapconcat renderer val ", ") ")"))) + +(defun org-babel-ocaml-elisp-to-ocaml-array (val &optional nested-renderer-f) + "Return OCaml evaluating to VAL, with elements rendered by NESTED-RENDERER-F." + (let ((renderer (or nested-renderer-f #'org-babel-ocaml-elisp-to-ocaml))) + (concat "[|" (mapconcat renderer val "; ") "|]"))) + (defun org-babel-ocaml-elisp-to-ocaml (val) "Return a string of ocaml code which evaluates to VAL." - (if (listp val) - (concat "[|" (mapconcat #'org-babel-ocaml-elisp-to-ocaml val "; ") "|]") - (format "%S" val))) + (cond ((and (listp val) (listp (car val))) + (org-babel-ocaml-elisp-to-ocaml-array val #'org-babel-ocaml-elisp-to-ocaml-tuple)) + ((listp val) + (org-babel-ocaml-elisp-to-ocaml-array val)) + (t (format "%S" val)))) (defun org-babel-ocaml-parse-output (value type) "Parse VALUE of type TYPE. -- 2.35.1