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 22:29:33 +0100 Message-ID: <87h67p7mpu.fsf@gmx.net> References: <87ser97r3k.fsf@gmx.net> <87ldx17oxv.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="38836"; 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 22:30:06 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 1tH8Yv-0009vv-SN for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 29 Nov 2024 22:30:06 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tH8YX-0006ie-Aq; Fri, 29 Nov 2024 16:29:41 -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 1tH8YU-0006iB-M4 for help-gnu-emacs@gnu.org; Fri, 29 Nov 2024 16:29:38 -0500 Original-Received: from mout.gmx.net ([212.227.15.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tH8YS-0007b8-Iq for help-gnu-emacs@gnu.org; Fri, 29 Nov 2024 16:29:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1732915773; x=1733520573; i=stephen.berman@gmx.net; bh=b8B++2gWjLg+Cfg3iJFMYNBiSFfDFzqQwvuRKRLlqUw=; 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=UESlV4iPjMARlN97kcV0Z3U6v0c8Z3nasPsuQ/kDvJx0QSnb9/RZb3SqCD0r42Yt 7C31c39x160s31lO2OsBqsMqNimCSRnODH+5fVk7kZJtlOXTqe5U1qu9I7JJ3NBK3 5j3zSmIAioe+KRTr39T/CvHwoDD//JL9FU3iiLPh3pIW5Q36qhdUOL1+So/mdFzIk Yq0z/SGu4D0bUb+UevwIaeJwkw5roTu84EXp89dnyP/j42Ak+7K3iixF0ZuFUOxc2 mfjilSZozo9Jxj6N/BdwyxdfeRAhx269iePk3bqEKHESkngte/DQcSUiNOxEyT0NC vzcnL0+o7Mnofnq0SQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfssd ([88.130.49.222]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MvK4Z-1tZDdU1XPt-011BXL; Fri, 29 Nov 2024 22:29:33 +0100 In-Reply-To: (Heime's message of "Fri, 29 Nov 2024 21:16:09 +0000") X-Provags-ID: V03:K1:dSZ8ugRQeBPkvAjJSIfHsvfMUnE+4Qi+cEgYr5T6Qp7UWkXjSNu mX1YZxGiimBNxKfdlMaaF/c6rBqyWn/cOBtL+ZHMF+AKjtYXTu9vx2T3YC2qUWm5m+XxpKq Tn1OjY7ccUpPLB/hksURdaCpl1JPr+q227GNIQ/CsnzIAMTEKbwDY0nEZeqAfSdfo14awLm UDJdwdqDjfPLvNIV+ZlwA== UI-OutboundReport: notjunk:1;M01:P0:aEG3cO64dQE=;927l3QJ2sB5JLvSoaBw5cYJ1h3k oWlhF2eZTbR7ZSUj8M6lwAnU2eDVomRTRMgUDLjjFEAg/RUR2b0Hm0y+CEoDAUFPHWEUlPg94 NuBXkBQ6XNfd9BeXEnxB08dMeU1Q6FQJfoLsyEgYYVebfYu2GmgKVSKvICU/bvztzVTKZkhKh LesE9z2vlonNO15Gh4NFs6N6vid8ztMl2x0Tu1mNQHOuW48H3W1225SnatZztznAfwukn4ZWI 1J5VAoag1WalvhuhxkdZUW+1bEYPFm9dGSUcOAifh0F2UhbA5AZiKAtOoMkW+3gGnRHt+CPLT 6HQo2ROAYIGGlf2pvNzIP7vDmKzBLlYz7bCIl5jjgw5LO3eU6iclGK0ismavsf1RvzpXVmeb9 SAOu2/RF9bUFFCcNcJzmmpyOw+850kdIEochT5q5TWyvP1sPrjUbWvfbDdsKdzkJYBPIX+Lk6 fWiWtBNH6//um0sFYM65vmaPywjm7K9GI3tNsIr5xCk8WvT1A3kUHd1pM+vHjWptmhtvXylZh om+Uk033MM4llwlhdwn96HvukA5z20YhTpYcgeondCk77U8DT+m6wXnzB65ISDzX+DuYLYwQW JuwbE8jOQp+59blSivqYw2ri59YlYJjqgKYDsoqg5Pri/1/iaHc/pHTmngjFUnhqwha+m/oLH R01t1pG0rvIl9NW6/uFqmaCMZK1odxVyjnZuBmSR71DpLll4qKvAwxLMInYycFLPK7vnDu8Qc YX5mHFeuBQT/Lurdcfeh3NZ0VhOGGaqLpZ2IrywC5AkNBMnu+t12Wt/jnNUSoWwq82xQ+U3+ Received-SPF: pass client-ip=212.227.15.18; 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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:148450 Archived-At: On Fri, 29 Nov 2024 21:16:09 +0000 Heime wrot= e: > On Saturday, November 30th, 2024 at 8:41 AM, Stephen Berman > wrote: > >> On Fri, 29 Nov 2024 20:15:04 +0000 Heime heimeborgia@protonmail.com wro= te: >> >> > On Saturday, November 30th, 2024 at 7:54 AM, Stephen Berman >> > stephen.berman@gmx.net wrote: >> > >> > > On Fri, 29 Nov 2024 17:34:01 +0000 Heime via Users list for the GNU= Emacs >> > > 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 val= ue >> > > 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 t= hen >> > be applied only when a string is passed. Which undoubtedly needs a co= nditional >> > 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' AFAI= K >> (but there are several variants and extensions of pcase, and I'm not to= o >> familiar with them, so maybe some of them do error handling), but >> `condition-case' is the basic error handling form in Elisp. Alternative= ly, >> 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 > > For the interactive call I want to pass the three values so that > actm-seqr will be a list of three objects. > > Thus I do > > (list (list colw rsel scope)) > > Would the above be correct? Yes. > With only (list colw rsel scope) emacs does complain. Because that means the interactive call passes three arguments, but your definition of `poalatuk' only specifies one argument parameter. > I wonder whether actm-seqr will give me ((72 tabtrail global)) > and not (72 tabtrail global). I don't know what you mean; actm-seqr is the function parameter, a variable whose value is whatever is passed on calling the function either interactively or noninteractively. > Have also been looking at the possibility of using > > (list (list colw (intern rsel) (intern scope))) > > Or would this be considered replication? Because the call > to intern would happen later anyway. Then it would cause the error you reported in your OP. Steve Berman