emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Bug: Babel: asymptote: erroneous conversion of heterogeneous-typ


From: Eric Schulte
Subject: Re: [O] Bug: Babel: asymptote: erroneous conversion of heterogeneous-typed table
Date: Mon, 29 Aug 2011 12:02:11 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Nicolas Goaziou <address@hidden> writes:

> Hello,
>
> Eric Schulte <address@hidden> writes:
>
>> I don't know asymptote well enough to know if you would /always/ want a
>> heterogeneous table to be converted to all strings, or if there would
>> ever be a case where you would want mixed types in a table.
>
> There are no mixed types arrays in Asymptote, hence the problem of the
> OP. You can choose between int[][], real[][] or string[][] (and other
> types specific to Asymptote and, as such, irrelevant here), but you
> never want an heterogeneous table.
>
> So, the real question is: what should Org do when an user tries to fit
> a mixed array into an Asymptote var? Until now, it was throwing an
> error. With this patch, _one_ string in the table will trigger the
> string type for every other cell.
>
> But this kind of an hidden feature. The user has to be aware that, under
> some circumstances, ints in his table will become strings.
>
> On the other hand, an user knowing he can't mix types in Asymptote (as
> he should) can't do much about it, as far as I know.
>
> As I said in this thread, an elegant solution would be to have a way to
> specify Babel to output tables of strings easily:
>
> | x | "1" | "2" | "3" |
> | y | "1" | "4" | "9" |
>
> That would be the less surprising, as the user would get the type he
> sees in his table.
>

Given that asymptote can not make use of heterogeneous tables, it seems
that it would be easiest to simply silently converted any table
containing a single string element to a table of all strings.  I've just
applied your previous patch (thanks for the patch!).  If this proves
confounding in the future we can always revisit the decision.

Additionally, I've just added a new function to the library of babel
which can be used to convert all elements of a table to strings.  It is
not needed here, but it could be useful in the future.

** Convert every element of a table to a string

#+tblname: hetero-table
| 1 | 2 | 3 |
| a | b | c |

#+source: all-to-string
#+begin_src emacs-lisp :var tbl='()
  (defun all-to-string (tbl)
    (if (listp tbl)
        (mapcar #'all-to-string tbl)
      (if (stringp tbl)
          tbl
        (format "%s" tbl))))
  (all-to-string tbl)
#+end_src

#+begin_src emacs-lisp :var tbl=hetero-table
  (mapcar (lambda (row) (mapcar (lambda (cell) (stringp cell)) row)) tbl)
#+end_src

#+results:
| nil | nil | nil |
| t   | t   | t   |

#+begin_src emacs-lisp :var tbl=all-to-string(hetero-table)
  (mapcar (lambda (row) (mapcar (lambda (cell) (stringp cell)) row)) tbl)
#+end_src

#+results:
| t | t | t |
| t | t | t |
Cheers -- Eric

>
>
> Regards,

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]