From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Israelsson Tampe Newsgroups: gmane.lisp.guile.devel Subject: Fwd: [Patch] definitions in when, unless, do as well as in cond- and case-clauses Date: Fri, 4 Feb 2022 21:11:52 +0100 Message-ID: References: <7f58438c-f2fb-49b6-b7b0-22054fde6277@www.fastmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000041dbe205d736dde4" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19070"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Fri Feb 04 21:18:40 2022 Return-path: Envelope-to: guile-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 1nG52V-0004jp-Cb for guile-devel@m.gmane-mx.org; Fri, 04 Feb 2022 21:18:39 +0100 Original-Received: from localhost ([::1]:33694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nG52U-0003dp-Cc for guile-devel@m.gmane-mx.org; Fri, 04 Feb 2022 15:18:38 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:42642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nG4wO-0006pW-0U for guile-devel@gnu.org; Fri, 04 Feb 2022 15:12:20 -0500 Original-Received: from [2607:f8b0:4864:20::431] (port=40601 helo=mail-pf1-x431.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nG4wL-0001dC-Gf for guile-devel@gnu.org; Fri, 04 Feb 2022 15:12:19 -0500 Original-Received: by mail-pf1-x431.google.com with SMTP id e6so5998539pfc.7 for ; Fri, 04 Feb 2022 12:12:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=KzMb2qriyNm05O361nNC/nGixHKOEFNHT1t+qHnXQe8=; b=QYMccFICoS8a52e7fJAjWWWO3ClQSMfhEul+W317CzpbSwWZd+owb9DrwEZ+YgkhVE egA1t65uZzi4hSk5AUe1wsCMKz0N9fuawdHTaY0rHzumJdqauSG3KOiYGOITe40MTRNB op863pEmqaPqD9xYdX1MWevojTHLmqXBPj4J+diqWbfkQUYN4KqOPYVgbU1XZaoC0WER qbmGkd0HxBgLWAUhvspZuadiPWAUfXIZ0GXX8XBAogB10/vd3e9AmVhvuYzqVSTrIAlg QDVx+e1s8vujfPnIq2ITfRK8XzdquzRkk8UjmNQCgNt7Erjqgevsi+KkDPsCwoMCqqGt Ks0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=KzMb2qriyNm05O361nNC/nGixHKOEFNHT1t+qHnXQe8=; b=NXsiW5GXIQEuxcq+yyQyd5Mk1iW+7HPPPlK3Ty9JfYOHdq1uu5DcxQf+9/SMUv8Xh8 P2WCXKBsxYl0etmLoyJkQMrdJRjWE7rcc2PBJYFqH5Y2tWFQp8vr7LyB9KimbvKwA2wJ lhk5eT9OQ+kzCDnVq8jS7gifVJz5+qaXz+1o/uS/WXxF8yO96S6hCFuLuMS6h22ByQsM uYWAXnz5F8np5Q8jZgwNsqNlPC2ZjTVcCkFO28G4kiWi7+beFxCS8BpvDC+LsUCCc6N7 nEhEmoKshTxiz72SOf/IQs69fuoP86JMgF3D6B1gABR3UepYzN/lo3G11gcgcArJQAB5 l4vA== X-Gm-Message-State: AOAM5327L+dujJwztEV8MzRUJTMn4R5tHhbRdwxNSE8KOhrLO2c9a48X 3D/04w7Dh71lKU08sOgGF+rmOT7qBWFgljGdYTydvVGc X-Google-Smtp-Source: ABdhPJzmIQHbhAR5vmZeEgYvlyxmhIt0BmivNVDTKOW4s/pDDeML9fYnaI+0ILJGVytmMaFsA6EFBqYsqGuOyMErj+s= X-Received: by 2002:a63:a55a:: with SMTP id r26mr566943pgu.52.1644005523838; Fri, 04 Feb 2022 12:12:03 -0800 (PST) In-Reply-To: X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::431 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=stefan.itampe@gmail.com; helo=mail-pf1-x431.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:21066 Archived-At: --00000000000041dbe205d736dde4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable ---------- Forwarded message --------- From: Stefan Israelsson Tampe Date: Thu, Feb 3, 2022 at 5:41 PM Subject: Re: [Patch] definitions in when, unless, do as well as in cond- and case-clauses To: Linus Bj=C3=B6rnstam using an implicit let in conditionals are bad in that you cannot escape from the let form which means that you loos conditional defines for example in the toplevel. e.g. (if 1 (define a 1) (define a 2)) will not work at the top level because of an implicit let. If you need implicit defines a simple macro for those are easy and if we need to state a syntax in stone for those, we should name them differently like when-let unless-let if-let cond-let case-let. On Thu, Feb 3, 2022 at 11:55 AM Linus Bj=C3=B6rnstam < linus.bjornstam@veryfast.biz> wrote: > Hi guys, > > It looks like a 3.0.8 might be happening. I am curious to know whether > this (perhaps minus the do form) is considered something that the > maintainers of guile could find interesting. > > If subset compatibility of r6|7rs is desired, I could provide a patch for > those files as well so that they enforce the distinction between definiti= on > and expression context. > > I myself find this a worthwhile patch since it has no drawbacks. a (let (= ) > ...) without definitions does not start a new lexical context and runs as > fast as a begin, so there should be no performance regressions. > > It also removes the last bodies in guile forms that have a definition > context, which may be confusing for beginners. > > I would say that the compatibility question with the enforcing cond of > rnrs is the only thing that needs proper addressing. > > Best > Linus Bj=C3=B6rnstam > > On Wed, 16 Jun 2021, at 21:11, Linus Bj=C3=B6rnstam wrote: > > Hi there! > > > > This patch updates some derived conditional forms (and do and and-let*) > > to support definitions in expression context. Meaning it makes this > > valid code: > > > > (cond > > ((pred? arg) > > (define a (something arg)) > > (when (error-case a) > > (error "a is broken")) > > (define b (something2 a)) > > (when (=3D 3 *log-level*) > > (display "logging something1 and 2 as successful")) > > (define c (something3 b a)) > > (when (odd? c) > > (error "something went wrong in something3")) > > c) > > (else > > ;;chosen by fair dice roll. Guaranteed to be random > > 4))) > > > > While awful, is sometimes what the world makes us do. > > > > The change means cond, case, when and unless behaves like it does in > > racket. Do was below case, so I changed that as well, and will actually > > become yet another way guile is superior to racket. > > > > I did also change the documentation, but I learned english by watching > > Beverly Hills cop, so that might need some fine touches by a capable > > english speaker. > > > > > > Best regards > > Linus Bj=C3=B6rnstam > > Attachments: > > * 0001-Allow-definitions-in-derived-conditional-forms.patch > > --00000000000041dbe205d736dde4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


---------- Forwarded message ---------
From: Stefan Israelsson Tampe <stefan.itampe@= gmail.com>
Date: Thu, Feb 3, 2022 at 5:41 PM
Subject: R= e: [Patch] definitions in when, unless, do as well as in cond- and case-cla= uses
To: Linus Bj=C3=B6rnstam <linus.bjornstam@veryfast.biz>


using an implicit let in conditionals=C2=A0are bad in that you cannot= escape=C2=A0from the let form which means that you loos conditional=C2=A0d= efines for example in the toplevel. e.g.

(if 1 (define a= 1) (define a 2)) will not work at the top level because of an implicit let= . If you need implicit defines a simple macro for those are easy and if we = need to state a syntax in stone for those, we should name them differently = like when-let=C2=A0 unless-let if-let cond-let case-let.

On Thu, Feb 3= , 2022 at 11:55 AM Linus Bj=C3=B6rnstam <linus.bjornstam@veryfast.biz> wro= te:
Hi guys,

It looks like a 3.0.8 might be happening. I am curious to know whether this= (perhaps minus the do form) is considered something that the maintainers o= f guile could find interesting.

If subset compatibility of r6|7rs is desired, I could provide a patch for t= hose files as well so that they enforce the distinction between definition = and expression context.

I myself find this a worthwhile patch since it has no drawbacks. a (let () = ...) without definitions does not start a new lexical context and runs as f= ast as a begin, so there should be no performance regressions.

It also removes the last bodies in guile forms that have a definition conte= xt, which may be confusing for beginners.

I would say that the compatibility question with the enforcing cond of rnrs= is the only thing that needs proper addressing.

Best
=C2=A0 Linus Bj=C3=B6rnstam

On Wed, 16 Jun 2021, at 21:11, Linus Bj=C3=B6rnstam wrote:
> Hi there!
>
> This patch updates some derived conditional forms (and do and and-let*= )
> to support definitions in expression context. Meaning it makes this > valid code:
>
> (cond
>=C2=A0 =C2=A0((pred? arg)
>=C2=A0 =C2=A0 =C2=A0(define a (something arg))
>=C2=A0 =C2=A0 =C2=A0(when (error-case a)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(error "a is broken"))
>=C2=A0 =C2=A0 =C2=A0(define b (something2 a))
>=C2=A0 =C2=A0 =C2=A0(when=C2=A0 (=3D 3 *log-level*)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(display "logging something1 and 2 as s= uccessful"))
>=C2=A0 =C2=A0 =C2=A0(define c (something3 b a))
>=C2=A0 =C2=A0 =C2=A0(when (odd? c)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (error "something went wrong in someth= ing3"))
>=C2=A0 =C2=A0 =C2=A0c)
>=C2=A0 =C2=A0(else
>=C2=A0 =C2=A0 =C2=A0;;chosen by fair dice roll. Guaranteed to be random=
>=C2=A0 =C2=A0 =C2=A04)))
>
> While awful, is sometimes what the world makes us do.
>
> The change means cond, case, when and unless behaves like it does in <= br> > racket. Do was below case, so I changed that as well, and will actuall= y
> become yet another way guile is superior to racket.
>
> I did also change the documentation, but I learned english by watching=
> Beverly Hills cop, so that might need some fine touches by a capable <= br> > english speaker.
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0
>
> Best regards
>=C2=A0 =C2=A0Linus Bj=C3=B6rnstam
> Attachments:
> * 0001-Allow-definitions-in-derived-conditional-forms.patch

--00000000000041dbe205d736dde4--