From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.devel Subject: Re: cond* Date: Mon, 01 Jan 2024 14:49:37 +0000 Message-ID: <87edf1m7lq.fsf@localhost> References: <87frzuae9n.fsf@posteo.net> <871qbatqc8.fsf@posteo.net> <87wmsz7lzn.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19433"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Philip Kaludercic , emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Jan 01 15:59:16 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 1rKJl6-0004nS-Q8 for ged-emacs-devel@m.gmane-mx.org; Mon, 01 Jan 2024 15:59:16 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rKJkO-00035Q-Tj; Mon, 01 Jan 2024 09:58:32 -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 1rKJkK-00033z-Nd for emacs-devel@gnu.org; Mon, 01 Jan 2024 09:58:29 -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 1rKJkH-0004Q2-Ns for emacs-devel@gnu.org; Mon, 01 Jan 2024 09:58:27 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 62F6A240104 for ; Mon, 1 Jan 2024 15:46:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1704120386; bh=fVtsBDbWixkSBrypGq+M0AEPF8Wu6m/9o6aq9aimbnE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=GCG9MmrTijzccAUcF8KOrRMKXHNLWWuus56RnrHTg+5tdRYg517c5ek4BP9lNgaNp 96eiUT06hMwro+EE2z5KR7BgH6Kyo6o9WFxDrX1Sdfucusqur0Qg0vBGACTr0bheZA ui7tpdBt4uaaATpPSM2Qr7xKT4DZyGR0htcyXIXFA3FFr1PdAq5rvcD0s8WIS6bYKE G40ox8x28Dut+qiR1J+8B4VX3cnGAt6Q2y/GUCGNjgHVY96Z5Vd++h8WggDYJEPNsp ue0t/MXC4Q6d3I2qYZM3lsZip2Jrt6lHYid4qRtCb+higX8u2zfNwXEZxaqYWlK1a4 UNspwaWHThwSg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4T3f1s43F1z9rxL; Mon, 1 Jan 2024 15:46:25 +0100 (CET) In-Reply-To: Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@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:314419 Archived-At: Richard Stallman writes: > Each clause in cond* that has just one element -- no "clause body" -- > is a "non-exit" clause. After that clause completes, control always > proceeds to the following clause. > ... > To test CONDITION and return its value if non-nil, use this: > > (CONDITION CONDITION) Note that it is different from `cond', which is somewhat confusing - (CONDITION) in `cond' exits, returning CONDITION value. > A backquoted cons cell > > ... > (cdr-safe QUOTED-CONS-CELL) > > This pattern is equivalent to QUOTED-CONS-CELL by itself > except that it makes the nil-match-all flag true within it. > > (cdr-safe `(a b)) matches (a b), (a b c), (a b . d), etc. > > (cdr QUOTED-CONS-CELL) > > This pattern is equivalent to QUOTED-CONS-CELL by itself > except that it makes the nil-match-all flag false within it. > > (cdr `(a b)) matches only (a b). This is more confusing than `pcase'. In `pcase', what you call "cdr-safe" is realized simply by `(a b . _) and what you cal ""cdr" is `(a b). I find `pcase' version both more intuitive and more compact. > Constrained variable: (PRED VARIABLE) or, more generally, > (PRED VARIABLE OTHER-ARGS...) > > This matches any value VALUE that satisfies the specified > constraint. PRED is a function to test the constraint. It receives > VALUE as its first argument. If PRED returns true, that means VALUE > satisfies the constraint, so this pattern binds (or sets) VARIABLE > to that value. For instance, > > (symbolp sym) ; Match any symbol, bind `sym' to it. This is an equivalent of pcase's pred pattern, except that pcase also allow VARIABLE to be non-first argument of PRED. What about allowing a construct like ,((plist-get plist) property) that will test for PROPERTY being in PLIST? Or, better, allow VARIABLE to be in an arbitrary argument of PRED: ,(PRED ARG1 ARG2 !VARIABLE ARG3 ...) Example: ,(plist-get plist !variable #'equal) > xxxxxxxxxxxxxx not decided yet > This would give some added power, but does that power really enable > the user to do more with cond*? I am not sure. > > PATTERN can also be a list, which is a pattern to destructure, > For instance, > > (plistp `(,a ,b . ,rest)) > > checks that VA and second element and binds rest to its cddr. > xxxxxxxxxxxxxx not decided yet I feel that layering conditions will lead to unnecessary complexity. What about allowing (and ...) pattern, similar to (or ...): (match* (and (plistp _) `(,a ,b . ,rest)) plist) P.S. What is missing in the above compared to pcase is matching regular expressions: =E2=80=98(rx RX-EXPR...)=E2=80=99 Matches strings against the regexp RX-EXPR..., using the =E2=80=98rx= =E2=80=99 regexp notation (*note Rx Notation::), as if by =E2=80=98string-match= =E2=80=99. In addition to the usual =E2=80=98rx=E2=80=99 syntax, RX-EXPR... can c= ontain the following constructs: =E2=80=98(let REF RX-EXPR...)=E2=80=99 Bind the symbol REF to a submatch that matches RX-EXPR.... REF is bound in BODY-FORMS to the string of the submatch or =E2=80=98nil=E2=80=99, but can also be used in =E2=80=98backref= =E2=80=99. =E2=80=98(backref REF)=E2=80=99 Like the standard =E2=80=98backref=E2=80=99 construct, but REF ca= n here also be a name introduced by a previous =E2=80=98(let REF ...)=E2=80= =99 construct. --=20 Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at