[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, 01 Jan 2024 14:33:11 +0000 |
Richard Stallman <rms@gnu.org> writes:
> For tests which don't fit that form, you can use `constrain'.
> Here's a valid example:
>
> `(,(integerp smaller)
> ,(constrain bigger (> (= (mod (- (integerp bigger) dec) 5) 0) smaller)))
>
> Does the text I sent fail to make this clear? Would you please take
> a look, and if it is not clear, tell me why?
Your description is clear. However, it is somewhat similar to the
existing `pcase' description in a way that it is also clear, but goes in
odds with the usual Elisp structures - I see nested "constrained
variable" construct yet as another DSL. I see myself coming to back the
documentation of `cond*' again and again, just as I do with `pcase' now.
Let me try to illustrate the problem with another example:
;; ALIST-VAL = '((:key1 . 1) (:key4 . 2))
;; Match alist key where the key is one of a know set of keys.
(match* (memq (alist-get key alist-val) '(:key1 :key2 :key3)) :key1)
>From the description of "constrained variable" construct, the above will
(1) test if ALIST-VAL contains a record with KEY=:key1 key; (2) test if
KEY=:key1 is one of :key1 :key2 :key3.
However, the above is also deceivingly similar to Elisp expression that
tests the return value of `alist-get': (memq 1 '(:key1 :key2 :key3))
--
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: Instead of pcase,
Ihor Radchenko <=
- Re: Instead of pcase, Richard Stallman, 2024/01/02
- Re: Instead of pcase, Richard Stallman, 2024/01/02
- Re: Instead of pcase, Ihor Radchenko, 2024/01/03
- Re: Instead of pcase, Richard Stallman, 2024/01/04
- Re: Instead of pcase, Ihor Radchenko, 2024/01/06
- Re: Instead of pcase, Richard Stallman, 2024/01/07
- Re: Instead of pcase, Ihor Radchenko, 2024/01/08
- Re: Instead of pcase, Richard Stallman, 2024/01/26