From mboxrd@z Thu Jan  1 00:00:00 1970
From: Greg Minshall <minshall@umich.edu>
Subject: Re: odd behavior for begin_src org :results
Date: Wed, 01 May 2013 17:57:09 -0400
Message-ID: <19624.1367445429@greg-minshalls-mbp.local>
References: <87k3ni4ghj.fsf@gmail.com>
Return-path: <emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org>
Received: from eggs.gnu.org ([208.118.235.92]:40765)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <minshall@umich.edu>) id 1UXf1Y-00060g-3N
	for emacs-orgmode@gnu.org; Wed, 01 May 2013 17:57:20 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <minshall@umich.edu>) id 1UXf1T-0000GI-Pr
	for emacs-orgmode@gnu.org; Wed, 01 May 2013 17:57:16 -0400
Received: from relay01.pair.com ([209.68.5.15]:3575)
	by eggs.gnu.org with smtp (Exim 4.71)
	(envelope-from <minshall@umich.edu>) id 1UXf1T-0000GD-K0
	for emacs-orgmode@gnu.org; Wed, 01 May 2013 17:57:11 -0400
In-reply-to: Your message of "Wed, 01 May 2013 14:01:12 -0600."
	<87k3ni4ghj.fsf@gmail.com>
List-Id: "General discussions about Org-mode." <emacs-orgmode.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-orgmode>,
	<mailto:emacs-orgmode-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/emacs-orgmode>
List-Post: <mailto:emacs-orgmode@gnu.org>
List-Help: <mailto:emacs-orgmode-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-orgmode>,
	<mailto:emacs-orgmode-request@gnu.org?subject=subscribe>
Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org
Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org
To: Eric Schulte <schulte.eric@gmail.com>
Cc: emacs-orgmode@gnu.org

Eric,

thanks for the answer.  another "#+begin_src org" question.  it appears
that only *string* values are allowed for any :var that are defined
(i.e., ':var bar="foo"', and *not* ':var bar=3').  since i'm not 100%
sure of the semantics, maybe this is desired.

if one *should* be allowed to pass in, e.g., tables, numbers, etc., then
maybe org-babel-expand-body:org in ob-org.el wants to change from the
current
----
(defun org-babel-expand-body:org (body params)
  (dolist (var (mapcar #'cdr (org-babel-get-header params :var)))
    (setq body (replace-regexp-in-string
		(regexp-quote (format "$%s" (car var)))  (cdr var) body
		nil 'literal)))
  body)
----
to something like this
----
  (defun org-babel-expand-body:org (body params)
    (dolist (var (mapcar #'cdr (org-babel-get-header params :var)))
      (setq body (replace-regexp-in-string
                  (regexp-quote (format "$%s" (car var)))  
                  (if (stringp (cdr var))
                      (cdr var)
                    (format "%s" (prin1 (cdr var))))
                  body nil 'literal)))
    body)
----
(as otherwise replace-regexp-in-string notices that (cdr var) is *not* a
string, and attempts to execute it.)

maybe^2 it would make even more sense to use the "#+begin_src
emacs-lisp" equivalent routine from ob-emacs-lisp.el as a template?
----
(defun org-babel-expand-body:emacs-lisp (body params)
  "Expand BODY according to PARAMS, return the expanded body."
  (let* ((vars (mapcar #'cdr (org-babel-get-header params :var)))
         (result-params (cdr (assoc :result-params params)))
         (print-level nil) (print-length nil)
         (body (if (> (length vars) 0)
		   (concat "(let ("
			   (mapconcat
			    (lambda (var)
			      (format "%S" (print `(,(car var) ',(cdr var)))))
			    vars "\n      ")
			   ")\n" body "\n)")
		 (concat body "\n"))))
    (if (or (member "code" result-params)
	    (member "pp" result-params))
	(concat "(pp " body ")") body)))
----
(my elisp isn't strong enough to evaluate this.)

cheers, Greg