From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: Surprising behaviour of 'append' with strings Date: Sun, 06 Nov 2022 13:13:26 +0100 Message-ID: <87v8ns5li1.fsf@gmx.net> References: <6554cc02-2082-3dca-73cc-05fee1c6c4d0.ref@yahoo.de> <6554cc02-2082-3dca-73cc-05fee1c6c4d0@yahoo.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32191"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: help-gnu-emacs@gnu.org To: "R. Diez" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Nov 06 13:14:13 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oreXV-0008BF-Iv for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 06 Nov 2022 13:14:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oreWu-00033C-Va; Sun, 06 Nov 2022 07:13:36 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oreWt-000334-3I for help-gnu-emacs@gnu.org; Sun, 06 Nov 2022 07:13:35 -0500 Original-Received: from mout.gmx.net ([212.227.15.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oreWr-0004Cw-7f for help-gnu-emacs@gnu.org; Sun, 06 Nov 2022 07:13:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1667736807; bh=0zMVIteb1VAY4dPOjMc6G7EblQdnTqecvYM3jTERXhQ=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date; b=QYdoH6Msb7ZxlFsf3bSYVaO5bchNlSu2DiH/4KBoaAv4Z1opv+4RoNqf/HHIHbWJw EEjHfIbDgzXOp2jSZj7+CZq8G9WfD5zoCnnXLt+S1hVzJjnpah+iuFSKLTDGUGSsPL BYUPAUw6sAqdp9cW10K8mw/KmZdUv2NRn7IYKhV3Vrh5f64E2HrQIKRX/ywyoGKNXX YLWWuO7QlOuZZQah6vzliZQJ5ibOuv3DAUi6SZ80IPUYJY2nV0EU3JluQ3nKpYs1WN nFGlBVBWAxsfZeQvcVqXAT1ejok6XInba1/Pt03dCZczhxWZoRMRscuJzddBr+dTR7 ZAxkKSellczgg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfs ([89.246.38.100]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M7b6l-1owtrO1UuT-0086KD; Sun, 06 Nov 2022 13:13:27 +0100 In-Reply-To: <6554cc02-2082-3dca-73cc-05fee1c6c4d0@yahoo.de> (R. Diez's message of "Sun, 6 Nov 2022 12:05:07 +0100") X-Provags-ID: V03:K1:oR6vzpOz0S6thjT1dWWAqieCUNjkCZ76hOkmzSDDJVBQYQ5Xvuw w7D4PE5eZ5ReBdw0+ti9XtrVtYLYIFCeOIkpvTpLOF9i2/FMlBzCX+k7a6gP+5Zi5CiPmMB S6oCKBFl5Hy18rdjJuUAPQUA8G4VX5bx28/9bqTnAh6GlnID7jYCjVmzLXE9QJvU1LJfwJ6 mKsjYlezZ23U52bWuP9tw== UI-OutboundReport: notjunk:1;M01:P0:tGDwlaJ4z6Y=;WG1XwYqw2vn1kijxs6WoUm5Dq9k DGKu0DS7gdTMrnI4V8aIOOCs/Ngj8l08Q+xmlqvyn69pHZ4v+Rv25k/SOvXog491TPLT1iUKC Efth49OmFvT+T7lafq5yDnqvdCIToX/GmmG+SdhK31F8rgEA4wMowf3wQMTVbn7Klsx4xeyRu xuOZm87FmCGSBsBdxM11ihol3xzpuCP2UU+xivyVK6Cf84DIKu3fHl1Yd+3PMUYS8pQg1kcrX nv8ZcqoaBrQK1IEHnu8y7kmtVFYk9LjNS6fkvMTcCLfMdhWnHx0izqCBCt6xNouud1ncHLK3e I40c9od+3EHGeDMPGWFSzCLhmRvKsmbgCZK1v+wVtfT03noKDj493BSLV/VRyQ98hegN17diW XW1v/94AJTHDjG450Rk57R01qisMFf/XoY/9wGHoj6UmOb2gQOooEus4CxUt5XTOCMkP7We2x WjE63RpZ8PfIp/H+bMmkgIPLjp+gyPJcKE4dfCLDTxG5cIO0H8g5e31TO7hHxAnnOg0c76Obh tAFIxwDrPWjjpJa6sejsLp2nCLJKB7V68pqJMCPqmFo1baQGbYGUToictSwo9iMjgpnNMe6Cn b9GC5Dhjoa5rUkt8ATNfESJvRNWLO716N+EMYzE8qDnK+CugoYKjrqpC51Wz/QC4PKE1xl4FH WbD+EuOHG0L6eHHCZZ4jcnnpcssPdvnFpzc7ymg6TMAVA3oVDDY+6UP/Wv3gZMhqtoyFkV5EN QU5htJQJtWnKfGve/js0SilMh9KVR476HXR8eJ7MvI0HM8liejYnS/Mewj8sfIUkh0MAKCEN Received-SPF: pass client-ip=212.227.15.19; envelope-from=stephen.berman@gmx.net; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: "help-gnu-emacs" Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:140717 Archived-At: On Sun, 6 Nov 2022 12:05:07 +0100 "R. Diez" wrote: > Hi all: > > I want to build a list of command-line arguments to run a > program. Each element of the list must be a string. [...] > However, I got into trouble with 'append'. Its documentation states: > > "Each argument may be a list, vector or string." > > I tested it like this: > > (append "1") -> "1" > (append "1" "2") -> (49 . "2") > > That behaviour is surprising and it does not fit the bill. It appears you didn't appreciate the preceding line of the doc string: "The result is a list whose elements are the elements of all the arguments." So the result contains the elements of the string "1", which is just the single character ?1, whose value is 49. > I need a routine like this: > > (my-append > "1" > (list "2" "3") > "4" > ) > > The result should be: > ("1" "2" "3" "4") > > As a bonus, 'my-append' should check that all elements are strings, or > list of strings (no nested lists, and no other data types). If you are willing to make the argument have this kind of form: '("1" ("2" "3") "4") then flatten-tree should do the job. To also check that the elements are either a string or a list of strings, you could use this: (defun my-append (l) (dolist (e l) (cond ((proper-list-p e) (dolist (s e) (unless (stringp s) (user-error "Invalid list")))) (t (unless (stringp e) (user-error "Invalid list"))))) (flatten-tree l)) Steve Berman