From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.emacs.bugs Subject: bug#31311: 27.0; doc of `pcase' Date: Sat, 26 May 2018 11:01:53 +0200 Message-ID: <87fu2e23jy.fsf@gnuvola.org> References: <83wowqrmp8.fsf@gnu.org> <87efixlv8g.fsf@web.de> <83muxlsvfm.fsf@gnu.org> <871sexlqvw.fsf@web.de> <83k1sps9n3.fsf@gnu.org> <87wowpndoo.fsf@gmail.com> <87fu3c6cm3.fsf@gnuvola.org> <83zi1kqynx.fsf@gnu.org> <871seh3yw8.fsf@gnuvola.org> <877eo9kmid.fsf@web.de> <87y3gl574j.fsf@gnuvola.org> <87po1xc5lb.fsf@web.de> <87muwz6ftl.fsf@gnuvola.org> <874lj7r5mx.fsf@web.de> <878t8e2lw1.fsf@gnuvola.org> <83in7ecrxo.fsf@gnu.org> <87r2m22ndx.fsf@gnuvola.org> <87tvqwfxzv.fsf@gmail.com> Reply-To: 31311@debbugs.gnu.org NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Trace: blaine.gmane.org 1527331031 19247 195.159.176.226 (26 May 2018 10:37:11 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 26 May 2018 10:37:11 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Noam Postavsky To: 31311@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat May 26 12:37:07 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fMWZM-0004oz-Nx for geb-bug-gnu-emacs@m.gmane.org; Sat, 26 May 2018 12:37:05 +0200 Original-Received: from localhost ([::1]:48429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fMWbS-0000pa-1J for geb-bug-gnu-emacs@m.gmane.org; Sat, 26 May 2018 06:39:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fMWbK-0000pP-93 for bug-gnu-emacs@gnu.org; Sat, 26 May 2018 06:39:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fMWbH-0007oF-Dm for bug-gnu-emacs@gnu.org; Sat, 26 May 2018 06:39:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:41147) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fMWbH-0007oB-9v for bug-gnu-emacs@gnu.org; Sat, 26 May 2018 06:39:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fMWbG-0002i7-UY for bug-gnu-emacs@gnu.org; Sat, 26 May 2018 06:39:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Thien-Thi Nguyen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 26 May 2018 10:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31311 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 31311-submit@debbugs.gnu.org id=B31311.152733113410397 (code B ref 31311); Sat, 26 May 2018 10:39:02 +0000 Original-Received: (at 31311) by debbugs.gnu.org; 26 May 2018 10:38:54 +0000 Original-Received: from localhost ([127.0.0.1]:49043 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fMWb7-0002hZ-Ni for submit@debbugs.gnu.org; Sat, 26 May 2018 06:38:53 -0400 Original-Received: from mail.agora-net.com ([67.59.132.6]:39526) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fMWb4-0002hF-TO for 31311@debbugs.gnu.org; Sat, 26 May 2018 06:38:51 -0400 Original-Received: from ttn by mail.agora-net.com with local (Exim 4.82) (envelope-from ) id 1fMWb3-0003kM-Tu; Sat, 26 May 2018 06:38:50 -0400 Original-Received: from ttn by zigzag.favinet with local (Exim 4.80) (envelope-from ) id 1fMV5P-0005F4-1w; Sat, 26 May 2018 11:02:03 +0200 In-Reply-To: <87tvqwfxzv.fsf@gmail.com> (Noam Postavsky's message of "Thu, 24 May 2018 19:13:40 -0400") X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: ttn@gnuvola.org X-SA-Exim-Scanned: No (on mail.agora-net.com); SAEximRunCond expanded to false X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:146567 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable () Noam Postavsky () 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 =E2=80=98s/case/cl-&/g=E2=80=99 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 =E2=80=98case=E2=80=99 in Emacs Lisp is actually =E2=80=98cl-case=E2=80=99, which has a second-class citizen feel. In using =E2=80=98cl-case=E2=80=99 as one of the conceptual parents = of =E2=80=98pcase=E2=80=99, my reasoning is: =2D Build on "expectatious programmer" mindset. Programmers new to Emacs Lisp might feel that same surprise i felt and do what i did: reach for =E2=80=98cl-case=E2=80=99 immediately, making it a habit= to such an extent as to consider it intrinsic (thus, familiar). =2D I agree somewhat that =E2=80=98cl-destructuring-bind=E2=80=99 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 =E2=80=98pcase=E2=80=99 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, =E2=80=98app=E2=80=99 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. =2D-=20 Thien-Thi Nguyen ----------------------------------------------- (defun responsep (query) (pcase (context query) (`(technical ,ml) (correctp ml)) ...)) 748E A0E8 1CB8 A748 9BFA =2D-------------------------------------- 6CE4 6703 2224 4C80 7502 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlsJIoUACgkQZwMiJEyAdQLh3ACfdvXpzsPgAisgE8rfUwKYPwtv fs4AoJN9GCeWMFvxNd4DfAcF78p4NyvK =2NtZ -----END PGP SIGNATURE----- --=-=-=--