From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Oleh Krehel Newsgroups: gmane.emacs.devel Subject: Re: Question on pcase Date: Fri, 23 Oct 2015 15:26:32 +0200 Message-ID: <87k2qdd8c7.fsf@gmail.com> References: <871tcngdv2.fsf@gmail.com> <87k2qe1u09.fsf@web.de> <83r3kmrtat.fsf@gnu.org> <87k2qdeqym.fsf@gmail.com> <87lhat22pv.fsf@web.de> <87ziz9dadv.fsf@gmail.com> <87wpud68e6.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1445606805 15342 80.91.229.3 (23 Oct 2015 13:26:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 23 Oct 2015 13:26:45 +0000 (UTC) Cc: emacs-devel@gnu.org To: Michael Heerdegen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Oct 23 15:26:35 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 1ZpcMV-0007Av-DN for ged-emacs-devel@m.gmane.org; Fri, 23 Oct 2015 15:26:27 +0200 Original-Received: from localhost ([::1]:38480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpcMU-00013X-Kj for ged-emacs-devel@m.gmane.org; Fri, 23 Oct 2015 09:26:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42451) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpcMD-00013S-Vx for emacs-devel@gnu.org; Fri, 23 Oct 2015 09:26:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZpcMA-0006JO-LT for emacs-devel@gnu.org; Fri, 23 Oct 2015 09:26:09 -0400 Original-Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]:36755) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpcMA-0006J7-FQ for emacs-devel@gnu.org; Fri, 23 Oct 2015 09:26:06 -0400 Original-Received: by wicfx6 with SMTP id fx6so31297172wic.1 for ; Fri, 23 Oct 2015 06:26:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=WS3EoWzvh2v1Au1dSzXT9GBbthpG08Pv3ivD9lvcVW0=; b=J/CYfKkOkfyXMXx8NwyXOavk5qR83ZLLovQWIQNfKxeslu8kTK2/1rSDeUszTM+A1O 4ashZtiIzjD13Zsu5556yUMu6ThbaM/GHxWZfvOXx97c5PvQROytXXY9Bhj2EcVukySh /yYKpBA4cYw76Gzs3Re7AuJJx29irrCIvmxkuWJh2jK9HiXoNTtOFuH7gfvE1u5+yUFQ oaEFya5jwvS3lNuvWP53zqQ12qWlL9AZQH4ABVCu5GMi5jLgw+92VgqNn3HZjlCugmSM DqNDIrU5a3/dTDhhBcIMzfUOtofOHH0x4mfGj+6BGcwsdE8he2/ZN+I6ZiWCF0UiCwIA PBmg== X-Received: by 10.194.143.43 with SMTP id sb11mr26583756wjb.120.1445606765733; Fri, 23 Oct 2015 06:26:05 -0700 (PDT) Original-Received: from firefly (dyn069045.nbw.tue.nl. [131.155.69.45]) by smtp.gmail.com with ESMTPSA id bk4sm22724238wjc.1.2015.10.23.06.26.04 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 23 Oct 2015 06:26:04 -0700 (PDT) In-Reply-To: <87wpud68e6.fsf@web.de> (Michael Heerdegen's message of "Fri, 23 Oct 2015 15:07:13 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::232 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:192484 Archived-At: Michael Heerdegen writes: > Oleh Krehel writes: > >> Thanks Michael, that's almost exactly what I need. The only thing is >> that I don't understand what `-bind-' is. > > That's just a placeholder I used. Depending on what pcase form you are > using (`pcase', `pcase-lambda', `pcase-let'), the semantic is a bit > different. > > You can just imagine that it creates a local binding, like `let', and > that binding is available in the CODE part of the > > (PATTERN CODE...) > > of this branch. > > The actual code `pcase' produces is easy as well but longer; when I > included this aspect in `pcase-demystify-pattern', the result would look > more like what you would get with `macroexpand', so I don't think it > would be useful, since the semantic is also slightly different in other > `pcase' derived macros. I think there's a bit of miscommunication here. I can `macroexpand' as well, but the branch info isn't clear-cut in that case. The thing is that I don't want to use `pcase-demystify-pattern' to understand approximately what each pattern does, I want it to expand to the exact code that is run for a branch, and I want to run that code. This can all be done in-place without producing extra buffers. A simple "C-c C-e" on a branch should either: (message "the branch doesn't match") or e.g.: (progn (setq hookfun (car res)) (setq start (nth 0 (cdr res))) (setq end (nth 1 (cdr res))) (setq collection (nth 2 (cdr res))) (setq plist (nthcdr 3 (cdr res))) (message "match")) Instead, (pcase-demystify-pattern '`(,hookfun . (,start ,end ,collection . ,plist))) gives: (if (consp -tested-expression-) (let* ((x (car -tested-expression-)) (x (cdr -tested-expression-))) (if (consp x) (let* ((x (car x)) (x (cdr x))) (if (consp x) (let* ((x (car x)) (x (cdr x))) (if (consp x) (let* ((x (car x)) (x (cdr x))) (progn (-bind- plist x) (-bind- collection x) (-bind- end x) (-bind- start x) (-bind- hookfun x))) nil)) nil)) nil)) nil) Which is indeed close to what I need. I guess `-bind-` should be some macro that pops and does a `set'. I'm just not sure that this is exactly true, and will work for all patterns.