[Top][All Lists]

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

Re: The poor state of documentation of pcase like things.

From: Michael Heerdegen
Subject: Re: The poor state of documentation of pcase like things.
Date: Thu, 24 Dec 2015 18:46:36 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

address@hidden (Phillip Lord) writes:

> I do worry that the syntax of pcase is too complex. As an example
> compare dash.el and pcase:
> (-let [(a b _) '(1 2 3)]
>   (list a b))
> (pcase-let
>     ((`(,a ,b ,_) '(1 2 3)))
>   (list a b))

-let is only about binding.  pcase, and it's ` macro, is about matching
and binding, including condition testing etc.  Since the latter offers
more features, it is not a surprise that it can be beaten by specialized
tools in special cases wrt the length of the call.

> I've chosen an extreme example here,

I don't think that three additional colons are extreme.

> but the pcase version has a lot of punctuation (and worth remembering
> however familiar the macro expert is with punctuation not all
> emacs-lisp programmers are).

You can just use the `seq' pattern type if you are not familiar with

> > This would mess up the semantics to the worse: `_ would
> > then be a pcase pattern matching anything.  Should '_ also match
> > anything?  But how to match the symbol _ then?  If not, why should `_ be
> > different from '_ when there is no unquoting involved?
> >
> > Or should _ as a QPAT only behave different when used "not at toplevel"?
> > This would be horribly inconsequent: We would get two different types of
> > QPATs: toplevel QPATS, and non-toplevel-QPATS.  That would confuse
> > people even more, a pain to explain and to internalize.
> I thought we were not going to mention q-patterns any more!

I never said that.  "qpattern" is a useful term when describing the `
pattern.  What I said was we should avoid the old term "upattern" for
general type pcase patterns.

> I think that too much of the implementation semantics is poking
> through into the syntax.

It's a good thing if the syntax reflects the semantics.  And I don't
think that Stefan had let the semantics be dictated by implementation

> I suspect no one would notice if "_" matched anything inside a
> backquoted list, because it feels natural.

It doesn't feel natural anymore once you have used the thing yourself
and understood the concept.  Yes, pcase does look unusual at the first
look, as does Lisp, but it won't kill you, I promise.  Just give it a



reply via email to

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