From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Heime via Users list for the GNU Emacs text editor Newsgroups: gmane.emacs.help Subject: Re: Passing a list of symbols to function argument Date: Fri, 29 Nov 2024 21:16:09 +0000 Message-ID: References: <87ser97r3k.fsf@gmx.net> <87ldx17oxv.fsf@gmx.net> Reply-To: Heime Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31085"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Heime via Users list for the GNU Emacs text editor To: Stephen Berman Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Nov 29 22:16:46 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 1tH8M2-0007ys-BG for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 29 Nov 2024 22:16:46 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tH8Lf-00053I-F9; Fri, 29 Nov 2024 16:16:23 -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 1tH8La-00052f-S6 for help-gnu-emacs@gnu.org; Fri, 29 Nov 2024 16:16:20 -0500 Original-Received: from mail-10698.protonmail.ch ([79.135.106.98]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tH8LY-0001tQ-Nc for help-gnu-emacs@gnu.org; Fri, 29 Nov 2024 16:16:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1732914973; x=1733174173; bh=KlyYkPA9yuLvNSYOlTDWJmhOHn64wzCNWoPq/7P0B6g=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=wLpDstLdWGyTY7NM0xTLbNBz5kH2Kq/tUMauLPC4DrT3xeYp/+MGPD3ECx/UT8n5o DJyHyt+WbPLiJ+HwT537xdJNB+c96VBr0bQLCTH0d0T4QYfsscfE74FfcSBqTe9wpQ JrgW7vEzn7+Awv+Qs1j5EqNVbYCcyiLVpsdAfOMNx1bsYNztGpf9L18UJu/J6ArGKT XlKRNANpBBJUI8BKl7A8pBue1peK+ixzgiH3/26IZNwyYcrg8Qxdm43y3N325zkDXu ZdKLJQMMq/mvVvMoHaZFRDLgtqVYsKcR6BWOyCRMc0tQvIv1ENdKOS3GAkZPyd7W6z MNY4ZHfb7mt0Q== In-Reply-To: <87ldx17oxv.fsf@gmx.net> Feedback-ID: 57735886:user:proton X-Pm-Message-ID: e40c5461a5ae6ce5ca0a8efe56a9bb73eed72a03 Received-SPF: pass client-ip=79.135.106.98; envelope-from=heimeborgia@protonmail.com; helo=mail-10698.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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:148448 Archived-At: 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 wrote= : >=20 > > On Saturday, November 30th, 2024 at 7:54 AM, Stephen Berman > > stephen.berman@gmx.net wrote: > >=20 > > > On Fri, 29 Nov 2024 17:34:01 +0000 Heime via Users list for the GNU E= macs > > > text editor help-gnu-emacs@gnu.org wrote: > > >=20 > > > > Why do I get > > > >=20 > > > > Wrong type argument: stringp, tabtrail > > > >=20 > > > > When using the call > > > >=20 > > > > (poalatuk '(72 tabtrail global)) > > > >=20 > > > > to the function > > > >=20 > > > > (defun poalatuk (actm-seqr) > > > >=20 > > > > (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")) ) > > > >=20 > > > > ;; Pass a single list as argument > > > > (list (list colw rsel scope))) ) > > > >=20 > > > > ;; ------------------------------------------------------------- > > > >=20 > > > > (message "poalatuk: %S" actm-seqr) > > > >=20 > > > > (let* ( (colw (nth 0 actm-seqr)) ;; Extract column width. > > > > (rsel (intern (nth 1 actm-seqr))) ;; Extract mode selector. > > >=20 > > > ^^^^^^^^^^^^^^^^^^^^^^^^^^ > > >=20 > > > 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 th= e > > > obarray) whose name is given by the string. > > >=20 > > > Steve Berman > >=20 > > 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. > >=20 > > Perhaps I should also test whether the argument is a symbol or do the i= f > > and pcase handle errors (because the commands will be skipped). > >=20 > > (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)))) >=20 >=20 > 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 c= alls use` completing-read', which returns strings), > you could condition on `called-interactively-p'. >=20 > 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=20 (list (list colw rsel scope)) Would the above be correct? With only (list colw rsel scope) emacs does complain. I wonder whether actm-seqr will give me ((72 tabtrail global)) and not (72 tabtrail global). 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.