[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: Phillip Lord
Subject: Re: The poor state of documentation of pcase like things.
Date: Sat, 19 Dec 2015 21:57:22 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Michael Heerdegen <address@hidden> writes:

>> Not convinced. The documentation says....
>> ‘(pred numberp)’ is a pattern that simply checks that ‘exp’ is a number,
>> and ‘_’ is the catch-all pattern that matches anything.
>> for example, which made me assume that "_" matches anything.
> Anything in a backquote is implicitly quoted, and thus should behave
> like
>     'VAL              matches if the object is ‘equal’ to VAL.
> The elements in a backquoted list in a pcase pattern are _not_
> interpreted as pcase patterns, unless unquoted.  _ is not special here.
> You also can't use
>   `(1 2 (pred numberp))
> as you would expect.  Why should _ be different?

I can certainly see your point, and agree from a point-of-view of
semantics then it makes sense. But from a point-of-view of usability, I
am less convinced.

"_" is different because it has no formal semantics in the rest of lisp.
So, for example, 


returns 1. Compare this with works

(pcase 1
  (a a))

and this which errors

(pcase 1
  (_ _))

So, "_" can have any semantics we like, and remain consistent.

To me, I would expect this:

(pcase '(1)
  (`(_) 'hello))

to return 'hello and yet it does not. Set against, this, I guess you are
worried that with the semantics I suggest then you cannot do something
like this:

(pcase '(1)
  (`(_) 'hello)
  (`(1) 'goodbye))
which now returns 'goodbye, but would return 'hello. This is a valid
concern, I agree, although I think is a more minor usage (since "_" has
no special semantics, how often do you want to match this!). Perhaps, it
could be supported by a syntax like this:

(pcase '(1)
  (`('_) 'hello)
  (`(1) 'goodbye))
=> 'goodbye

Irrespective of whether you agree with this or not, what I would say is
that the current requirement for ,_ is not obvious, and that it is a
pcase "gotcha". I would say that least one concrete example in the
manual of this usage, explicitly mentioning the , is a good idea.


reply via email to

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