help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Surprising behaviour of 'append' with strings


From: Jean Louis
Subject: Re: Surprising behaviour of 'append' with strings
Date: Sun, 6 Nov 2022 15:39:16 +0300
User-agent: Mutt/2.2.7+37 (a90f69b) (2022-09-02)

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/



reply via email to

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