From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?UTF-8?Q?Przemys=c5=82aw_Wojnowski?= Newsgroups: gmane.emacs.devel Subject: Re: Question on pcase Date: Fri, 23 Oct 2015 21:59:38 +0200 Message-ID: <562A91AA.3030208@cumego.com> References: <871tcngdv2.fsf@gmail.com> <87k2qe1u09.fsf@web.de> <83r3kmrtat.fsf@gnu.org> <87r3kl22zk.fsf@web.de> <837fmdzpf2.fsf@gnu.org> <87oafp659p.fsf@web.de> <831tclzly9.fsf@gnu.org> <87fv115t20.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1445630415 13007 80.91.229.3 (23 Oct 2015 20:00:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 23 Oct 2015 20:00:15 +0000 (UTC) Cc: Emacs Development To: Michael Heerdegen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Oct 23 22:00:08 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZpiVG-0003Er-Tu for ged-emacs-devel@m.gmane.org; Fri, 23 Oct 2015 21:59:55 +0200 Original-Received: from localhost ([::1]:41264 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpiVG-0003yE-FW for ged-emacs-devel@m.gmane.org; Fri, 23 Oct 2015 15:59:54 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57567) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpiVC-0003xt-DL for emacs-devel@gnu.org; Fri, 23 Oct 2015 15:59:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZpiV9-0001tO-7W for emacs-devel@gnu.org; Fri, 23 Oct 2015 15:59:50 -0400 Original-Received: from smtp23.iq.pl ([86.111.242.228]:50844) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpiV8-0001q9-U4 for emacs-devel@gnu.org; Fri, 23 Oct 2015 15:59:47 -0400 Original-Received: (qmail 30585 invoked from network); 23 Oct 2015 19:59:39 -0000 Original-Received: from unknown (HELO [192.168.1.102]) (esperanto@cumego.com@[159.205.196.239]) (envelope-sender ) by smtp22.iq.pl with AES128-SHA encrypted SMTP for ; 23 Oct 2015 19:59:39 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 In-Reply-To: <87fv115t20.fsf@web.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 86.111.242.228 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:192517 Archived-At: W dniu 23.10.2015 o 20:38, Michael Heerdegen pisze: > I wrote a step by step introduction for people who (1) are frightened by > `pcase' and (2) are willing to invest some (not much, but some) time to > learn it. It is how I would describe `pcase' to a friend, maybe it is > good for learning, maybe it is ugly, dunno. Some errors included. > > Someone who wants to try to learn pcase (Oleh? Oleh!) can help by > reading it and telling me if it is understandable, and send corrections > - or write a better introduction ;-) - and format it nicely for > inclusion into Elpa or Emacs when it turns out to help people. Thanks for the tutorial! :-) I didn't know what pcase is until I read the first few lines. Then I just realized that it's just a version of Pattern Matching that I know from Clojure (https://youtu.be/mi3OtBc73-k - is a good intro). Anyway, I read the tutorial and IMHO it is mostly clear. I just have a few questions and comments: 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? --------------- 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. --------------- 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. --------------- What are some good (concrete) use cases for the pcase? When would you suggest to use it instead of cond or other similar constructs? --------------- Great job! Thanks, Przemysław