From: Keith Amidon <camalot@picnicpark.org>
To: emacs-orgmode@gnu.org
Cc: camalot@picnicpark.org
Subject: Problem with bash arrays from list-valued org-babel :var assignments?
Date: Thu, 08 Jun 2017 21:56:34 -0700 [thread overview]
Message-ID: <1496984194.5909.4.camel@picnicpark.org> (raw)
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
next reply other threads:[~2017-06-09 4:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-09 4:56 Keith Amidon [this message]
2017-06-09 9:16 ` Problem with bash arrays from list-valued org-babel :var assignments? Neil Jerram
2017-06-09 22:53 ` Nicolas Goaziou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1496984194.5909.4.camel@picnicpark.org \
--to=camalot@picnicpark.org \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).