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 22:42:36 +0200 Message-ID: References: <147c2fb4-75d6-7cf6-4f4a-4edd996b0a4a@gmail.com> <9c058f24-5b15-417a-17ff-10bc13fed12d@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000006c195505ccafaca9" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22100"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Jean-Paul Roy , guile-devel To: Taylan Kammer Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Thu Sep 23 22:46:07 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 1mTVbb-0005dA-Cy for guile-devel@m.gmane-mx.org; Thu, 23 Sep 2021 22:46:07 +0200 Original-Received: from localhost ([::1]:51992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mTVbZ-0005gW-E5 for guile-devel@m.gmane-mx.org; Thu, 23 Sep 2021 16:46:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTVYR-0002sh-0f for guile-devel@gnu.org; Thu, 23 Sep 2021 16:42:51 -0400 Original-Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]:39519) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mTVYO-0001Sr-VR for guile-devel@gnu.org; Thu, 23 Sep 2021 16:42:50 -0400 Original-Received: by mail-il1-x12f.google.com with SMTP id h9so8027995ile.6 for ; Thu, 23 Sep 2021 13:42:48 -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=y3ZMoAcsCsU/PxvYQaATB46gpm3lxZ4TT75MKdqnEBE=; b=H/NTUmC6XgE5LcHODUfZzDWukVFtndjLd2XhY1iV7m3LQaLavM4jCIGkDVkzoUY+z+ lLlRgRmU+DUCEySH93CWkFUAT0z3+vhK/twWYCU1cMWDvPO4JxH2FcYdPX90RA9jGhJW QiSYWCavlpc6J/DA+gFYL9uYPziimwv73epIXLe7xBthZuBhiiWCl06qutuqDQQqZCp3 rXA2ODLKSWvIfb2ecsEZ8tl8DeSsU4SA1rEP3E6swJT6KHXYoo/wMiiILG2wnhKXhEjk 0sN+kDM/8vMSLY5a2KLCzDWqdELG6DCdQdMDG1aTE5GkSSlN6hypTUNAenWVSzWMi3tG 0cAw== 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=y3ZMoAcsCsU/PxvYQaATB46gpm3lxZ4TT75MKdqnEBE=; b=mvKRX+lEMMv//mNnZPzmn34jPvgVQCr8bQARONW1YahZIxHJ+e0g6ByFXCJT3wT3Iu 20i3kHDVK7i4swPEL9cD8/ObImIVbRZ5Q2dEu2mwattmjz/F0nHtPX6Fb66LDTb3yRUO AG3TQkw3b8tH0RDLw+l5GQOr+dP2Hyw3U7qaWPLj98ZBci1klqxsXY9llSb+hN+LzdBU /dOnvd6s63xjHYEMbP/mdc0RyK5D8pk/qFNuR+4HSSaRb9LUDt2yWWRrTB8vzDsGL15Z kwrrdwI6AJQ5mmwD6kG1Ad4Nml7OAHkKeWRFl/+G/peClKf1oqlP/AlDhVX/7J9krvzc 8Olg== X-Gm-Message-State: AOAM531d0h7QdhMFAGRfcd6Vrx66x//lULr2oJHUIr//LabUCvpIs2oF CAUz8jyn0M+ojAWEHlTlhnnCzmeTgX84ZCEfCLE= X-Google-Smtp-Source: ABdhPJz72TMUyCbUifzJxqy7yH+ez4DkkQx9pqUK+updx5k6GA05N1BrO36HUllz7+1R8hdKu2wBfV7jbfbwEB+Cmsw= X-Received: by 2002:a05:6e02:156a:: with SMTP id k10mr5390213ilu.317.1632429767660; Thu, 23 Sep 2021 13:42:47 -0700 (PDT) In-Reply-To: <9c058f24-5b15-417a-17ff-10bc13fed12d@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::12f; envelope-from=damien.mattei@gmail.com; helo=mail-il1-x12f.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:20883 Archived-At: --0000000000006c195505ccafaca9 Content-Type: text/plain; charset="UTF-8" yes it can reuse an upper and precedent definition but a nested definition can not be used later at an upper level. anyway it would not be portable , for all those reason i will use to separate operator ,basically <- for set! and <+ for define ,so i can even modify toplevel bindings , i did not want to have all the python behavior which is not safe and did not allow local nested variables. even using an exception will not solve the problem: scheme@(guile-user)> (call-with-current-continuation (lambda (exit) (with-exception-handler (lambda (e) (exit "undefined ,you need to define somewhere")) (lambda () (set! notdefined 7))))) ;;; :97:69: warning: possibly unbound variable `notdefined' $28 = "undefined ,you need to define somewhere" ??? i do not see any solution with a macro with exception Damien On Thu, Sep 23, 2021 at 10:27 PM Taylan Kammer wrote: > On 23.09.2021 19:27, Damien Mattei wrote: > > yes i know parsing the whole code is the only portable solution, but it > is slow,even on a few dozen of lines the slowing is visible ,so i can even > think of that on one thousand lines... > > > > I finally succeed in Guile with simple piece of code to make my example > run with a single assignment operator <- , here i define for variable the > assignment operator <$ , <- is working with arrays too: > > > > *Preview:* > > > > (define-syntax <$ > > > > (lambda (s) > > > > (syntax-case s () > > > > ((_ var value) > > > > (case (syntax-local-binding #'var) > > > > ((lexical) #'(begin > > (display "<$ : lexical scope : ") > > (display (quote var)) > > (newline) > > (set! var value))) > > > > ((displaced-lexical) #'(begin > > (display "<$ : displaced-lexical scope : > ") > > (display (quote var)) > > (newline) > > (set! var value))) > > > > ((global) #'(begin > > (display "<$ : global scope : ") > > (display (quote var)) > > (newline) > > (define var value))) > > > > (else #'(begin > > (display "<$ : unknow variable scope :") > > (display (quote var)) > > (error "<$ : unknow variable scope : ")))))))) > > > > I can't seem to find syntax-local-binding in Guile 2.2 or 3.0. Did you > have to import some special module, or are you using another version? > > Either way, I suspect that the following will not work with your macro: > > (let () > (let () > (<$ x 1)) > (display x) > (newline)) > > If I understand correctly, it will expand to: > > (let () > (let () > (define x 1)) > (display x) > (newline)) > > And that won't work because 'x' is only defined in the inner 'let'. > > This is where we see the crucial difference between Scheme and Python: > in Python there is nothing similar to an inner 'let'. There is only > one function-level scope. In Scheme, there can be as many nested > scopes as you want, and an inner scope can't affect an outer one. > > -- > Taylan > --0000000000006c195505ccafaca9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
yes= it can reuse an upper and precedent definition but a nested definition can= not be used later at an upper level.

