From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#31311: 27.0; doc of `pcase' Date: Thu, 24 May 2018 19:13:40 -0400 Message-ID: <87tvqwfxzv.fsf@gmail.com> 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> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1527203528 32007 195.159.176.226 (24 May 2018 23:12:08 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 24 May 2018 23:12:08 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) To: 31311@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri May 25 01:12:04 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 1fLzOu-0008D9-3j for geb-bug-gnu-emacs@m.gmane.org; Fri, 25 May 2018 01:12:04 +0200 Original-Received: from localhost ([::1]:41028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLzR1-0006Gj-59 for geb-bug-gnu-emacs@m.gmane.org; Thu, 24 May 2018 19:14:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLzQs-0006F7-9q for bug-gnu-emacs@gnu.org; Thu, 24 May 2018 19:14:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLzQo-0001SU-AC for bug-gnu-emacs@gnu.org; Thu, 24 May 2018 19:14:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39152) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fLzQo-0001SN-5j for bug-gnu-emacs@gnu.org; Thu, 24 May 2018 19:14:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fLzQo-00009s-06 for bug-gnu-emacs@gnu.org; Thu, 24 May 2018 19:14:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 24 May 2018 23:14:01 +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.1527203630584 (code B ref 31311); Thu, 24 May 2018 23:14:01 +0000 Original-Received: (at 31311) by debbugs.gnu.org; 24 May 2018 23:13:50 +0000 Original-Received: from localhost ([127.0.0.1]:47049 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fLzQc-00009M-EZ for submit@debbugs.gnu.org; Thu, 24 May 2018 19:13:50 -0400 Original-Received: from mail-qt0-f178.google.com ([209.85.216.178]:40570) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fLzQa-000097-LG for 31311@debbugs.gnu.org; Thu, 24 May 2018 19:13:49 -0400 Original-Received: by mail-qt0-f178.google.com with SMTP id h2-v6so4313762qtp.7 for <31311@debbugs.gnu.org>; Thu, 24 May 2018 16:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:references:date:in-reply-to:message-id:user-agent :mime-version:content-transfer-encoding; bh=6t8XWmW1r6k+Rvrf6ccUE7sEg8D8M+BW0YigTgGi+EQ=; b=m+XEO/jvV9788g/YetVMbn2LzqBO6ble4uu0BEBoYGEg3xnsJ1/2EkUvEMzKPJLYhO S3vjWrPQwzK68PcpN0VBviT0JxZ23zUfm/SSxYd+7T2F5Ug2dc7MEjQvvTemAH3A2VQv 9uHj45Yte6E94rgJ9Dx+sLVH6KGbYQ2mbd6KyN8W7dfvjRAdlpz81L+TU87Su1xY+ubm h0QDh1WtDX+bVrFBdFv2DuFIPMVvOF5hfIPsEMfQr6536yBjYnjOBcz8HAVq0VnfAf+X fVZdEqJh4pn9Ec9j6fyG6aeX5Qu94RT92x3Ns5VQEJyCPpZL+/VcXp82/6WrB9H85rng wUNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=6t8XWmW1r6k+Rvrf6ccUE7sEg8D8M+BW0YigTgGi+EQ=; b=qr3o4iUKLFJqDNcGHiiLj7IqzHrSG7wuPTil1hpU+DG1SLOxWi4x2Iw7TrIM1Zm02H v+rG+OSUaXi39zjXTARaqL/rhHh3WMUssJM8ui57kDjYZ4jI2NXaMcYmgs9VYmSicI6L ctdjM0uygEO/xnriTj5lQ5pQyI4eh4c2eo8Ew5oiLiYUrqrKBkLIJ9wZepld88py9G5o cMxM50zWPnFUVSp5lMPS5/UZQ/fWBnwIvrQY/ITj5ZHOaMWNArfTKi9lf33h/pNV8GKy i5wmvZs+Bag93U8ygX1tk/hH68E7ulgk2YN0vFeCvDBKMBilk+9xXMpWHP29b7+7wdPm xnAg== X-Gm-Message-State: ALKqPwcxlA3HkUsakm31eRF0dbPA3Msi4ADFyqYe1rZODVQOZ+R3uQ0N UrO1Kt0XIRdQHYphNPGLv1z7m2P8 X-Google-Smtp-Source: AB8JxZowIdyH8avwx3kFCUKZS7j+r5V8GCjFVGMatyzz91V4wntkEYfacJHRQLNGlVN9vq3U9ymkmg== X-Received: by 2002:a0c:b03d:: with SMTP id k58-v6mr9002943qvc.121.1527203622958; Thu, 24 May 2018 16:13:42 -0700 (PDT) Original-Received: from zebian (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.googlemail.com with ESMTPSA id k127-v6sm3629512qke.20.2018.05.24.16.13.41 for <31311@debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 May 2018 16:13:41 -0700 (PDT) In-Reply-To: <87r2m22ndx.fsf@gnuvola.org> (Thien-Thi Nguyen's message of "Wed, 23 May 2018 21:16:42 +0200") 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:146510 Archived-At: Thien-Thi Nguyen writes: > Also, =E2=80=98pcase=E2=80=99 is the only conditional construct that take= s a > first arg and evaluates it (like =E2=80=98case=E2=80=99). The new text e= xplains > its hybrid nature (=E2=80=98cond=E2=80=99 and =E2=80=98case=E2=80=99) in = more detail. The manual should refer to `cl-case', not `case'. 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. > +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. > +(defun grok/traditional (obj) > + (if (and (stringp obj) > + (string-match "^key:\\([[:digit:]]+\\)$" obj)) > + (match-string 1 obj) > + (list "149" 'default))) > +(defun grok/pcase (obj) > + (pcase obj > + ((or ; @r{line 1} > + (and ; @r{line 2} > + (pred stringp) ; @r{line 3} > + (pred (string-match ; @r{line 4} > + "^key:\\([[:digit:]]+\\)$")) ; @r{line 5} > + (app (match-string 1) ; @r{line 6} You have to pass the original string to match-string. > + 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))