emacs-orgmode
[Top][All Lists]
Advanced

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

[O] Problem with bash arrays from list-valued org-babel :var assignments


From: Keith Amidon
Subject: [O] Problem with bash arrays from list-valued org-babel :var assignments?
Date: Thu, 08 Jun 2017 21:56:34 -0700

With current org-mode, when I try to execute the following org-babel
block:

#+begin_src bash :var lst='(1 2 3 4 5 6 7)
printf "%s\n" "${lst[*]}"
#+end_src

I get result and the following error in the minibuffer:

   Wrong type argument: listp, 1

This, on the other hand works fine:

#+begin_src emacs-lisp :var lst='(1 2 3 4 5 6 7)
lst
#+end_src

In investigating this, I looked into the code for how bash variables
are set from the org variables and found this code in ob-shell that I
don't really understand:

(defun org-babel--variable-assignments:bash (varname values &optional sep hline)
  "Represents the parameters as useful Bash shell variables."
  (if (listp values)
      (if (and (listp (car values)) (= 1 (length (car values))))
          (org-babel--variable-assignments:bash_array varname values sep hline)
        (org-babel--variable-assignments:bash_assoc varname values sep hline))
    (org-babel--variable-assignments:sh-generic varname values sep hline)))

I *think* that the org-babel--variable-assignments:bash_assoc function
is supposed to allow initializing bash arrays with arbitrary key/value
mappings when each element of the list is itself a list where the first
element of the sublist is the key of the mapping and the remaining
elements form the value, whereas the org-babel--variable-
assignments:bash_array function is supposed to create integer-indexed
bash arrays for simple lists.

However, if that is the case, the logic for picking between them
doesn't work as I would expect, since a simple list like the example at
the beginning of this email, '(1 2 3 4 5 6 7), will will fail the test
(listp (car values)) and result in the bash_assoc version being called
when the list is not of the correct form for that function.

The following version of the function that replaces the current test
with a simpler one seems to do what I think the expected behavior
should be for both types of lists, but it isn't clear to me whether the
current code is trying to support some other use cases that I don't
understand:

(defun org-babel--variable-assignments:bash (varname values &optional sep hline)
  "Represents the parameters as useful Bash shell variables."
  (if (listp values)
      (if (not (listp (car values)))
          (org-babel--variable-assignments:bash_array varname values sep hline)
        (org-babel--variable-assignments:bash_assoc varname values sep hline))
    (org-babel--variable-assignments:sh-generic varname values sep hline)))

In any case, it seems like the simple example at the beginning of this
message should work. Is this a bug or am I missing something?

          Thanks, Keith




reply via email to

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