I'm sorry if this is not the correct format to send patches in, but it's
my first patch.  Hope it looks good.

This patch fixes the OCaml list assignment when using a table as a var
to an OCaml source block in org-babel.

diff --git a/lisp/ob-ocaml.el b/lisp/ob-ocaml.el
index 8cdffc9..43be08c 100644
--- a/lisp/ob-ocaml.el
+++ b/lisp/ob-ocaml.el
@@ -50,12 +50,44 @@
 (defvar org-babel-ocaml-eoe-indicator "\"org-babel-ocaml-eoe\";;")
 (defvar org-babel-ocaml-eoe-output "org-babel-ocaml-eoe")
 
+(defun org-babel-ocaml-quote-item (itm)
+  (cond ((stringp itm)
+	 (format "\"%s\"" itm))
+	(t
+	 (format "%s" itm))))
+
+(defun org-babel-ocaml-list-from-elisp (lst)
+  "Construct OCaml list from elisp list LST.
+
+As LST is expected to be an org-mode table, the result will actually
+be a list of n-tuples, such as [(1, 2, 3); (2, 3, 4)]."
+  (concat "["
+	  (mapconcat 
+	   #'(lambda (itm)
+	       (cond ((listp itm)
+		      (concat "("
+			      (mapconcat #'org-babel-ocaml-quote-item itm ", ")
+			      ")"))
+		     ((stringp itm)
+		      (format "\"%s\"" itm))
+		     (t
+		      (format "%s" itm))))
+	   lst "; ")
+	  "]"))
+
+(defun org-babel-ocaml-assign-elisp (name value colnames-p rownames-p)
+  "Construct OCaml code assigning the elisp VALUE to a variable named NAME."
+  (if (listp value)
+      (format "let %s = %s in\n"
+	      name (org-babel-ocaml-list-from-elisp value))
+    (format "let %s = %s in\n" name value)))
+
 (defun org-babel-expand-body:ocaml (body params &optional processed-params)
   "Expand BODY according to PARAMS, return the expanded body."
   (let ((vars (nth 1 (or processed-params (org-babel-process-params params)))))
     (concat
      (mapconcat
-      (lambda (pair) (format "let %s = %s;" (car pair) (cdr pair)))
+      (lambda (pair) (org-babel-ocaml-assign-elisp (car pair) (cdr pair) nil nil))
       vars "\n") "\n" body "\n")))
 
 (defun org-babel-execute:ocaml (body params)
-- 
Erik Arneson <dyb...@lnouv.com>
  GPG Key ID: 1024D/62DA1D25
  Office: +1.541.291.9776
  Skype: callto://pymander
_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

Reply via email to