* pcase on multiple conditions
@ 2022-10-28 6:47 Heime
2022-10-28 7:08 ` Jean Louis
0 siblings, 1 reply; 12+ messages in thread
From: Heime @ 2022-10-28 6:47 UTC (permalink / raw)
To: Heime via Users list for the GNU Emacs text editor
Is this the way to test for two values to perform the same operation?
(pcase complt
((or 3 4)
(myfunc)))
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: pcase on multiple conditions
2022-10-28 6:47 pcase on multiple conditions Heime
@ 2022-10-28 7:08 ` Jean Louis
2022-10-28 7:44 ` Michael Heerdegen
2022-10-30 12:53 ` Emanuel Berg
0 siblings, 2 replies; 12+ messages in thread
From: Jean Louis @ 2022-10-28 7:08 UTC (permalink / raw)
To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor
* Heime <heimeborgia@protonmail.com> [2022-10-28 09:49]:
> Is this the way to test for two values to perform the same operation?
>
> (pcase complt
>
> ((or 3 4)
>
> (myfunc)))
With `or' it will become true if any of values is true. If you need to
test for all values to be true, use `and'.
I don't know how it is called in English, I believe "logics". And I
still remember learning it in primary school. It was not related to
programming, just mathematics. In many countries they teach it in
secondary schools. My remark is not related to your request.
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: pcase on multiple conditions
2022-10-28 7:08 ` Jean Louis
@ 2022-10-28 7:44 ` Michael Heerdegen
2022-10-28 9:57 ` Heime
` (2 more replies)
2022-10-30 12:53 ` Emanuel Berg
1 sibling, 3 replies; 12+ messages in thread
From: Michael Heerdegen @ 2022-10-28 7:44 UTC (permalink / raw)
To: help-gnu-emacs
Jean Louis <bugs@gnu.support> writes:
> * Heime <heimeborgia@protonmail.com> [2022-10-28 09:49]:
> > Is this the way to test for two values to perform the same operation?
> >
> > (pcase complt
> >
> > ((or 3 4)
> >
> > (myfunc)))
>
> With `or' it will become true if any of values is true.
`pcase' patterns are not values. Your interpretation of the semantics
of this `or` pattern is wrong.
Michael.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: pcase on multiple conditions
2022-10-28 7:44 ` Michael Heerdegen
@ 2022-10-28 9:57 ` Heime
2022-10-28 10:39 ` Michael Heerdegen
2022-10-28 12:05 ` Jean Louis
2022-10-30 12:55 ` Emanuel Berg
2 siblings, 1 reply; 12+ messages in thread
From: Heime @ 2022-10-28 9:57 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
------- Original Message -------
On Friday, October 28th, 2022 at 7:44 AM, Michael Heerdegen <michael_heerdegen@web.de> wrote:
> Jean Louis bugs@gnu.support writes:
>
> > * Heime heimeborgia@protonmail.com [2022-10-28 09:49]:
> >
> > > Is this the way to test for two values to perform the same operation?
> > >
> > > (pcase complt
> > >
> > > ((or 3 4)
> > >
> > > (myfunc)))
> >
> > With `or' it will become true if any of values is true.
>
>
> `pcase' patterns are not values. Your interpretation of the semantics of this` or` pattern is wrong.
>
> Michael.
I want to call "myfunc" when "complt" has value 3 or 4.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: pcase on multiple conditions
2022-10-28 7:44 ` Michael Heerdegen
2022-10-28 9:57 ` Heime
@ 2022-10-28 12:05 ` Jean Louis
2022-10-28 12:47 ` Michael Heerdegen
2022-10-28 13:14 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-10-30 12:55 ` Emanuel Berg
2 siblings, 2 replies; 12+ messages in thread
From: Jean Louis @ 2022-10-28 12:05 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
* Michael Heerdegen <michael_heerdegen@web.de> [2022-10-28 10:46]:
> Jean Louis <bugs@gnu.support> writes:
>
> > * Heime <heimeborgia@protonmail.com> [2022-10-28 09:49]:
> > > Is this the way to test for two values to perform the same operation?
> > >
> > > (pcase complt
> > >
> > > ((or 3 4)
> > >
> > > (myfunc)))
> >
> > With `or' it will become true if any of values is true.
>
> `pcase' patterns are not values. Your interpretation of the semantics
> of this `or` pattern is wrong.
I actually skipped to think of pcase, but mentioned only `or' in
general.
(let ((my-number (read-number "Number: ")))
(pcase my-number
((or 3 4) (message "Yes, it is 3 or 4"))
(t (message "Not 3 or 4")))) ⇒ "Not 3 or 4" for entry of 5
So why this does not work?
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: pcase on multiple conditions
2022-10-28 7:44 ` Michael Heerdegen
2022-10-28 9:57 ` Heime
2022-10-28 12:05 ` Jean Louis
@ 2022-10-30 12:55 ` Emanuel Berg
2 siblings, 0 replies; 12+ messages in thread
From: Emanuel Berg @ 2022-10-30 12:55 UTC (permalink / raw)
To: help-gnu-emacs
Michael Heerdegen wrote:
>>> Is this the way to test for two values to perform the
>>> same operation?
>>>
>>> (pcase complt
>>> ((or 3 4)
>>> (myfunc)))
>>
>> With `or' it will become true if any of values is true.
>
> `pcase' patterns are not values. Your interpretation of the
> semantics of this `or` pattern is wrong.
The syntax and semantics are not easy to understand but here
is an example of `pcase' use that should be simple enough, at
least what it does and how to use it.
(defun insert-mail (&optional delim)
(interactive "P")
(pcase-let ((`(,delim-beg ,delim-end) (if delim '("<" ">") '("" ""))))
(insert (format "%s%s%s" delim-beg user-mail-address delim-end)) ))
;; (insert-mail) ; incal@dataswamp.org
;; (insert-mail t) ; <incal@dataswamp.org>
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: pcase on multiple conditions
2022-10-28 7:08 ` Jean Louis
2022-10-28 7:44 ` Michael Heerdegen
@ 2022-10-30 12:53 ` Emanuel Berg
1 sibling, 0 replies; 12+ messages in thread
From: Emanuel Berg @ 2022-10-30 12:53 UTC (permalink / raw)
To: help-gnu-emacs
Jean Louis wrote:
> I don't know how it is called in English, I believe
> "logics". And I still remember learning it in primary
> school. It was not related to programming, just mathematics.
> In many countries they teach it in secondary schools.
> My remark is not related to your request.
I did it at the university, "Logic & Proof Techniques",
2009-10-02. So I guess we're that much behind, ey?
To be honest that course was a bit of a joke and I agree with
you a kid could and should understand that and/or stuff.
Well, I did anyway and I can assure you that didn't make me
pound my chest thinking I was a genious LOL
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2022-10-30 16:29 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-28 6:47 pcase on multiple conditions Heime
2022-10-28 7:08 ` Jean Louis
2022-10-28 7:44 ` Michael Heerdegen
2022-10-28 9:57 ` Heime
2022-10-28 10:39 ` Michael Heerdegen
2022-10-28 12:05 ` Jean Louis
2022-10-28 12:47 ` Michael Heerdegen
2022-10-28 13:14 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-10-30 12:58 ` Emanuel Berg
2022-10-30 16:29 ` Jean Louis
2022-10-30 12:55 ` Emanuel Berg
2022-10-30 12:53 ` Emanuel Berg
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).