Browse Source

babel: ocaml: New variable assignment and expansion scheme

	* ob-ocaml.el (org-babel-execute:ocaml): Use generic expansion
	function
	(org-babel-variable-assignments:ocaml): New function
	(org-babel-expand-body:ocaml): Delete function
Dan Davison 10 years ago
parent
commit
590fae34e1
1 changed files with 10 additions and 9 deletions
  1. 10 9
      lisp/ob-ocaml.el

+ 10 - 9
lisp/ob-ocaml.el

@@ -51,19 +51,13 @@
 (defvar org-babel-ocaml-eoe-indicator "\"org-babel-ocaml-eoe\";;")
 (defvar org-babel-ocaml-eoe-output "org-babel-ocaml-eoe")
 
-(defun org-babel-expand-body:ocaml (body params)
-  "Expand BODY according to PARAMS, return the expanded body."
-  (let ((vars (nth 1 (org-babel-process-params params))))
-    (concat (mapconcat
-	     (lambda (pair) (format "let %s = %s;;" (car pair)
-			       (org-babel-ocaml-elisp-to-ocaml (cdr pair))))
-	     vars "\n") "\n" body "\n")))
-
 (defun org-babel-execute:ocaml (body params)
   "Execute a block of Ocaml code with Babel."
   (let* ((processed-params (org-babel-process-params params))
          (vars (nth 1 processed-params))
-         (full-body (org-babel-expand-body:ocaml body params))
+         (full-body (org-babel-expand-body:generic
+		     body params
+		     (org-babel-variable-assignments:ocaml params)))
          (session (org-babel-prep-session:ocaml
 		   (cdr (assoc :session params)) params))
          (raw (org-babel-comint-with-output
@@ -99,6 +93,13 @@
     (save-window-excursion (tuareg-run-caml)
                            (get-buffer tuareg-interactive-buffer-name))))
 
+(defun org-babel-variable-assignments:ocaml (params)
+  "Return list of ocaml statements assigning the block's variables"
+  (mapcar
+   (lambda (pair) (format "let %s = %s;;" (car pair)
+			  (org-babel-ocaml-elisp-to-ocaml (cdr pair))))
+   (mapcar #'cdr (org-babel-get-header params :var))))
+  
 (defun org-babel-ocaml-elisp-to-ocaml (val)
   "Return a string of ocaml code which evaluates to VAL."
   (if (listp val)