emacs-devel
[Top][All Lists]
Advanced

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

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


From: Eli Zaretskii
Subject: Re: The poor state of documentation of pcase like things.
Date: Sat, 19 Dec 2015 19:08:18 +0200

> From: Michael Heerdegen <address@hidden>
> Cc: John Wiegley <address@hidden>,  address@hidden,  address@hidden,  
> address@hidden
> Date: Sat, 19 Dec 2015 16:55:12 +0100
> 
> > >     (pcase value
> > >       (`(1 2 ,foo 3)
> > >        (message "Matched 1, 2, something now bound to foo, and 3"))
> > >       (foo
> > >        (message "Match anything at all, and bind it to foo!"))
> > >       (`(,the-car . ,the-cdr))
> > >        (message "Match any cons cell, binding the car and cdr locally"))
> >
> > So to bind something to 'foo' you just use "foo", but to bind
> > something to 'the-car' and 'the-cdr' you need to use ",the-car" and
> > ",the-cdr"?  Why the inconsistency?
> 
> The examples only differ because some symbols occur inside backquote and
> others don't.

",foo" in the first pattern is also inside a backquote, but it is
still different from "foo" in the second pattern and ",the-car" in the
third.  So I'm still not out of the woods regarding the inconsistency.

> > >     (pcase value
> > >       (`(1 2 ,(or 3 4)
> > >          ,(and (pred stringp)
> > >                (pred (string> "aaa"))
> > >                (pred (lambda (x) (> (length x) 10)))))
> > >        (message "Matched 1, 2, 3 or 4, and a long string "
> > >                 "that is lexically greater than 'aaa'")))
> >
> > Why did you use 'lambda' for the 3rd predicate, but not for the 2nd?
> > Is it just a way to show off use of 'lambda', or is there some
> > significant difference between these 2 use cases that requires a
> > 'lambda' in the latter case?  More generally, when is 'lambda'
> > required in a predicate like these ones?
> 
> That's explained in the pcase docstring.

Which part of it?

> > Isn't it true that pcase-let is just a short-hand for a pcase that
> > assigns values according to patterns, and has nil as the default
> > value?  If that's true, I think it explains better what pcase-let
> > does, especially when backed up by an example of a pcase and the
> > equivalent pcase-let.
> 
> I think there are more differences, AFAICT pcase-let can't "fail"

Neither can a pcase that has a default clause, right?

> and it can bind multiple value--pattern pairs.

Did John's tutorial include an example of that?

Or maybe I shouldn't ask about pcase-let, as it's not for the
uninitiated yet? ;-)



reply via email to

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