From: Jean Louis <bugs@gnu.support>
To: "R. Diez" <rdiezmail-emacs@yahoo.de>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Surprising behaviour of 'append' with strings
Date: Sun, 6 Nov 2022 15:39:16 +0300 [thread overview]
Message-ID: <Y2eq9P6BMm3rkqvO@protected.localdomain> (raw)
In-Reply-To: <6554cc02-2082-3dca-73cc-05fee1c6c4d0@yahoo.de>
Hello,
* R. Diez <rdiezmail-emacs@yahoo.de> [2022-11-06 14:07]:
> I want to build a list of command-line arguments to run a
> program. Each element of the list must be a string.
First I was using function `shell-command' which is pretty liberate,
and it invokes shell and string as command, but that one is in reality
error prone and difficult, especially when there is quoting required.
> The commands are complex shell invocations with nested shell
> commands. I have been shell-quoting and concatenating plain strings
> for a long time, but it is error prone (in my experience).
You should use `call-process'
(call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS)
Probably introduced at or before Emacs version 18.
Then look ARGS, that is where you place the list.
> So now I am testing a different approach: I am building a list of
> strings, joining them with (string-join my-cmd-args " "), and
> passing the result to 'compile'.
I guess that could be all thinking in wrong direction, look at
`call-process' first and tell us if you tried that one out. It
minimizes all errors.
> (append "1") ⇒ "1"
> (append "1" "2") ⇒ (49 . "2")
Right
> (my-append
> "1"
> (list "2" "3")
> "4"
> )
>
> The result should be:
> ("1" "2" "3" "4")
`append' is to append for example lists:
(append (list 1) (list 2 3 4)) ⇒ (1 2 3 4)
(append (list "1") (list "2" "3" "4")) ⇒ ("1" "2" "3" "4")
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
next prev parent reply other threads:[~2022-11-06 12:39 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <6554cc02-2082-3dca-73cc-05fee1c6c4d0.ref@yahoo.de>
2022-11-06 11:05 ` Surprising behaviour of 'append' with strings R. Diez
2022-11-06 12:13 ` Stephen Berman
2022-11-06 12:35 ` Emanuel Berg
2022-11-06 20:28 ` Michael Heerdegen
2022-11-06 20:57 ` Emanuel Berg
2022-11-06 12:19 ` Emanuel Berg
2022-11-06 12:32 ` Emanuel Berg
2022-11-06 12:37 ` Eli Zaretskii
2022-11-06 12:39 ` Jean Louis [this message]
2022-11-06 20:33 ` Michael Heerdegen
2022-11-06 21:45 ` [External] : " Drew Adams
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.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y2eq9P6BMm3rkqvO@protected.localdomain \
--to=bugs@gnu.support \
--cc=help-gnu-emacs@gnu.org \
--cc=rdiezmail-emacs@yahoo.de \
/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.
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).