anyway it would not be portable , for all those reason i will = use to separate operator ,basically <- for set! and <+ for define ,so= i can even modify toplevel bindings , i did not want to have all the pytho= n behavior which is not safe and did not allow local nested variables.

even using an exception will = not solve the problem:
scheme@(guile-user)> (call-with-current-continuation
=C2=A0 = =C2=A0(lambda (exit)
=C2=A0 =C2=A0 =C2=A0(with-exception-handler
=C2= =A0 =C2=A0 =C2=A0 (lambda (e)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (exit "un= defined ,you need to define somewhere")) (lambda () (set! notdefined 7= )))))
;;; <stdin>:97:69: warning: possibly unbound variable `notde= fined'
$28 =3D "undefined ,you need to define somewhere"

??? i do not see any solut= ion with a macro with exception

Damien


On Thu, Sep 23, 2021 at 10:27 PM Taylan Kammer <= ;taylan.kammer@gmail.com>= wrote:
On 23.09= .2021 19:27, Damien Mattei wrote:
> yes i know parsing the whole code is the only portable solution, but i= t is slow,even on a few dozen of lines the slowing is visible ,so i can eve= n think of that on one thousand lines...
>
> I finally succeed in Guile with simple piece of code to make my exampl= e run with a single assignment operator <-=C2=A0 , here i define for var= iable the assignment operator <$ , <- is working with arrays too:
>
> *Preview:*
>
> (define-syntax <$
>=C2=A0 =C2=A0
>=C2=A0 =C2=A0(lambda (s)
>=C2=A0 =C2=A0 =C2=A0
>=C2=A0 =C2=A0 =C2=A0(syntax-case s ()
>=C2=A0 =C2=A0 =C2=A0 =C2=A0
>=C2=A0 =C2=A0 =C2=A0 =C2=A0((_ var value)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (case (syntax-local-binding #'var)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ((lexical) #'(begin
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0(display "<$ : lexical scope : ")
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0(display (quote var))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0(newline)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0(set! var value)))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 ((displaced-lexical) #'(begin
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(display "<$ : disp= laced-lexical scope : ")
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(display (quote var))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(newline)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(set! var value)))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ((global) #'(begin
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (display "<$ : global scope : ")
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (display (quote var))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (newline)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (define var value)))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (else #'(begin
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (display= "<$ : unknow variable scope :")
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (display= (quote var))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (error &= quot;<$ : unknow variable scope : "))))))))
>

I can't seem to find syntax-local-binding in Guile 2.2 or 3.0.=C2=A0 Di= d you
have to import some special module, or are you using another version?

Either way, I suspect that the following will not work with your macro:

=C2=A0 (let ()
=C2=A0 =C2=A0 (let ()
=C2=A0 =C2=A0 =C2=A0 (<$ x 1))
=C2=A0 =C2=A0 (display x)
=C2=A0 =C2=A0 (newline))

If I understand correctly, it will expand to:

=C2=A0 (let ()
=C2=A0 =C2=A0 (let ()
=C2=A0 =C2=A0 =C2=A0 (define x 1))
=C2=A0 =C2=A0 (display x)
=C2=A0 =C2=A0 (newline))

And that won't work because 'x' is only defined in the inner &#= 39;let'.

This is where we see the crucial difference between Scheme and Python:
in Python there is nothing similar to an inner 'let'.=C2=A0 There i= s only
one function-level scope.=C2=A0 In Scheme, there can be as many nested
scopes as you want, and an inner scope can't affect an outer one.

--
Taylan
--0000000000006c195505ccafaca9--