[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Checking conditions unrelated to expression
From: |
Heime |
Subject: |
Re: Checking conditions unrelated to expression |
Date: |
Sun, 08 Dec 2024 14:49:34 +0000 |
Sent with Proton Mail secure email.
On Monday, December 9th, 2024 at 12:31 AM, Thibaut Verron
<thibaut.verron@gmail.com> wrote:
> Le dim. 8 déc. 2024 à 13:06, Heime via Users list for the GNU Emacs text
> editor help-gnu-emacs@gnu.org a écrit :
>
> > It looks like pcase can only be used with some variable condition
> >
> > This will check condition of featr
> >
> > (pcase featr
> > ('this (do-this))
> > ('that (do-that))
> > (_ (message "some message"))
> >
> > What if I want to check a number of conditions, not all dependent upon
> > featr, what should one do?
> >
> > Suppose I want to test (eq duck 'quack), cannot use a pcase because tests
> > are dependent upon featr.
> >
> > (pcase featr
> > ('this (do-this))
> > ('that (do-that))
> > (_ (message "some message"))
>
>
> You can use a plain case-switch, rather than a pattern-matching one:
>
> (cond
> ((eq featr 'this) (do-this))
> ((eq featr 'that) (do-that))
> ((eq duck 'quack) (do-duck))
> (t (message "blabla")))
>
> https://www.gnu.org/s/emacs/manual/html_node/elisp/Conditionals.html
>
> You can also replace the first two cases by a pattern-matching case, if
> you'd like:
>
> (cond
> (pcase featr
> ('this (do-this) t) ;; important to return non-nil in each branch
> ('that (do-that) t)
> (_ nil))
> ((eq duck 'quack) (do-duck))
> (t (message "blabla")))
But I cannot do the other way round, right? Cannot have a pcase using featr
as EXP, but checking something else.