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 Subject: Re: new function Date: Thu, 23 Sep 2021 10:40:02 +0200 Message-ID: References: <147c2fb4-75d6-7cf6-4f4a-4edd996b0a4a@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000004bf35a05cca59405" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15089"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Jean-Paul Roy , guile-devel To: William ML Leslie Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Thu Sep 23 10:40:46 2021 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 1mTKHd-0003fc-8b for guile-devel@m.gmane-mx.org; Thu, 23 Sep 2021 10:40:45 +0200 Original-Received: from localhost ([::1]:57500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mTKHb-0005Gc-Bz for guile-devel@m.gmane-mx.org; Thu, 23 Sep 2021 04:40:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37212) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTKHC-0005GU-4S for guile-devel@gnu.org; Thu, 23 Sep 2021 04:40:18 -0400 Original-Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]:36604) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mTKH9-00041X-SL for guile-devel@gnu.org; Thu, 23 Sep 2021 04:40:17 -0400 Original-Received: by mail-io1-xd2c.google.com with SMTP id q3so7071250iot.3 for ; Thu, 23 Sep 2021 01:40:14 -0700 (PDT) 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 :cc; bh=UCTDP0H5qhblVrTqVlilaTPYtI3G4NsnhThQs/h0I/s=; b=IbQR+y3jTN/akGmYB7iN4An6rsoGoXQ3CpAm+3Ja/rRSw74UZI5VyQWdS8yQVkmSwd 02zT7XkVywIlnEKO97zD5B8NgvJixeLlR7l30vq+LtasU6pUR1D00DuhE6yLb8Drfsjx evv56IcxeieewWHaiV8nCSV3cneAolAfviyae668pPb1iQBXxUIrKULZLuD+frwiQl5l Uvj0OK5Y5i+DsWvG2tW9qYQnkrBD0hMI1E042/IE2e8CGqUCmDfBipO4J5p1oe+kXVso Fqb2ReW4YOxgte4y55hlSnqQQ95gbNPyz5YLzhOmaxCDl1E9FKrX0EAabuckWDZAXtey eQdQ== 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:cc; bh=UCTDP0H5qhblVrTqVlilaTPYtI3G4NsnhThQs/h0I/s=; b=FBdDb/VmVDGDgtLyJSuIHgBsShalw2GpixWwEPIwNoM3hDPeyvcL46CCWfGsjtZkVW 8RKOociCAj1qBEQh0YjWrvTXxSDI2C3c0GhH0FfAb75kF+WuFOwcsrF3iRnWBA2GKYeW 1aluu6IjmEORZim/PG3xBJIIKseI7k7TAdpCEXOsY92MRCPd/vSZwCxlv8VAl0JniRmv /1tjeRy61K5GpNHpeXIdVwL934U8wm/tfo9ZpzJU6p1M4qB8u21JQRpXyd7FeC7sFviJ hvs8YSUwPO7mZ7m52RMvNLEGZd8UTLvH398gnqm83htHbAJ72+0BlObHaO2zs2pTkxtC djhQ== X-Gm-Message-State: AOAM533VYqJdAnMSYFRwuE7r7AaNLIHpG81hpcEbqpYqp14yUwPwrbyw cLMxCLlp89xE7mq94uVTOyalVLhpMfCTe2BD1xY= X-Google-Smtp-Source: ABdhPJxy1H+9Mq8IS+ZFFSJMXYeaRDJl2Aj0Yv37CVzCaZ3A4sY3JuthM55V2oaWQ4db3+1eOjfC/jwy9oRjf1aL6F0= X-Received: by 2002:a02:b91a:: with SMTP id v26mr2934329jan.78.1632386413227; Thu, 23 Sep 2021 01:40:13 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::d2c; envelope-from=damien.mattei@gmail.com; helo=mail-io1-xd2c.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 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:20878 Archived-At: --0000000000004bf35a05cca59405 Content-Type: text/plain; charset="UTF-8" interesting discussion about "scope", note i'm not saying i want Scheme+ act as Python, i'm still thinking the best solution... to be sure about terminology i find this good article about scoping: https://medium.com/altcampus/scope-local-global-and-lexical-e164f53450b3 Damien On Wed, Sep 22, 2021 at 11:52 PM William ML Leslie < william.leslie.ttg@gmail.com> wrote: > On Thu, 23 Sep 2021, 4:51 am Taylan Kammer, > wrote: > >> On 22.09.2021 11:53, Damien Mattei wrote: >> > i already do it this way for internal defines ,using a recursive macro >> that build a list of variable using an accumulator. It can works but macro >> expansion seems slow, it was not immediate at compilation on a little >> example (oh nothing more that 2 seconds) but i'm not sure it is easily >> maintainable, it is at the limit what macro can do i think ,for speed >> reasons. In fact i can not really understand in Guile as it is based on C >> and compiled when macro expansion happens,what is the time cost... so for >> all those ,perhaps not objective reason ,i prefer to avoid. >> >> I don't think there's any other way to achieve what you want, especially >> using portable Scheme code. The lexical scoping semantics of Scheme are >> a very fundamental part of the language, and cannot be worked around in >> portable Scheme code without using a macro that rewrites whole bodies of >> lambda expressions. >> >> Even using implementation-specific hacks, you won't get very far. Any >> compiled Scheme implementation, and even most interpreted ones, won't >> allow you to modify an outer scope's set of variable definitions from >> within an inner scope. >> >> So if you really want to have Python's scoping semantics in Scheme, you >> will probably have to write a complex 'def' macro that walks through the >> body and "hoists" variable definitions to the outermost scope. >> > > Python is lexically scoped, and the assignment here is supposed to be > local. > > >> If you're targeting R6RS implementations, you can use syntax-case to >> write such a macro, but it won't be easy. >> >> If you're targeting R5RS or R7RS-small implementations, you will have to >> rely on syntax-rules, which will probably be extremely difficult for this >> kind of complex macro. >> >> Personally I don't even know how I would approach the problem using the >> more capable syntax-case, let alone pure syntax-rules. >> >> -- >> Taylan >> > --0000000000004bf35a05cca59405 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
int= eresting discussion about "scope",
note i'm not saying i want Scheme+ a= ct as Python, i'm still thinking the best solution...
to be sure about terminology i= find this good article about scoping:
Damien

