From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Bug: Babel: asymptote: erroneous conversion of heterogeneous-typed table Date: Wed, 31 Aug 2011 11:35:32 +0200 Message-ID: <87obz5hqjf.fsf@gmail.com> References: <20110829080003.GA12790@discus> <87hb50li4b.fsf@gmail.com> <878vqclf64.fsf@gmail.com> <87mxesjs9e.fsf@gmail.com> <87fwkkjhvt.fsf@gmail.com> <87y5yc6tx4.fsf@gmail.com> <87vctgi0ve.fsf@gmail.com> <87hb506qqk.fsf@gmail.com> <878vqc6nye.fsf@gmail.com> <87ei0266dw.fsf@gmail.com> <878vqa62lo.fsf@gmail.com> <10851.1314778677@alphaville.dokosmarshall.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:59599) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QyhDS-0003li-1J for emacs-orgmode@gnu.org; Wed, 31 Aug 2011 05:36:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QyhDQ-0003si-7E for emacs-orgmode@gnu.org; Wed, 31 Aug 2011 05:36:13 -0400 Received: from mail-ww0-f49.google.com ([74.125.82.49]:53337) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QyhDP-0003se-Tq for emacs-orgmode@gnu.org; Wed, 31 Aug 2011 05:36:12 -0400 Received: by wwf10 with SMTP id 10so420737wwf.30 for ; Wed, 31 Aug 2011 02:36:10 -0700 (PDT) In-Reply-To: <10851.1314778677@alphaville.dokosmarshall.org> (Nick Dokos's message of "Wed, 31 Aug 2011 04:17:57 -0400") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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: nicholas.dokos@hp.com Cc: =?utf-8?b?QW5kcsOhcw==?= Major , emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, Nick Dokos writes: > Andr=C3=A1s Major wrote: > >> Hi Eric, >>=20 >> > Can you post an example? Here is a working example. >>=20 >> In your example, simply write "asymptote" in place of "sh" and replace t= he >> code by "size(100);" just to make sure it's valid asymptote (though the >> error occurs even if you don't). In fact, I'm quite sure that asy never >> gets executed in this case. >>=20 > > Yes, even without any asymptote code, this breaks. But there seem to be > multiple problems. One is fix-empty-lines, a local routine defines > inside org-babel-asymptote-table-to-array: it seems to assume that the ta= ble > is a list of lists, whereas in this case it's a list of strings. The > following patch (which probably is wrong, in that it cures the symptom > rather than the disease): Yes, the problem is more general: uni-dimensional lists are not handled correctly. I attach a patch that should fix the problem (and simplify a lot that whole process). One thing, though. Now, | 1 | 2 | and (but this was already the case) | 1 | | 2 | are treated as bi-dimensional arrays, because that's how they really are passed to ob-asymptote. Regards, --=20 Nicolas Goaziou --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ob-asymptote-full-support-for-uni-dimensional-lists.patch >From 82ae786a8ed1248a62912272edec6f8fa7df4d12 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Wed, 31 Aug 2011 11:11:31 +0200 Subject: [PATCH 1/2] ob-asymptote: full support for uni-dimensional lists * lisp/ob-asymptote.el (org-babel-asymptote-var-to-asymptote): recognize non-nested lists as uni-dimensional arrays. --- lisp/ob-asymptote.el | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lisp/ob-asymptote.el b/lisp/ob-asymptote.el index 89aecb7..f90bb85 100644 --- a/lisp/ob-asymptote.el +++ b/lisp/ob-asymptote.el @@ -97,9 +97,8 @@ Asymptote does not support sessions" The elisp value PAIR is converted into Asymptote code specifying a variable of the same value." (let ((var (car pair)) - (val (if (symbolp (cdr pair)) - (symbol-name (cdr pair)) - (cdr pair)))) + (val (let ((v (cdr pair))) + (if (symbolp v) (symbol-name v) v)))) (cond ((integerp val) (format "int %S=%S;" var val)) @@ -107,14 +106,17 @@ a variable of the same value." (format "real %S=%S;" var val)) ((stringp val) (format "string %S=\"%s\";" var val)) + ((and (listp val) (not (listp (car val)))) + (let* ((type (org-babel-asymptote-define-type val)) + (fmt (if (eq 'string type) "\"%s\"" "%s")) + (vect (mapconcat (lambda (e) (format fmt e)) val ", "))) + (format "%s[] %S={%s};" type var vect))) ((listp val) - (let* ((dimension-2-p (cdr val)) - (dim (if dimension-2-p "[][]" "[]")) - (type (org-babel-asymptote-define-type val)) + (let* ((type (org-babel-asymptote-define-type val)) (array (org-babel-asymptote-table-to-array val type - (if dimension-2-p '(:lstart "{" :lend "}," :llend "}"))))) - (format "%S%s %S=%s;" type dim var array)))))) + '(:lstart "{" :lend "}," :llend "}")))) + (format "%S[][] %S=%s;" type var array)))))) (defun org-babel-asymptote-table-to-array (table type params) "Convert values of TABLE into a string of an asymptote array. -- 1.7.6.1 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-ob-asymptote-simplify-table-to-array-conversion-proc.patch >From 2e3b7579649ead40128e3c8e31ca75ced139285d Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Wed, 31 Aug 2011 11:26:29 +0200 Subject: [PATCH 2/2] ob-asymptote: simplify table to array conversion process * lisp/ob-asymptote.el (org-babel-asymptote-var-to-asymptote): refactor code. (org-babel-asymptote-table-to-array): removed function. --- lisp/ob-asymptote.el | 40 ++++++++-------------------------------- 1 files changed, 8 insertions(+), 32 deletions(-) diff --git a/lisp/ob-asymptote.el b/lisp/ob-asymptote.el index f90bb85..2219e03 100644 --- a/lisp/ob-asymptote.el +++ b/lisp/ob-asymptote.el @@ -113,38 +113,14 @@ a variable of the same value." (format "%s[] %S={%s};" type var vect))) ((listp val) (let* ((type (org-babel-asymptote-define-type val)) - (array (org-babel-asymptote-table-to-array - val type - '(:lstart "{" :lend "}," :llend "}")))) - (format "%S[][] %S=%s;" type var array)))))) - -(defun org-babel-asymptote-table-to-array (table type params) - "Convert values of TABLE into a string of an asymptote array. - -TABLE is a list whose atoms are assumed to be of type -TYPE. PARAMS is a plist of parameters that can influence the -conversion. - -Empty cells are ignored." - (labels ((atom-to-string (table) - (cond - ((null table) '()) - ((not (listp (car table))) - (cons (if (or (eq type 'string) - (and (stringp (car table)) - (not (string= (car table) "")))) - (format "\"%s\"" (car table)) - (format "%s" (car table))) - (atom-to-string (cdr table)))) - (t - (cons (atom-to-string (car table)) - (atom-to-string (cdr table)))))) - ;; Remove any empty row - (fix-empty-lines (table) - (delq nil (mapcar (lambda (l) (delq "" l)) table)))) - (orgtbl-to-generic - (fix-empty-lines (atom-to-string table)) - (org-combine-plists '(:hline nil :sep "," :tstart "{" :tend "}") params)))) + (fmt (if (eq 'string type) "\"%s\"" "%s")) + (array (mapconcat (lambda (row) + (concat "{" + (mapconcat (lambda (e) (format fmt e)) + row ", ") + "}")) + val ","))) + (format "%S[][] %S={%s};" type var array)))))) (defun org-babel-asymptote-define-type (data) "Determine type of DATA. -- 1.7.6.1 --=-=-=--