emacs-devel
[Top][All Lists]
Advanced

[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"



reply via email to

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