From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Damien Mattei Newsgroups: gmane.lisp.guile.devel,gmane.lisp.guile.user Subject: Re: expression and definition context in Scheme Date: Wed, 31 Aug 2022 09:01:34 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000e7f04605e784113f" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29771"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user , guile-devel To: =?UTF-8?Q?Linus_Bj=C3=B6rnstam?= Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Wed Aug 31 09:02:23 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 1oTHjz-0007Xz-1W for guile-devel@m.gmane-mx.org; Wed, 31 Aug 2022 09:02:23 +0200 Original-Received: from localhost ([::1]:54366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oTHjx-0006Q1-LO for guile-devel@m.gmane-mx.org; Wed, 31 Aug 2022 03:02:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oTHjZ-0006Pp-Q8; Wed, 31 Aug 2022 03:01:57 -0400 Original-Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]:44941) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oTHjU-0001Hd-07; Wed, 31 Aug 2022 03:01:57 -0400 Original-Received: by mail-lj1-x232.google.com with SMTP id by6so13630363ljb.11; Wed, 31 Aug 2022 00:01:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=BH8DFkZGiAVZjuXg9vXEKaqoKFhYloNVlZe6IqOnppo=; b=GLYxBrOx8ehLULzQnmSKyC+LX5e4e3XwjxfEncVpsxSfJTOe+B1/JwmaYSwiRqZ9mu b+NUfovfGUnLhR5Nmu7H5SlRvm4GydkP0DjnNcDOHaRz9BCP4csVMD4IkjNoh25Y3NMI /54UD2w7PZPl8gLGB0IX10UY3QieBWKaRg48aVtC4z6YGCi0/bZ8zD3j+8Hg3x5SNgNR Hve/DhUnl2lD+f7vflqLNwIzyD7Wfx3jEYZpI8HlO5mpJ2rROXgsQb/9i3dNyErs38Ad 9qSZgAbLP07SwCbt5+zcNYoL5wjRJuQaQ1UV4lk4+JEthtvg4/0vE9iLKkCjSkUVwkgG SowA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=BH8DFkZGiAVZjuXg9vXEKaqoKFhYloNVlZe6IqOnppo=; b=5VaLjL5++kxaLEJR1bER6IJb0I9CX2taA34wcKOUJ9aIig/HhKfAMjycJflIOY4I3d RNlXsVXVQ25tqf+CG0pwZn/QhYWgAwgEDvntnhykL6CsDZdDk1+7uw+pKkCNUT5H6ck3 zROFUfunav4qYm/RrGfpLGGDL4bfbmbuzt3v08F5WD+V22mzV0PRfNYPolDgX3BzTyDy yGCDClWBJlSz+UrD9khsmS4fdgdOMWOCL8TwZ3aMvQ6nf4P+VEC6ZLLcN2hKkb70Iqu8 6JH0F8JNV6H7P82Obbo+x4467lx/agO4rPnsVfhPDMPvT+fYaruxjrgRkTJfU4/vf8x2 CeZQ== X-Gm-Message-State: ACgBeo3GrmQHSwyNRFp+X4hhfW2YMQC8kE/qoFBv6y9obfLnrXnqufIG u410NNZQIShpjRRni9f00Fe3Ik19wb5aBoD0rCE= X-Google-Smtp-Source: AA6agR6DwpY37xEyVOKCQGmyisO86CtOrlZoH4Y8Chm5ppohgfnlg2nC/IAhI8lE7KLvqia696cUuclVXsIHIVwXJGY= X-Received: by 2002:a2e:a801:0:b0:261:91a3:bc44 with SMTP id l1-20020a2ea801000000b0026191a3bc44mr7838464ljq.497.1661929305664; Wed, 31 Aug 2022 00:01:45 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::232; envelope-from=damien.mattei@gmail.com; helo=mail-lj1-x232.google.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, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: 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:21338 gmane.lisp.guile.user:18553 Archived-At: --000000000000e7f04605e784113f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello Linus, if you have a repo somewhere with code this could be interesting ? do you think this could be set in the main code of guile? or is it just a personal project? there is two options, one is to have guile modified for doing this , the other is: i can modify when, unless, cond, case, while, and do and insert those macro in my Scheme+ project. I always try to keep compatibility with RnRS and in fact except cond none of when, unless, cond, case, while, and do are in standart RnRS scheme, anyway having the possibility to use 'define in any of those when, unless, cond, case, while, and do does not remove any backward compatibility. About documentation, there should not be a lot of work. I can do all that if it is possible to make it in guile repository if you have no time. Regards, Damien On Tue, Aug 30, 2022 at 12:47 PM Linus Bj=C3=B6rnstam < linus.bjornstam@veryfast.biz> wrote: > I am working on a patch to guile to add definitions to just about every > body except for (begin ...) outside definition context. > > The patch is trivial, but I have to document it and a patch to r6rs that > makes the r6rs cons work according to spec. > > I had a kid recently so it might take some time before I have any compute= r > time, so if anyone has some time this is a really simple thing. You can > find the first patch somewhere in this mailing list, it only changes the > (begin ...)s in the derived forms in (ice-9 boot-9) to (let () ...). Then= i > was going to copy the cond and case from the r6rs appendix and add some > error reporting. > > The most difficult part is documenting it :) > > Andy have the idea hos blessing, and will mean guile gets define in > expression context in when, unless, cond, case, while, and do as well as = in > derived forms. > > -- > Linus Bj=C3=B6rnstam > > On Sat, 27 Aug 2022, at 18:48, Damien Mattei wrote: > > Hello, > > > > i'm facing sometimes recursively the problem to have definitions in > > expression context, which i manage every time by adding an upper empty > > (let () my definitions goes here ) > > the last case i was facing this probleme is defining a 'for macro: > > > > ;; scheme@(guile-user)> (for ({i <+ 0} {i < 5} {i <- {i + 1}}) (display > > i) (newline)) > > ;; 0 > > ;; 1 > > ;; 2 > > ;; 3 > > ;; 4 > > > > > > (define-syntax for > > > > (syntax-rules () > > > > ((_ (init test incrmt) b1 ...) > > > > (let () > > init > > (let loop () > > (when test > > b1 ... > > incrmt > > (loop))))))) > > > > this one fails in my Scheme+ code below: > > (define (compute-carries n) > > > > (for ( {k <+ 0} {k <=3D n} {k <- {k + 1}} ) > > > > { Ckp1 <+ (compute-Ck-plus1 k) } > > (display-nl Ckp1))) > > > > because { Ckp1 <+ (compute-Ck-plus1 k) } expands in : > > (define Ckp1 (compute-Ck-plus1 k)) > > and i get a compilation error: > > ;;; Syntax error: > > ;;; logic-syracuse+.scm:15:7: definition in expression context, where > > definitions are not allowed, in form (define Ckp1 (compute-Ck-plus1 k)) > > > > so i replace my 'for macro definition with: > > > > (define-syntax for > > > > (syntax-rules () > > > > ((_ (init test incrmt) b1 ...) > > > > (let () > > init > > (let loop () > > (when test > > (let () > > b1 ... > > incrmt > > (loop)))))))) > > > > and it works, but you will notice an abusive use of empty (let () ...) > > in the code to avoid the restrictions of definitions not allowed in > > expression context. > > > > My ideas is as it is so easy to cheat the compiler from seeing the > > expressio context why does the compiler restrict this? expression and > > defintion context, i'm not sure they are in scheme standarts, are they > > really usefull? > > why not remove this from Scheme at all? > > > > Regards, > > > > Damien > --000000000000e7f04605e784113f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello Linus,

