[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Passing a list of symbols to function argument
From: |
Stephen Berman |
Subject: |
Re: Passing a list of symbols to function argument |
Date: |
Fri, 29 Nov 2024 22:52:25 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
On Fri, 29 Nov 2024 21:41:27 +0000 Heime <heimeborgia@protonmail.com> wrote:
> On Saturday, November 30th, 2024 at 9:29 AM, Stephen Berman
> <stephen.berman@gmx.net> wrote:
>
>> > > > 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))))
>> > >
>> > > 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
>> >
>> > 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.
>
> For the interactive part, would returning
>
> (list (list colw (intern rsel) (intern scope)))
>
> pass
>
> ((72 tabtrail global)) ; list with single element being a list
>
> or
>
> (72 tabtrail global) ; list of three entries
>
> to actm-seqr?
The answer is in message displayed when you do `M-x poalatuk' and act
appropriately on the prompts, isn't it?
>> > 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.
>
> (list (list colw (intern rsel) (intern scope)))
>
> The above will be for the interactive part, so that the string values
> would be changed immediately to symbols.
>
> And since I now fixed the problem by checking with stringp so intern gets
> called when calling the function programatically with strings.
Ok.
Steve Berman
- Passing a list of symbols to function argument, Heime, 2024/11/29
- Re: Passing a list of symbols to function argument, Stephen Berman, 2024/11/29
- Re: Passing a list of symbols to function argument, Heime, 2024/11/29
- Re: Passing a list of symbols to function argument, Stephen Berman, 2024/11/29
- Re: Passing a list of symbols to function argument, Heime, 2024/11/29
- Re: Passing a list of symbols to function argument, Stephen Berman, 2024/11/29
- Re: Passing a list of symbols to function argument, Heime, 2024/11/29
- Re: Passing a list of symbols to function argument,
Stephen Berman <=
- Re: Passing a list of symbols to function argument, Heime, 2024/11/29