<= div dir=3D"ltr" class=3D"gmail_attr">On Wed, Sep 22, 2021 at 11:52 PM Willi= am ML Leslie <william.le= slie.ttg@gmail.com> wrote:
On Thu, 23 Sep 2021, 4:51 am Taylan Kammer, = <taylan.kam= mer@gmail.com> wrote:
On 22.09.2021 11:53, Damien Mattei wrote:
> i already do it this way for internal defines ,using a recursive macro= that build a list of variable using an accumulator. It can works but macro= expansion seems slow, it was not immediate at compilation on a little exam= ple (oh nothing more that 2 seconds) but i'm not sure it is easily main= tainable, it is at the limit what macro can do i think ,for speed reasons. = In fact i can not really understand in Guile as it is based on C and compil= ed when macro expansion happens,what is the time cost... so for all those ,= perhaps not objective reason ,i prefer to avoid.

I don't think there's any other way to achieve what you want, espec= ially
using portable Scheme code.=C2=A0 The lexical scoping semantics of Scheme a= re
a very fundamental part of the language, and cannot be worked around in
portable Scheme code without using a macro that rewrites whole bodies of lambda expressions.

Even using implementation-specific hacks, you won't get very far.=C2=A0= Any
compiled Scheme implementation, and even most interpreted ones, won't allow you to modify an outer scope's set of variable definitions from within an inner scope.

So if you really want to have Python's scoping semantics in Scheme, you=
will probably have to write a complex 'def' macro that walks throug= h the
body and "hoists" variable definitions to the outermost scope.

Pyt= hon is lexically scoped, and the assignment here is supposed to be local.


If you're targeting R6RS implementations, you can use syntax-case to write such a macro, but it won't be easy.

If you're targeting R5RS or R7RS-small implementations, you will have t= o
rely on syntax-rules, which will probably be extremely difficult for this kind of complex macro.

Personally I don't even know how I would approach the problem using the=
more capable syntax-case, let alone pure syntax-rules.

--
Taylan
--0000000000004bf35a05cca59405--