From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Kaushal Modi Newsgroups: gmane.emacs.help Subject: Re: Using let-bound var inside pcase conditions Date: Mon, 17 Apr 2017 20:40:19 +0000 Message-ID: References: <87tw5mdba4.fsf@drachen> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: blaine.gmane.org 1492461661 20989 195.159.176.226 (17 Apr 2017 20:41:01 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 17 Apr 2017 20:41:01 +0000 (UTC) Cc: Help Gnu Emacs mailing list To: Michael Heerdegen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Apr 17 22:40:57 2017 Return-path: Envelope-to: geh-help-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 1d0DSB-0005KX-Sx for geh-help-gnu-emacs@m.gmane.org; Mon, 17 Apr 2017 22:40:56 +0200 Original-Received: from localhost ([::1]:38695 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0DSH-0004wt-Ib for geh-help-gnu-emacs@m.gmane.org; Mon, 17 Apr 2017 16:41:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36519) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0DRp-0004wo-Lq for help-gnu-emacs@gnu.org; Mon, 17 Apr 2017 16:40:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0DRo-0000Lo-J8 for help-gnu-emacs@gnu.org; Mon, 17 Apr 2017 16:40:33 -0400 Original-Received: from mail-lf0-x22d.google.com ([2a00:1450:4010:c07::22d]:34498) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d0DRo-0000LL-65 for help-gnu-emacs@gnu.org; Mon, 17 Apr 2017 16:40:32 -0400 Original-Received: by mail-lf0-x22d.google.com with SMTP id t144so70999207lff.1 for ; Mon, 17 Apr 2017 13:40:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vosTduTy0bQv6/5LqSq5oxK0qznPie3FSFaSEQS16mA=; b=bXDolLlUhwfEjZDODYBp0WOWlwCCvZTCrksYUvv30JcHjSsRpxoA7mwFZjNtJ+kan+ kj5zuqemiQRkhuH+XgAIY8buNjj04bmrmKHyiT6/BhB0vipeaprU8HncUfU5gjcN+TD2 2GFzCbvKKAgzWI2TcTHlyg+G9PSqJESNfzZbOECeEaaLXFItK5kgDtx42Wrw4uDrruXG vP2AfAfc/lxmIviHo80K5+EeOffTHwjsMrJJwE0MNAa1QfPdA0uppeZSbeP/88dSJFiL IXY6nD8WpgLCRRzXVlSJleyzcd9ZzivtS+pw0Q0U6v1G1jQS1VDfMfWOw4biTkzNU7n5 cMbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vosTduTy0bQv6/5LqSq5oxK0qznPie3FSFaSEQS16mA=; b=H25qcWMXVme3fBTe/vg4v/km+wTVL1OVrqZQH7pItUNuiIiClOOrPtm9u6SIvPr1x4 I11VPov52ryD9f4qki/yEfXMi9VWRWCFuIrG/YDOD+1KbIwLF25mCsR9N1Wit80Nbhfp h6VEKKjrnhPF6hJkIwHgGpRTw/P3j3wCC0t1BlLPbOiKzvjD1IsYrL/H88WTN2UIkPQr Pf1iUItnfWXk3HIZfrgQ3fOFSrps3L2PNuYiy2L78L6divevRAudu6OWf2JjImHf8Sox 7gQAmqKBAKXKKN+N4XEqx7N7IQ1xvw0qmdMXDW8Y4V8DQqtIio/wiiJcciLa8OQoXXIN nhGw== X-Gm-Message-State: AN3rC/48Cqe6ohmpNFN6DfumjMV3ILPi4UBovW04+Xjaihn5EG8KFi/e zaIetmCEHIaofEuto17D5F1FRTdbpQ== X-Received: by 10.25.193.205 with SMTP id r196mr3292445lff.127.1492461630379; Mon, 17 Apr 2017 13:40:30 -0700 (PDT) In-Reply-To: <87tw5mdba4.fsf@drachen> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::22d X-Content-Filtered-By: Mailman/MimeDel 2.1.21 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:112796 Archived-At: On Mon, Apr 17, 2017 at 4:33 PM Michael Heerdegen wrote: > I also try this from time to time just to remember that it's wrong: the > first appearance of a symbol in a pcase pattern is never transformed > into an `eq'uality test. Sometimes that's surprising (especially in > backquote patterns), but that's how it's defined. > > BTW, `nil is equivalent to 'nil, and `,symbol is equivalent to just > symbol as a pattern. > Thanks! I did not know that. > To your question: I guess the shortest correct pattern is > > (pred (eq one)) > Works! Thank you. Here the code again for completeness (or my future-self ending up on this thread while searching the Intrawebs): ;; -*- lexical-binding: t; -*- ;; http://lists.gnu.org/archive/html/help-gnu-emacs/2017-04/msg00123.html (defun pcase-test (var) (let ((one 1) (two 2)) (message "(hard-coded) Value is %s." (pcase var (`nil "nil") (1 "one") (2 "two") (_ "none of the expected"))) (message "(vars - bad) Value is %s." (pcase var (`nil "nil") (`,one "one") (`,two "two") (_ "none of the expected"))) (message "(vars - good) Value is %s." (pcase var (`nil "nil") ((pred (eq one)) "one") ((pred (eq two)) "two") (_ "none of the expected"))))) (pcase-test nil) (pcase-test 1) (pcase-test 2) (pcase-test 3) -- Kaushal Modi