emacs-devel
[Top][All Lists]
Advanced

[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: Mon, 12 Feb 2024 19:41:12 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

> With the cond* syntax for simple constrained variables,
> that ordering is natural.  the variable to be bound
> goes in the same spot as its value will be passed to the predicate.
>
>  (< x 15)  as a pattern means, conceptually, bind x and evaluate (< x 15).
>
> So the question is whether to use
>
>   (pred < x 15)
>
> or just
>
>   (< x 15)
>
> I prefer the latter because it is more concise.
> The equivalent (and (pred...) car) is used often in pcase
> so other forms ofit will be used often also.

As mentioned in an email I had sent before, I agree that it'd be nice
for `pred` to be able to bind a variable, since indeed when that's
needed the `(and (pred ...) VAR)` form is rather inconveniently verbose.

Your syntax (FUN VAR ARGS...) has two disadvantages in my view:

- It fixes the argument to be checked as the first argument.
- It does not syntactically distinguish the VAR from the normal
  arguments, making a bit too magical for my taste.

Maybe a good alternative is to annotate the special arg with a comma:

    (pred (FUN ,VAR ARGS...))

this way we can trivially support other placements:

    (pred (FUN ARG1 ARG2 ,VAR ARGS...))

Of course, there remains the question whether this usage should be the
one that gets the privilege of not needing a dedicated "keyword", i.e. to
allowing using it without the surrounding `pred`:

    (FUN ,VAR ARGS...)

Until now, in `pcase` I refrained from eating this huge chunk of
the namespace.


        Stefan




reply via email to

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