[Top][All Lists]

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

Re: pcase-dolist

From: Stefan Monnier
Subject: Re: pcase-dolist
Date: Wed, 08 Jul 2015 09:54:43 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

> (pcase-dolist ((and x (pred < 0)) '(-1 0 1 2))
>   (message "%s" x))
> prints all members of the sequence.

What would you want it to do?

I think it'd be the only other meaningful behavior would be to signal an
error, but that would rarely be useful.

It could also skip those elements that don't match, but then it'd be
more like a "filter" loop so it would need another name.  And it would
then be very tempting/desirable to make it possible to provide a chunk
of code to use when the pattern doesn't match.  So we'd end up with
something like

   (pcase-newdolist LIST
    (PAT1 . BODY1)
    (PAT2 . BODY2)

which would just be a shorthand for

   (dolist (x LIST)
     (pcase x
       (PAT1 . BODY1)
       (PAT2 . BODY2)

> Apart from the question whether this semantic is useful: with the
> current semantic, a name that includes "case" is irritating considering
> such a behavior.

I completely read the name as "<prefix>-dolist" but you have a good
point: the prefix has "case" in its name, which makes it misleading.

> Maybe "pdolist" (and "plet", "plet*") would be better names?

For pcase-dolist, I think the right name to use is `dolist'.

> Anyway, an idea that came to my mind more than once: `when-let',
> `if-let' should really be `pcase-when-let' , `pcase-if-let'.  They would
> be much more useful than the plain versions I think.

Yes, feel free to change them that way.

> Then `pcase-dolist' could be reimplemented using `pcase-when-let'.

Not sure what you mean: the current semantics of pcase-dolist is the
right one IMNSHO.


reply via email to

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