if you have a repo somewhere with code this could be interesting ? do you= think this could be set in the main code of guile? or is it just a persona= l project? there is two options, one is to have guile modified for doing th= is , the other is: i can modify when, unless, cond, case, while, and do and= insert those macro in my Scheme+ project. I always try to keep compatibili= ty with RnRS and in fact except cond none of when, unless, cond, case, whil= e, and do are in standart RnRS scheme, anyway having the possibility to use= 'define in any of those when, unless, cond, case, while, and do does n= ot remove any backward compatibility. About documentation, there should not= be a lot of work. I can do all that if it is possible to make it in guile = repository if you have no time.

Regards,
Damien

On Tue, Aug 30, 2022 at 12:47 PM Linus Bj=C3=B6rnstam <= linus.bjornstam@veryfast.bi= z> wrote:
I am working on a patch to guile to add definitions to just about every bo= dy except for (begin ...) outside definition context.

The patch is trivial, but I have to document it and a patch to r6rs that ma= kes the r6rs cons work according to spec.

I had a kid recently so it might take some time before I have any computer = time, so if anyone has some time this is a really simple thing. You can fin= d the first patch somewhere in this mailing list, it only changes the (begi= n ...)s in the derived forms in (ice-9 boot-9) to (let () ...). Then i was = going to copy the cond and case from the r6rs appendix and add some error r= eporting.

