[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Instead of pcase
From: |
Ihor Radchenko |
Subject: |
Re: Instead of pcase |
Date: |
Mon, 25 Dec 2023 14:26:23 +0000 |
Richard Stallman <rms@gnu.org> writes:
> Constrained variable: (PRED VARIABLE) or, more generally,
> (PRED VARIABLE OTHER-ARGS...)
> ...
> (symbolp sym) ; Match any symbol, bind `sym' to it.
This one is clear, especially as ,(symbolp sym) - comma indicates that
the form is special.
> (> num-foos min-foos) ; Match any number greater than MIN-FOOS,
> ; bind `num-foos' to it.
But this is confusing - which symbol to bind and which one to eval is
based purely on position in the ,(PRED ...) pattern. In such scenario,
it is very easy to confuse that num-foos will be let-bound. It does not
help that the whole thing looks like an ordinary function call.
I'd suggest to provide a more clear indication about which symbol will
be bound, so that it stands out compared to ordinary variables like
min-foos.
> Constrained variable constructs can be nested
>
> For example,
>
> (< (integerp num-foos) 1) ; Match any integer number > 1,
> ; bind `num-foos' to it.
This is also confusing. Looking at the above expression, I expect that
we compare the return value of `integerp' with 1, but it is not the case
- integerp returns nil or t. Again, it looks deceivingly similar to
normal function call.
> General constrained variable: (constrain VAR EXPRESSION)
>
> This general constrained variable pattern binds VAR to the
> value being matched against, tentatively, then evaluates EXPRESSION.
> If the result is true, the match succeeds and leaves VAR
> bound to that value.
>
> For instance,
>
> (constrain x (and (> x 0) (< x 100)))
>
> succeeds if the value being matched aainst is in the open interval (0, 100),
> and in that case it binds x to that value.
This looks much better, as `constrain' is a special keyword that can be
easily recognized and not confused with a function call.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
- Re: [External] : Re: cond*, (continued)
- Re: [External] : Re: cond*, Richard Stallman, 2023/12/20
- Re: [External] : Re: cond*, Richard Stallman, 2023/12/20
- cond*, Richard Stallman, 2023/12/17
- Re: cond*, Adam Porter, 2023/12/18
- Re: cond*, Richard Stallman, 2023/12/20
- Re: Instead of pcase, Richard Stallman, 2023/12/15
- Re: Instead of pcase, Adam Porter, 2023/12/16
- Re: Instead of pcase, Richard Stallman, 2023/12/19
- Re: Instead of pcase, Adam Porter, 2023/12/20
- Re: Instead of pcase, Richard Stallman, 2023/12/22
- Re: Instead of pcase,
Ihor Radchenko <=
- Re: Instead of pcase, Richard Stallman, 2023/12/26
- Re: Instead of pcase, Ihor Radchenko, 2023/12/28
- Re: Instead of pcase, Richard Stallman, 2023/12/29
- Re: Instead of pcase, Richard Stallman, 2023/12/22
- Re: Instead of pcase, Richard Stallman, 2023/12/12
- Re: Instead of pcase, Richard Stallman, 2023/12/10