[Top][All Lists]

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

bug#31311: 27.0; doc of `pcase'

From: Thien-Thi Nguyen
Subject: bug#31311: 27.0; doc of `pcase'
Date: Sat, 26 May 2018 11:01:53 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

() Noam Postavsky <address@hidden>
() Thu, 24 May 2018 19:13:40 -0400

   The manual should refer to `cl-case', not `case'.

   > +These render @code{case} unsuitable for strings or compound
   > +data structures (e.g., lists or vectors).
   > +For that, why not use @code{cond}?  Wait, what?  @dots{}

   I guess this is supposed to be funny, but I think it might
   confuse the reader.

I did ‘s/case/cl-&/g’ in commit 468e82790f1, and converted the
haha attempt text to: "(And here we end up in a circle.)"

   I don't think pcase should be referred to as a
   hybrid of cond and cl-case; maybe a hybrid of
   cond and cl-destructuring-bind.  Or perhaps:
   like cl-case, only more so.

Many computer languages have an intrinsic case-ish construct, so
it was a bit surprising for me to learn that ‘case’ in Emacs
Lisp is actually ‘cl-case’, which has a second-class citizen
feel.  In using ‘cl-case’ as one of the conceptual parents of
‘pcase’, my reasoning is:

- Build on "expectatious programmer" mindset.  Programmers new
  to Emacs Lisp might feel that same surprise i felt and do what
  i did: reach for ‘cl-case’ immediately, making it a habit to
  such an extent as to consider it intrinsic (thus, familiar).

- I agree somewhat that ‘cl-destructuring-bind’ might be a
  better parent, especially for structural pattern matching, but
  it does not have widespread analogs in other programming
  languages, and its operation is not as easy to grasp as a
  case-ish construct.  Too, structural patterns are but one kind
  of pattern that ‘pcase’ supports.

So, i understand your point (i believe) but disagree.

   > +       (app (match-string 1)                 ; @r{line 6}

   You have to pass the original string to match-string.

Yes, ‘app’ handles that.  There is an explanation in one of the
paragraphs following the code.  Anyway, thanks for pointing this
out, as the paragraph in question lacked a reference "line 6"
due to oversight on my part -- fixed in commit 6aace45830.

   > +            val))                            ; @r{line 7}
   > +      (let val (list "149" 'default)))       ; @r{line 8}
   > +     val)))                                  ; @r{line 9}

   This doesn't seem like a great example of pcase usage.  Not
   sure if you want to introduce the extended `rx' pattern here,
   but it works better for this, IMO:

       (pcase x
         ((and (pred stringp)
               (rx bol "key:" (let val (+ (any digit))) eol))
         (_ 'default))

Thanks for the tip; that's certainly more elegant.  This example
is admittedly a bit contrived, but i think its merit is that it
stays w/ the basic core patterns, using them in idiomatic ways.

I think i saw in another thread (bug report?) that rx.el needs
documentation.  It would be great if those docs could xref this
example w/ the re-re-formulation you wrote.

Thien-Thi Nguyen -----------------------------------------------
 (defun responsep (query)
   (pcase (context query)
     (`(technical ,ml) (correctp ml))
     ...))                              748E A0E8 1CB8 A748 9BFA
--------------------------------------- 6CE4 6703 2224 4C80 7502

Attachment: signature.asc
Description: PGP signature

reply via email to

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