[Top][All Lists]

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

Re: Code for cond*

From: Stefan Monnier
Subject: Re: Code for cond*
Date: Wed, 24 Jan 2024 10:55:37 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

> To explain this correctly, I’d need to understand where the mental
> model breaks down.  For example, I was surprised that this
> forward/reverse symmetry was not maintained:
> (let ((list-var '(foo moo loo))
>       (other 'boo))
>   `(,@list-var . ,other)). ; -> (foo moo loo . boo)
> (pcase '(foo moo loo . boo)
>   (`(,@list-var . ,other)
>    (format "Got %S: %S" list-var other))). ; -> nil, expected “Got (foo moo 
> loo): boo"

Note that

    (let ((list-var '(foo moo))
          (other '(loo . boo)))
      `(,@list-var . ,other))

returns the same `(foo moo loo . boo)`, so there is not a unique way for
a pattern like `(,@list-var . ,other) to match a given list.
That's a large part of the reason why ,@ is not supported in Pcase's
backward patterns.

> I also noticed that "Backquote-Style Patterns: Backquote Patterns.” is
> quite deep in the pcase doc structure, coming just after  “Extending
> ‘pcase’: Extending pcase.  Define new kinds of patterns.”.  Yet most
> pcase examples I come across in the wild use backquote patterns.
> I don’t know if that’s an intentional arrangement, or was put in place
> before people had experience with pcase and voted with their key-taps
> for backquote style. 

I think it's a mistake due to the docs being written by people too
familiar with the implementation (where core Pcase does not include
backquote patterns).  I'd welcome a patch which corrects this, indeed.


reply via email to

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