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: Michael Heerdegen
Subject: Re: The poor state of documentation of pcase like things.
Date: Sat, 19 Dec 2015 18:40:25 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Eli Zaretskii <address@hidden> writes:

> > > 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?

  (pred FUN)    matches if FUN applied to the object returns non-nil.

[...]

FUN can take the form
  SYMBOL or (lambda ARGS BODY)  in which case it’s called with one argument.
  (F ARG1 .. ARGn) in which case F gets called with an n+1’th argument
                        which is the value being matched.

So, FUN is generally a symbol or a lambda, as everywhere, nothing
special.  In addition there is a 

  (F ARG1 .. ARGn)

("in which case F gets called with an n+1’th argument which is the value
being matched.")

form that can be used to abbreviate things in some cases.  Probably you
got confused with this additional possible syntax.

> > > 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?

Yes - but `pcase-let' never fails AFAIR, no matter how the clauses look
like.

> Did John's tutorial include an example of that?

Haven't looked yet.

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

I don't expect the semantics of `pcase-let' to change much in the
future, and I think it's quite unquestioned that it's useful and a
good-to-have form per se.


Michael.



reply via email to

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