emacs-devel
[Top][All Lists]
Advanced

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

Re: Question on pcase


From: Michael Heerdegen
Subject: Re: Question on pcase
Date: Fri, 23 Oct 2015 23:01:46 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Przemysław Wojnowski <address@hidden> writes:

> line 103:
> ;; that's the case only for the string "Hallo" (why would it not be
> ;; useful to leave out the quote before the symbol `a'?
>
> Is it a question to the reader or you just forgot to remove?

A question to the reader - forgetting to quote a symbol is a common
pitfall.  If the user works the reason out for herself, it is probably
easier to remember.

> ---------------
> line 136:
> ;; If matching any pattern established a variable binding, you can
> ;; refer to these bindings in the following patterns.
>
> Shouldn't end with "[...]the following patterns in the same branch."?
> Without this there's a little confusion on whether the binding is also
> available in the below branches too.

Good catch, indeed.

> ---------------
> Around line 177 - (let PAT EXP) example:
> (pcase x
>   ((and (pred numberp)
>         (let (pred (lambda (x) (< 5 x))) (abs x)))
>    t)
>   (_ nil))
> IMHO it would be better to simplify this example to contain only "let" part:
> (pcase x
>   ((let (pred (lambda (x) (< 5 x))) (abs x))
>    t)
>   (_ nil))
> And in explanation write order of evaluation: result of EXP(x) is
> passed to PAT. Anyway, this part wasn't clear to me.

Mmh, so this part is a bit unclear.  Thanks, maybe I can even find a
better suited example.


> What are some good (concrete) use cases for the pcase? When would you
> suggest to use it instead of cond or other similar constructs?

IME you know when you need it after having learned it.

The first times where you use it in your code will probably be cases
where a `case' or a `cond' nearly fit, but is not sufficient.
E.g. where a `cl-case' would be appropriate for most branches but you
need to test a condition in one branch.

Start like that, and keep in mind that `pcase' is in your toolbox while
coding.

For concrete use cases - just see the Emacs sources!  But it's hard to
describe the typical use case for `pcase' as it is hard to describe a
typical use case for a tool chest.


Thanks for your feedback!

Michael.



reply via email to

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