From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.devel Subject: Re: pcase bindings in patterns with complicated logic Date: Sun, 14 Jan 2024 07:03:35 +0000 Message-ID: <871qakjt14.fsf@posteo.net> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21401"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Richard Stallman Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jan 14 08:04:15 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rOuXX-0005NZ-Hj for ged-emacs-devel@m.gmane-mx.org; Sun, 14 Jan 2024 08:04:15 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rOuXA-0004XC-5O; Sun, 14 Jan 2024 02:03:52 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rOuX6-0004V3-IL for emacs-devel@gnu.org; Sun, 14 Jan 2024 02:03:48 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rOuX2-0004s6-9r for emacs-devel@gnu.org; Sun, 14 Jan 2024 02:03:46 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 8B2EA240101 for ; Sun, 14 Jan 2024 08:03:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1705215821; bh=yHCOiD3EeSvZYUzbo/SUtQNDQh7xDpFOSdspZlPAG2k=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Autocrypt:OpenPGP: From; b=SX4OPU2xyQVgA3vR6zRSagxupt0iFHr4ta0unu94riTZSvyYrGR/iS9PZDYixAHlk B5kV+52i5cjqk3bfMKnfCbelwDXfEEh0SfniGIXCARJAqKESlC3lngmJQ4qCFLChkf z0cdih2XihS+7Ry/AWpW0ninaAsqfKFC4ZTIDFjxpocT97kJMrQz1Xx4m4qDhpc8r/ QjH5A/XvlaEsvtlS4qjLokuUWe41p+WG11eyvrR4MKKhyleGTz12lQaxSh46kP7D1Z 3xXMXHiFWF3R4a8Te501oZr4GGFuaxv1CMgT+yVM08YNbguta/KAGx8ejpJLuYfwwN 4LdmwA6hWrXtg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TCR7w1hyMz6tm8; Sun, 14 Jan 2024 08:03:40 +0100 (CET) In-Reply-To: (Richard Stallman's message of "Fri, 12 Jan 2024 22:54:31 -0500") Autocrypt: addr=thievol@posteo.net; prefer-encrypt=mutual; keydata=xsDNBF8ylcIBDADG+hy+zR6L4/vbdDDZuSaMmSrU3A5QZJpeBCvxTr7MpzzruZbhLPW1K3R6N2MA edi8Y+C8o27FVRIjpdbaKMGu9je7JV/TbUQYo3SOwCK1vM4LUn4V6ZLzSYkuiEt4eyMoiDdyvN0p kcK6P9x9DCetcEVszXzQg+yzCVrQ2hXWDXWT4M18EC3wtO7RHPouMqGiwBFhBAYErCqFWFxQHkfb tG/4yGyJ58rglb65O3qijjMWvYwcWZun9/7qm8Z4/4mHopmo2zgU+OrptnLSZfkZGz3Y7Uf452xQ GVq0Fv75NPvQru7y+DYVhuVXXyAmGxt+vf4rIiixMBbhKEPjcxEPAa2LTzex2IsTZR+QVG9uDnqC WcgaOEQ58fzXNvNhtwwF/Rgio2XWAJVdmFWS59/k9W58CIUSNKBMZh2XeGdEmtHvDtCxW3z6FJha 36RzOM3fMNNiAGdFZJA84gcdloJR+sHCDTTPT3784fjr+V8An7sI581NGFzkRQqPvEQCZbUAEQEA Ac0SdGhpZXZvbEBwb3N0ZW8ubmV0wsEOBBMBCgA4AhsDBQsJCAcCBhUKCQgLAgQWAgMBAh4BAheA FiEEI9twfRN7r3nig/xwDsVtFB0W75MFAmL3HCoACgkQDsVtFB0W75OVEAv/f6XxmtIFz08fUb8h Bp/zJP6IC4/rhhh+0GMRIRzLN8DK0jV8JCzYdFHiRJOy2lNIOpmrrCmjRRxferc2G42+ePFIsslx hU46VSz1Z83NwIG3mpdYNV5WUTUdgzxExHTNTFCd7NKv0nlHKQaA OpenPGP: url=https://posteo.de/keys/thievol@posteo.net.asc; preference=encrypt Received-SPF: pass client-ip=185.67.36.66; envelope-from=thievol@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:314952 Archived-At: Richard Stallman writes: > I'm trying to figure out how pcase behaves in terms of which pattern > variables are actually bound, depending on which parts of a case's > pattern succeeds in matching. That wasn't clear to me from the docs I > read. > > I tried this example: > > (setq x1 nil x2 nil y1 nil y2 nil) > > (pcase '(foo 5) > ((or `(,(and (pred symbolp) x1) ,(and (pred symbolp) y1)) > `(,(and (pred symbolp) x2) ,(and (pred numberp) y2))) > `(,x1 ,y1 ,x2 ,y2))) > > => (nil nil foo 5) > > So it seems that unless a match for a variable is included in the > branch of the matching tree that actually completes, its variable is > not set. > > But then I tried > > (pcase '(foo 5) > ((or `(,(and (pred symbolp) a1) ,(and (pred symbolp) b1)) > `(,(and (pred symbolp) a2) ,(and (pred numberp) b2))) > `(,a1 ,b1 ,a2 ,b2))) > > => (nil nil foo 5) > > That surrised me, since outside the pcase, all four variables > are unbound and referring to them gets errors. To avoid this you could write instead: (pcase '(foo 5) (`(,(and (pred symbolp) a1) ,(and (or (pred symbolp) (pred numberp)) b1)) `(,a1 ,b1))) -- Thierry