emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: dybbuk-qPb3x58jdZkAvxtiuMwx3w@public.gmane.org (Erik L. Arneson)
To: emacs-orgmode-mXXj517/zsQ@public.gmane.org
Subject: [PATCH] Fix list assignments in ob-ocaml.el
Date: Fri, 16 Jul 2010 12:59:23 -0700	[thread overview]
Message-ID: <m2iq4f8ag4.fsf@tyche.LNouv.com> (raw)
In-Reply-To: m2r5j38nqt.fsf@tyche.LNouv.com

[-- Attachment #1: Type: text/plain, Size: 222 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Fix OCaml list assignment --]
[-- Type: text/x-patch, Size: 1713 bytes --]

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)

[-- Attachment #3: Type: text/plain, Size: 149 bytes --]


-- 
Erik Arneson <dybbuk-qPb3x58jdZkAvxtiuMwx3w@public.gmane.org>
  GPG Key ID: 1024D/62DA1D25
  Office: +1.541.291.9776
  Skype: callto://pymander

[-- Attachment #4: Type: text/plain, Size: 222 bytes --]

_______________________________________________
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

  reply	other threads:[~2010-07-16 19:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-16 15:12 org-babel and OCaml - help? Erik L. Arneson
2010-07-16 19:59 ` Erik L. Arneson [this message]
2010-07-16 20:59   ` [PATCH] Fix list assignments in ob-ocaml.el Erik L. Arneson
2010-07-17 18:08     ` Eric Schulte
2010-07-17  0:41   ` Bernt Hansen
2010-07-16 22:30 ` org-babel and OCaml - help? Eric Schulte
2010-07-18 14:30   ` Erik L. Arneson
2010-07-18 17:07     ` Eric Schulte
2010-07-21 16:56       ` [babel] " Erik L. Arneson
2010-07-21 22:19         ` [babel] Re: org-babel and OCaml Eric Schulte

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2iq4f8ag4.fsf@tyche.LNouv.com \
    --to=dybbuk-qpb3x58jdzkavxtiumwx3w@public.gmane.org \
    --cc=emacs-orgmode-mXXj517/zsQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).