From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel Semyonov Newsgroups: gmane.emacs.devel Subject: Re: combining cond and let, to replace pcase. Date: Fri, 24 Nov 2023 05:08:55 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=----4PSM4DC5NSOCE29VUVKZBT1SWHD1KV Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39019"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: K-9 Mail for Android Cc: emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Nov 24 04:09:51 2023 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 1r6MZj-0009ys-25 for ged-emacs-devel@m.gmane-mx.org; Fri, 24 Nov 2023 04:09:51 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r6MYv-0000zj-7g; Thu, 23 Nov 2023 22:09:01 -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 1r6MYu-0000zb-Fr for emacs-devel@gnu.org; Thu, 23 Nov 2023 22:09:00 -0500 Original-Received: from dsemy.com ([46.23.89.208]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r6MYs-0001hi-Ma; Thu, 23 Nov 2023 22:09:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=dkim; bh=qb8YIcGroqLXt zjevlFuFZnhYRP/+OtRzJAMLIUAx7k=; h=references:in-reply-to:subject:cc: to:from:date; d=dsemy.com; b=ubS3oDzHfsu+Q/UQrHMLnmkXvAS2tycndJ/MWte4Q t/QoDWlthezwCLQxcFFreKUJaF14LAz0pW7FBUbZcsmLOsGgZl1mDGWCCIfcbBqk3qHGZ1 tw4xoWdagxZDqT/pp1JHWZ5ca4z38QX17VYP3N5S29OzQoX8DEkCkPgZ8BMKQYLgdHgFAV OHIxyD3awjAc3dA+F/9pGEsJiMdJ82Tlr6ckFE1zm7dLTW3m4SqkGm/ISBwxXk4BTYHQlb 2mh0z/tbbvGGq7B7AdmSQF3Y932SQqC+vlSqIbXsHDE/iCbH3QFThkipwB5Fdj3U7+u365 6TrieWRmKjlfG0L6f3dTQ== Original-Received: from [127.0.0.1] (CUST-29.202.102.5.018.net.il [5.102.202.29]) by dsemy.com (OpenSMTPD) with ESMTPSA id 5b525ee2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 24 Nov 2023 04:08:54 +0100 (CET) In-Reply-To: Received-SPF: pass client-ip=46.23.89.208; envelope-from=daniel@dsemy.com; helo=dsemy.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, HTML_MESSAGE=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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:313163 Archived-At: ------4PSM4DC5NSOCE29VUVKZBT1SWHD1KV Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable >>>>> Richard Stallman writes: > I've done more work on designing `cond*'; here is what I have now=2E > Please send me constructive suggestions, including for features you > suggest adding=2E I think either the name should be changed or the behavior of t as a condition should be the same as in 'cond', as IMO it could lead to confusion=2E Maybe ':always' or ':continue' could be used instead? Other than that this seems very simple and easy to understand, I would honestly much prefer this over 'pcase'=2E > Here are three macros that would be useful as conditions in `cond*' > but can also be used elsewhere=2E These also seem nice, but they make the ':match' condition almost pointless? AFAIU, the following should be equivalent: (cond* (:bind foo bar (x foobar)) ;; IMO changing t to ':always' would make it very clear what's ;; going on here=2E (t (match-set `(a ,foo ,bar) x)) ((match-set `(b ,foo ,bar) x) ;; do stuff and exit ) ;; more conditions=2E=2E=2E ) (cond* (:bind (x foobar)) (:match (`(a ,foo ,bar) x)) (:match (`(b ,foo ,bar) x) ;; do stuff and exit=2E=2E=2E ) ;; more conditions=2E=2E=2E ) The only usecase for ':match' (which can't really be fulfilled by the macros) is binding "new" variables (which haven't been bound using ':bind' beforehand), but I think requiring an explicit ':bind' is more clear, and would make it easier to quickly identify local variable names=2E It could also be better for people new to ELisp eventually, since these macros would be more likely familiar to them already (due to their potential usage outside of 'cond*') when compared to ':match'=2E And a minor nitpick, I think it would be better to rename 'match-bind' to 'match-let', to mirror other macros like 'if-let' (maybe even change ':bind' to ':let')=2E Regards, Daniel ------4PSM4DC5NSOCE29VUVKZBT1SWHD1KV Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
>>>>> Richard S= tallman writes:

> I've done more work on designing `cond*'; here= is what I have now=2E
> Please send me constructive suggestions, in= cluding for features you
> suggest adding=2E

I think either t= he name should be changed or the behavior of t as a
condition should be = the same as in 'cond', as IMO it could lead to
confusion=2E Maybe ':alwa= ys' or ':continue' could be used instead?

Other than that this seems= very simple and easy to understand, I would
honestly much prefer this o= ver 'pcase'=2E

> Here are three macros that would be useful as c= onditions in `cond*'
> but can also be used elsewhere=2E

Thes= e also seem nice, but they make the ':match' condition
almost pointless?= AFAIU, the following should be equivalent:

(cond* (:bind foo bar (x= foobar))
;; IMO changing t to ':always' would make it very clear what'= s
;; going on here=2E
(t (match-set `(a ,foo ,bar) x))
((match-= set `(b ,foo ,bar) x)
;; do stuff and exit
)
;; more conditions= =2E=2E=2E
)

(cond* (:bind (x foobar))
(:match (`(a ,foo ,bar= ) x))
(:match (`(b ,foo ,bar) x)
;; do stuff and exit=2E=2E=2E
= )
;; more conditions=2E=2E=2E
)

The only usecase for ':match= ' (which can't really be fulfilled by the
macros) is binding "new" varia= bles (which haven't been bound using
':bind' beforehand), but I think re= quiring an explicit ':bind' is more
clear, and would make it easier to q= uickly identify local variable
names=2E It could also be better for peop= le new to ELisp eventually, since
these macros would be more likely fami= liar to them already (due to their
potential usage outside of 'cond*') w= hen compared to ':match'=2E

And a minor nitpick, I think it would be= better to rename 'match-bind'
to 'match-let', to mirror other macros li= ke 'if-let' (maybe even change
':bind' to ':let')=2E

Regards,
= Daniel
------4PSM4DC5NSOCE29VUVKZBT1SWHD1KV--