[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.
Stefan
- Re: Code for cond*, (continued)
- Re: Code for cond*, Emanuel Berg, 2024/01/24
- Re: Code for cond*, Po Lu, 2024/01/25
- Re: Code for cond*, Emanuel Berg, 2024/01/25
- Re: Code for cond*, Po Lu, 2024/01/25
- Re: Code for cond*, Emanuel Berg, 2024/01/25
Re: Code for cond*, Richard Stallman, 2024/01/19
Re: Code for cond*, Stefan Monnier, 2024/01/23
- Re: Code for cond*, JD Smith, 2024/01/23
- Re: Code for cond*, Stefan Kangas, 2024/01/24
- Re: Code for cond*, JD Smith, 2024/01/24
- Re: Code for cond*,
Stefan Monnier <=
- Re: Code for cond*, Stefan Monnier, 2024/01/24
- Re: Code for cond*, JD Smith, 2024/01/24
- Re: Code for cond*, Stefan Monnier, 2024/01/24
- RE: [External] : Re: Code for cond*, Drew Adams, 2024/01/24
RE: [External] : Re: Code for cond*, Drew Adams, 2024/01/24
Re: Code for cond*, Madhu, 2024/01/25
Re: Code for cond*, Stefan Monnier, 2024/01/25
Re: Code for cond*, JD Smith, 2024/01/25
Re: Code for cond*, JD Smith, 2024/01/25
Re: Code for cond*, Alfred M. Szmidt, 2024/01/25