From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Nathan Moreau Newsgroups: gmane.emacs.devel Subject: Re: pcase-if-let? Date: Tue, 17 Apr 2018 22:26:41 +0200 Message-ID: References: <871sg3eqi5.fsf@web.de> <0e8139b0-b59c-1d7e-29db-66170858f8ca@lanl.gov> <87woxvd947.fsf@web.de> <87605filw6.fsf@web.de> <60dc117a-7ee2-42d2-acbc-49dae9ec6ae1@default> <871sg3ijgf.fsf@web.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1523996691 8111 195.159.176.226 (17 Apr 2018 20:24:51 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 17 Apr 2018 20:24:51 +0000 (UTC) Cc: Drew Adams , Emacs Development To: Michael Heerdegen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Apr 17 22:24:47 2018 Return-path: Envelope-to: ged-emacs-devel@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 1f8X9j-000206-0s for ged-emacs-devel@m.gmane.org; Tue, 17 Apr 2018 22:24:47 +0200 Original-Received: from localhost ([::1]:60898 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8XBo-0006i8-3h for ged-emacs-devel@m.gmane.org; Tue, 17 Apr 2018 16:26:56 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44072) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f8XBd-0006gs-RW for emacs-devel@gnu.org; Tue, 17 Apr 2018 16:26:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f8XBc-0002op-Qx for emacs-devel@gnu.org; Tue, 17 Apr 2018 16:26:45 -0400 Original-Received: from mail-it0-x232.google.com ([2607:f8b0:4001:c0b::232]:36476) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f8XBc-0002cd-A1 for emacs-devel@gnu.org; Tue, 17 Apr 2018 16:26:44 -0400 Original-Received: by mail-it0-x232.google.com with SMTP id n81-v6so11212954ita.1 for ; Tue, 17 Apr 2018 13:26:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=PwwgbKhThRrqBH4+vXCd2iHCVUFColwlrWZ8jkuZJCk=; b=oOB5QOZmGAZtHqX6p/XDIM2G7GBKPYZlgpQIeha2zIZpiHrBCjJeX6Ci6+U86nXytV CL51b7fJABqMbUTCEvbzuj8sBuIgZ2aiR3r3RMQINrFAMVkvWTjIPGOzcoDyADAeLd/h 9dLGvK1sPIUNmXcpTqDRU95BLyGScLzUmjy6Qj7ERWVwObZrDt27F2kf9eTtjGsy3oJG KYvPLeUre1PLMmUEKjc4rJFQjT0x0oUlEEu3TFRUcq9OEABH0LE70BEChtDzFSgAsuGP v0VlAvk3MLwQVQWEgaM/Xn0v40jVyjQZJgArzI0GtkpDAjF1OpJl+V0itg/U6SckW9fz vvjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=PwwgbKhThRrqBH4+vXCd2iHCVUFColwlrWZ8jkuZJCk=; b=ZIr5EMuXsA7m8uUqY4Y+5GgmdBrI8c2vzOt9r9nNnFd/Hh4gFLzTuxxJ4dhRhsdxYF jkbl68wWzfMgy7t2mJWiO7NTVJcUfhDT5WuPJ1zqPP2Cf8ImKaJYhttALOLFPab/XI2R 8mQy0ha5lPyJAgbANJrkBEhcSlZae2HS63NCtlW8A3PDr5/XR7uDA4ZUvZ7pmZwhjltN Zlw2FL1FlbZPhbgu+zMi033MGkeWI/scO2X7V6YYmojxpEMKt5fTaTgYM17eLHx4DH/i ZWiHUILxBqRuxptTyOciiSzmSwrC3wOsBPqDdYVs/UYJ4BW9OtoNpQwgsW7iRNI+fay1 ZL0A== X-Gm-Message-State: ALQs6tDVpGMmIYQeGXB+aWmTCi9b8jR9W5WXAb9TQ6y1TsHD8uSXEWoH 3YWznl8DUAc2PfXIQXXuMG6hg6sSSCn5Y5jTmic= X-Google-Smtp-Source: AIpwx49b1wM7VJMv/JnKvjnF2eEuLAOx/Pp3iGjDFkx2yhhPcsdrQt+FXHs96RCvgSbU+yzlTngcPqGikkTzHoOTYK8= X-Received: by 2002:a24:2903:: with SMTP id p3-v6mr2758236itp.10.1523996802958; Tue, 17 Apr 2018 13:26:42 -0700 (PDT) Original-Received: by 2002:a02:8249:0:0:0:0:0 with HTTP; Tue, 17 Apr 2018 13:26:41 -0700 (PDT) In-Reply-To: <871sg3ijgf.fsf@web.de> X-Google-Sender-Auth: eot2QWKFBvCwJKFB7XLxMkCY3Og X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::232 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:224711 Archived-At: > > P.S.: Here is the updated definition: > > #+begin_src emacs-lisp > (defmacro pcase-if (clauses then &rest elses) > "Depending on CLAUSES, evaluate THEN or ELSES. > CLAUSES is a list of the form \((PATTERN VALUE-FORM) ...) > Successively try to match every `pcase' PATTERN against its > VALUE-FORM. When all match, eval THEN, else the > ELSES." > (declare (indent 2) > (debug ((&rest (pcase-PAT &optional form)) > form body))) > (if (null clauses) > then > (let ((success-syms '()) (last-success-sym nil)) > (dotimes (i (length clauses)) > (push (make-symbol (format "matching-%d-success" i)) > success-syms)) > (cl-callf nreverse success-syms) > `(let ,(mapcar (lambda (s) `(,s nil)) success-syms) > (pcase nil > ((and ,@(mapcar > (pcase-lambda (`(,pattern ,value)) > `(let (and ,@(and last-success-sym > `((guard ,last-success-sym))) > ,pattern > (let ,(setq last-success-sym > (pop success-syms)) > t)) > ,value)) > clauses)) > (if ,last-success-sym ,then ,@elses))))))) > #+end_src > > > Hi, about that new definition, is the following semantics what you expect? (pcase-if ((`(,q . ,r) '()) (`(,s . ,u) '(b c))) (list q r s u 'ok) 'nope) => nil ? I would have expected 'nope instead. Nathan