From mboxrd@z Thu Jan 1 00:00:00 1970 From: dybbuk-qPb3x58jdZkAvxtiuMwx3w@public.gmane.org (Erik L. Arneson) Subject: [PATCH] Fix list assignments in ob-ocaml.el Date: Fri, 16 Jul 2010 12:59:23 -0700 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org-mXXj517/zsQ@public.gmane.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org-mXXj517/zsQ@public.gmane.org To: emacs-orgmode-mXXj517/zsQ@public.gmane.org --=-=-= 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=ob-ocaml.patch Content-Description: Fix OCaml list assignment 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 GPG Key ID: 1024D/62DA1D25 Office: +1.541.291.9776 Skype: callto://pymander --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode-mXXj517/zsQ@public.gmane.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=-=-=--