help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [External] : Re: pcase without code duplication


From: Drew Adams
Subject: RE: [External] : Re: pcase without code duplication
Date: Fri, 23 Apr 2021 03:51:16 +0000

> > I am using pcase, but am wondering whether I can have pcase
> > for 0 and 2 do the same things without adding a separate pcase
> > (0 and duplicating the statements.
> >
> > (pcase orthogr-region
> >   (0 ... )    ; same operations as pcase 2
> >   (1 ... )
> >   (2 ... )    ; operations
> >   (_ ... ) )
> 
> (let ((xx 2))
>   (pcase xx
>     (1 (message "one"))
>     ((or 0 2) (message "zero or two"))
>     (_ (message "something else"))))

And even ordinary cl-case (aka case) will do,
if that's all you're doing.

(cl-case xx
  (1     (message "one"))
  ((0 2) (message "zero or two"))
  (t     (message "something else")))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]