[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Instead of pcase
From: |
Adam Porter |
Subject: |
Re: Instead of pcase |
Date: |
Sat, 16 Dec 2023 00:57:43 -0600 |
User-agent: |
Mozilla Thunderbird |
Hello Richard,
On 12/15/23 22:23, Richard Stallman wrote:
> As well, what if the user needed to pass an already-bound argument in
> addition to the one being bound there? With pcase, the binding would be
> explicit, and the accompanying `guard' expression would have a clear
> place in lexical scope, so there would be no doubt about where the
> arguments were bound.
I am having trouble grasping the abstract description. Would you like
to show an example of the putative problem that you are concerned
about? I might understand it then.
Here are some examples I put together that demonstrate, IMHO, that
pcase's binding forms are more explicit and less confusing.
;; In the match, will "bar" be called with "CONST" or "FOO" as the
;; first argument?
(cl-labels ((bar (one two)
t))
(let ((foo 'FOO)
(const 'CONST)
(body '(CONST FOO)))
(cond* (:match ((or `()
`(,(bar foo const)))
body)))))
;; In the match, will "bar" be called with "CONST" or "FOO" as the
;; first argument?
(cl-labels ((bar (one two)
t))
(let ((foo 'FOO)
(const 'CONST)
(body '(FOO CONST)))
(cond* (:match ((or `()
`(,(bar const foo)))
body)))))
;; In the match, will "bar" be called with "FOO" or "B" as the second
;; argument?
(cl-labels ((bar (one two)
t))
(let ((foo 'FOO)
(body '(A B)))
(cond* (:match ((or `()
`(,(bar const foo)))
body)))))
;; pcase's bindings are more explicit and less confusing:
(cl-labels ((bar (one two)
t))
(let ((foo 'FOO)
(const 'CONST)
(body '(A B)))
(pcase body
((or `()
(and `(,const ,foo) ; Explicitly binds within scope of clause.
(guard (bar const foo)))) ; Binding of "foo" clearly
shadows that of the LET form.
(format "CONST:%S FOO:%S" const foo))
(_ "No match"))))
;; "CONST:A FOO:B"
- Re: cond*, (continued)
- RE: [External] : Re: cond*, Drew Adams, 2023/12/19
- 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 <=
- 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, 2023/12/25
- 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