GNU bug report logs - #31311
27.0; doc of `pcase'

Previous Next

Package: emacs;

Reported by: Drew Adams <drew.adams <at> oracle.com>

Date: Sun, 29 Apr 2018 16:04:02 UTC

Severity: wishlist

Found in version 27.0

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Thien-Thi Nguyen <ttn <at> gnu.org>
To: 31311 <at> debbugs.gnu.org
Cc: Noam Postavsky <npostavs <at> gmail.com>
Subject: bug#31311: 27.0; doc of `pcase'
Date: Sat, 26 May 2018 11:01:53 +0200
[Message part 1 (text/plain, inline)]
() Noam Postavsky <npostavs <at> gmail.com>
() 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))
          val)
         (_ '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

[signature.asc (application/pgp-signature, inline)]

This bug report was last modified 3 years and 23 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.