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: Thu, 29 Oct 2015 10:44:14 +0100 Message-ID: <87ziz280wh.fsf@gmail.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> <87io5tzkt8.fsf@gmail.com> <87fv0xd2jr.fsf@web.de> <87egggya6e.fsf@gmail.com> <87twpcidyl.fsf@web.de> <87h9lcid0g.fsf@web.de> <87fv0ukgx2.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1446112090 29298 80.91.229.3 (29 Oct 2015 09:48:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 29 Oct 2015 09:48:10 +0000 (UTC) Cc: emacs-devel@gnu.org To: Michael Heerdegen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Oct 29 10:48:06 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 1ZrjoT-0007Q1-2E for ged-emacs-devel@m.gmane.org; Thu, 29 Oct 2015 10:48:05 +0100 Original-Received: from localhost ([::1]:42983 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrjoS-0003NZ-DT for ged-emacs-devel@m.gmane.org; Thu, 29 Oct 2015 05:48:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrjkP-0004zI-7Y for emacs-devel@gnu.org; Thu, 29 Oct 2015 05:43:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZrjkK-0001zD-80 for emacs-devel@gnu.org; Thu, 29 Oct 2015 05:43:53 -0400 Original-Received: from mail-wi0-x22f.google.com ([2a00:1450:400c:c05::22f]:33281) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrjkK-0001yx-2P for emacs-devel@gnu.org; Thu, 29 Oct 2015 05:43:48 -0400 Original-Received: by wijp11 with SMTP id p11so281013840wij.0 for ; Thu, 29 Oct 2015 02:43:47 -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=P2ATwROGUin16Kgt4XCEhwZGqK0Bk5hJtke4EuO3vIw=; b=fnWCtoJlPinnfXBCvgMWmAeF1Y9q2KSlhKtENrxQMlubwnVkxahL0qXl7j7sKOUgF/ uDBkh3mPLXT69/PXfwWbSS/nHpOTUX2gNsX7rQpnuhcno3rRsc6chZl9o5qkTpTuVjBS XjUNSgJKdL8YRy8ge7Bw6AnpKWk2jKdgn8zGnnhgmBwvrhVZMSbd4WQznypaC7cXpTJe RDLZiTyRsiGMm8fEoI/Vnr1fwVW/q663nNIOZLkXzOLf1QDHep2IVjo3+zrrAWqX/0+1 5Y/vfmYe63yVEt1kZqZpDyjf8qrv6MAxeQ2QNU0wC2AIQzvnup02SevRVkGNEKrlr3Xi xPQA== X-Received: by 10.194.78.162 with SMTP id c2mr960702wjx.112.1446111827332; Thu, 29 Oct 2015 02:43:47 -0700 (PDT) Original-Received: from firefly (dyn069045.nbw.tue.nl. [131.155.69.45]) by smtp.gmail.com with ESMTPSA id ki7sm847754wjc.28.2015.10.29.02.43.46 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 29 Oct 2015 02:43:46 -0700 (PDT) In-Reply-To: <87fv0ukgx2.fsf@web.de> (Michael Heerdegen's message of "Wed, 28 Oct 2015 19:05:13 +0100") 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::22f 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:192864 Archived-At: Michael Heerdegen writes: > Here is a version that should fit your use case better: > > ;; -*- lexical-binding: t -*- > > (defun abo-abo-pattern-matcher (pattern) > "Turn pcase PATTERN into a predicate. > For any given pcase PATTERN, return a predicate P that returns > non-nil for any EXP when and only when PATTERN matches EXP. In > that case, P returns a list of the form (bindings . BINDINGS) as > non-nil value, where BINDINGS is a list of bindings that pattern > matching with PATTERN would actually establish in a pcase branch." > (let ((arg (make-symbol "exp"))) > `(lambda (,arg) > ,(pcase--u > `((,(pcase--match arg (pcase--macroexpand pattern)) > ,(lambda (vars) > `(cons > 'bindings > (list > ,@(nreverse (mapcar > (lambda (binding) > `(cons ',(car binding) > ,(cdr binding))) > vars))))))))))) Thanks a lot Michael! This seems to be exactly what I want. It even works for the initial example of debugging `completion-at-point' that I cited earlier: (funcall (abo-abo-pattern-matcher '`(,hookfun . (,start ,end ,collection . ,plist))) res) ;; => ;; (bindings (hookfun . elisp-completion-at-point) ;; (start . 1841) ;; (end . 1844) ;; (collection . [...]) ;; (plist ;; :predicate fboundp :company-doc-buffer elisp--company-doc-buffer ;; :company-docsig elisp--company-doc-string ;; :company-location elisp--company-location)) Now I can add the `pcase' debug functionality to lispy. I don't know if there's a place for this type of a helper function in the core. I think that we should at least encourage `pcase' to macroexpand to a simple `cond' with a regular structure every time. regards, Oleh