unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Heime via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: Stephen Berman <stephen.berman@gmx.net>
Cc: Heime via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: Re: Passing a list of symbols to function argument
Date: Fri, 29 Nov 2024 20:15:04 +0000	[thread overview]
Message-ID: <Y1i-JfzbUA9f_jnKFMPvCa3vZxWGPO7-THyPGEaCAwKwDgkBcq_fQ6NaDMjhHOMu8xtY7CJ65dBCsmENge3f2fO0faYW-GmW_5T-iNNskto=@protonmail.com> (raw)
In-Reply-To: <87ser97r3k.fsf@gmx.net>






Sent with Proton Mail secure email.

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 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 then 
be applied only when a string is passed.  Which undoubtedly needs a conditional
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))))



  reply	other threads:[~2024-11-29 20:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-29 17:34 Passing a list of symbols to function argument Heime via Users list for the GNU Emacs text editor
2024-11-29 19:54 ` Stephen Berman
2024-11-29 20:15   ` Heime via Users list for the GNU Emacs text editor [this message]
2024-11-29 20:41     ` Stephen Berman
2024-11-29 21:16       ` Heime via Users list for the GNU Emacs text editor
2024-11-29 21:29         ` Stephen Berman
2024-11-29 21:41           ` Heime via Users list for the GNU Emacs text editor
2024-11-29 21:52             ` Stephen Berman
2024-11-29 22:45               ` Heime via Users list for the GNU Emacs text editor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='Y1i-JfzbUA9f_jnKFMPvCa3vZxWGPO7-THyPGEaCAwKwDgkBcq_fQ6NaDMjhHOMu8xtY7CJ65dBCsmENge3f2fO0faYW-GmW_5T-iNNskto=@protonmail.com' \
    --to=help-gnu-emacs@gnu.org \
    --cc=heimeborgia@protonmail.com \
    --cc=stephen.berman@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).