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: Passing a list of symbols to function argument Date: Fri, 29 Nov 2024 21:41:32 +0100 Message-ID: <87ldx17oxv.fsf@gmx.net> References: <87ser97r3k.fsf@gmx.net> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25570"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Heime via Users list for the GNU Emacs text editor To: Heime Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Nov 29 21:42:10 2024 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 1tH7oX-0006Ss-Gr for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 29 Nov 2024 21:42:09 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tH7o3-0006h9-Rt; Fri, 29 Nov 2024 15:41:39 -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 1tH7o3-0006gn-1P for help-gnu-emacs@gnu.org; Fri, 29 Nov 2024 15:41:39 -0500 Original-Received: from mout.gmx.net ([212.227.17.22]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tH7o1-0005Mv-4O for help-gnu-emacs@gnu.org; Fri, 29 Nov 2024 15:41:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1732912893; x=1733517693; i=stephen.berman@gmx.net; bh=Fld/csXvB4gsD8rQmfI3fhgvib41koRZO8YvWwnneqw=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date: Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=o5IS3brFXqMwp1aknK4vmAHgJuZsycl2XOjCXjoao16+vu9a/ZDLoo5R0D7IHnGj 2qY2RemttcukbcpBr4rgcAn6+3PJ+Yhi0rJuOhHFeNTtdnztjw4pQxiGIW2TlAa1H CrJeBd++XaE6oiYOegeH8BBk8zUNcy7ZTMVlUJYrW5NvLo4jf7WeMimuDmAic6gsa nfmTFpvfPDncqmiGimF80Ub7U+m9SzLnURjOBegHTN5VeBD7zoCHvNzhHDetsRCYA 3ZZwX0F95Y0GOD7qatsKzBUO3qLDOwkfMUWWJmm6/JsB7c66vx6BQxzIdUiTDoZNM SUhriywOxBaX+I+rKg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfssd ([88.130.49.222]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MrhUK-1u4jkn0VPg-00moPp; Fri, 29 Nov 2024 21:41:33 +0100 In-Reply-To: (Heime's message of "Fri, 29 Nov 2024 20:15:04 +0000") X-Provags-ID: V03:K1:LJjGXrvKxEmRatyEtXHTniR8C6tyx0Ba19nMDTu7srRTxgQ/+Ee JOUgQ8w4h1X7qmxzCXmNgAk7aUuE9rcz78mwoVeQriygFxIgYiUHKLtKuC/5CHsDDx9cQx4 z/kXQQpKIAvBM2ZITZkn/h48aOYbLEtfGWjzrOzrMw2L61WiqsOcj1UX6RSRDN1BSKcwZbK q6OeRJpoE9zVzf0Vk1W8w== UI-OutboundReport: notjunk:1;M01:P0:n7bYDGGLGd4=;6umAinIXKx2qCdjwVp4LXKjdYhP J03j9M7QaOT2onTgGZ4Rh7A3r35CqO8fDhxws++mgxBbsDNliYkMn26KP8aAj5T9UHm1NpL8m IUAHTNdDkIVDdYDYaASGQkYqDeYuOXWRj9x1m20TcJXbllq1DxB10uTcLeIlSpBgjwE3bt3qB +DykXeBIyQ5/ZaEGnndh8gR5irNcSkvAWpL5jlL4Nuy7Ul7SPVKU7pHVlZrqNDg24mGlgPdZk FDvSrpOiX5/ahPI7TGJZsKTKiHOWIirCpIkEdFK35hTlaJZAdHfceOlf2U8+I8XE0Csz9vlVR 7w7JgSgGqpvVJxvpUsDawMSGiCqT77yt03GxuYOPvzC2iAOnEFcXLUZx9Zx7jgTozf70Zo6+q ZdH/be7vmqcrzNylQAikOsDjXPgveyE+Wi8R+YPk1An9FLwX9cfj4MZvsEKdPDFlv/8kHb6h/ E5Y5PywSMlv42oC8AfdgRX0Qunky9RlScbOTtyvR/qCG4yZC5XR1PnoO/bawJvOxC1mIdlMEb 2uBmL8PK5aJKTqTHQnzLrCxLYYcrM3mwxYQTG11EqwhyxL/3aXGWzc8xuOIbJ6p1yXAVp+M38 UlOGO3cHsaDKhzfu22QujFhUNHcGOWDGTTmuD6IgIvjBVdRJqRQRxhFRKoZOIIxxmQLfFoMPP JehWztWgBl41aROM70drBST0DuX+rJi2aScC61EYR0j2Gnv/b+LsGbllXb6pYQV6aH1r3glnj S4MHiWq2orgON5moFEN09kuYTZSOYhI3Op9NZNmT96hM0pVRJznTAPMHriLHPGYwOCFgUtqP Received-SPF: pass client-ip=212.227.17.22; envelope-from=stephen.berman@gmx.net; helo=mout.gmx.net X-Spam_score_int: -36 X-Spam_score: -3.7 X-Spam_bar: --- X-Spam_report: (-3.7 / 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.93, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:148446 Archived-At: On Fri, 29 Nov 2024 20:15:04 +0000 Heime wrot= e: > Sent with Proton Mail secure email. > > On Saturday, November 30th, 2024 at 7:54 AM, Stephen Berman > wrote: > >> On Fri, 29 Nov 2024 17:34:01 +0000 Heime via Users list for the GNU Ema= cs >> text editor help-gnu-emacs@gnu.org wrote: >> >> > Why do I get >> > >> > Wrong type argument: stringp, tabtrail >> > >> > When using the call >> > >> > (poalatuk '(72 tabtrail global)) >> > >> > to the function >> > >> > (defun poalatuk (actm-seqr) >> > >> > (interactive >> > (let* ( (colw (read-number "Line Column: " 72)) >> > (cseq '("extended" "disable" "tabtrail")) >> > (rsel (completing-read "Selector: " cseq nil t "tabtrail")) >> > (scope (completing-read "Scope: " >> > '("global" "local") nil t "local")) ) >> > >> > ;; Pass a single list as argument >> > (list (list colw rsel scope))) ) >> > >> > ;; ------------------------------------------------------------- >> > >> > (message "poalatuk: %S" actm-seqr) >> > >> > (let* ( (colw (nth 0 actm-seqr)) ;; Extract column width. >> > (rsel (intern (nth 1 actm-seqr))) ;; Extract mode selector. >> >> ^^^^^^^^^^^^^^^^^^^^^^^^^^ >> >> The error happens here. You passed '(72 tabtrail global) as the value >> of the argument actm-seqr, so (nth 1 actm-seqr) returns the symbol >> `tabtrail'. But` intern' takes a string and returns the symbol (in the >> obarray) whose name is given by the string. >> >> Steve Berman > > I want the function to accept both symbols and strings. intern must the= n > be applied only when a string is passed. Which undoubtedly needs a cond= itional > check. > > Perhaps I should also test whether the argument is a symbol or do the if > and pcase handle errors (because the commands will be skipped). > > (let* ((colw (nth 0 actm-seqr)) > (rsel (if (stringp (nth 1 actm-seqr)) > (intern (nth 1 actm-seqr)) > (nth 1 actm-seqr))) > (scope (if (stringp (nth 2 actm-seqr)) > (intern (nth 2 actm-seqr)) > (nth 2 actm-seqr)))) This seems fine; `if' does not do error handling, nor does `pcase' AFAIK (but there are several variants and extensions of pcase, and I'm not too familiar with them, so maybe some of them do error handling), but `condition-case' is the basic error handling form in Elisp. Alternatively, since the error only happens in noninteractive calls (since interactive calls use `completing-read', which returns strings), you could condition on `called-interactively-p'. Steve Berman