The most difficult part is documenting it :)

Andy have the idea hos blessing, and will mean guile gets define in express= ion context in when, unless, cond, case, while, and do as well as in derive= d forms.

--
=C2=A0 Linus Bj=C3=B6rnstam

On Sat, 27 Aug 2022, at 18:48, Damien Mattei wrote:
> Hello,
>
> i'm facing sometimes recursively the problem to have definitions i= n
> expression context, which i manage every time by adding an upper empty=
> (let () my definitions goes here )
> the last case i was facing this probleme is defining a 'for macro:=
>
> ;; scheme@(guile-user)> (for ({i <+ 0} {i < 5} {i <- {i + = 1}}) (display
> i) (newline))
> ;; 0
> ;; 1
> ;; 2
> ;; 3
> ;; 4
>
>
> (define-syntax for
>=C2=A0
>=C2=A0 =C2=A0(syntax-rules ()
>=C2=A0 =C2=A0
>=C2=A0 =C2=A0 =C2=A0((_ (init test incrmt) b1 ...)
>
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (let ()
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 init
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let loop ()
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(when test
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0b1 ...
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0incrmt
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(loop)))))))
>
> this one fails in my Scheme+ code below:
> (define (compute-carries n)
>
>=C2=A0 =C2=A0(for ( {k <+ 0}=C2=A0 {k <=3D n}=C2=A0 {k <- {k += 1}} )
>
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 { Ckp1 <+ (compute-Ck-plus1 k) }
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (display-nl Ckp1)))
>
> because { Ckp1 <+ (compute-Ck-plus1 k) } expands in :
> (define Ckp1 (compute-Ck-plus1 k))
> and i get a compilation error:
> ;;; Syntax error:
> ;;; logic-syracuse+.scm:15:7: definition in expression context, where =
> definitions are not allowed, in form (define Ckp1 (compute-Ck-plus1 k)= )
>
> so i replace my 'for macro definition with:
>
> (define-syntax for
>=C2=A0
>=C2=A0 =C2=A0(syntax-rules ()
>=C2=A0 =C2=A0
>=C2=A0 =C2=A0 =C2=A0((_ (init test incrmt) b1 ...)
>
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (let ()
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 init
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let loop ()
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(when test
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(let () >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0b1 ...
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0incrmt
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(loop))))))))
>
> and it works, but you will notice an abusive use of empty (let () ...)=
> in the code to avoid the restrictions of definitions not allowed in > expression context.
>
> My ideas is as it is so easy to cheat the compiler from seeing the > expressio context why does the compiler restrict this? expression and =
> defintion context, i'm not sure they are in scheme standarts, are = they
> really usefull?
> why not remove this from Scheme at all?
>
> Regards,
>
> Damien
--000000000000e7f04605e784113f--