unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Damien Mattei <damien.mattei@gmail.com>
To: Taylan Kammer <taylan.kammer@gmail.com>
Cc: Jean-Paul Roy <jean-paul.roy@unice.fr>,
	guile-devel <guile-devel@gnu.org>
Subject: Re: new function
Date: Thu, 23 Sep 2021 22:42:36 +0200	[thread overview]
Message-ID: <CADEOadeZVOW3CXDPDOWXB15Y3pvzfDnWZ5Zu+3nG5gJrtCTa4w@mail.gmail.com> (raw)
In-Reply-To: <9c058f24-5b15-417a-17ff-10bc13fed12d@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3307 bytes --]

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)))))
;;; <stdin>: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 <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 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
>

[-- Attachment #2: Type: text/html, Size: 5027 bytes --]

  reply	other threads:[~2021-09-23 20:42 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-19  7:54 new function Damien Mattei
2021-09-19 14:41 ` Matt Wette
2021-09-19 14:43   ` Matt Wette
2021-09-19 21:38 ` Taylan Kammer
2021-09-21 12:26   ` Damien Mattei
2021-09-22  8:44   ` Damien Mattei
2021-09-22  9:06     ` William ML Leslie
2021-09-22  9:53       ` Damien Mattei
2021-09-22 18:51         ` Taylan Kammer
2021-09-22 21:52           ` William ML Leslie
2021-09-23  8:40             ` Damien Mattei
2021-09-23 19:03             ` Taylan Kammer
2021-09-23 17:27           ` Damien Mattei
2021-09-23 18:00             ` Maxime Devos
2021-09-23 20:27             ` Taylan Kammer
2021-09-23 20:42               ` Damien Mattei [this message]
2021-09-23 20:48               ` Taylan Kammer
2021-09-23 21:53                 ` Damien Mattei
2021-09-24  4:41                   ` Damien Mattei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADEOadeZVOW3CXDPDOWXB15Y3pvzfDnWZ5Zu+3nG5gJrtCTa4w@mail.gmail.com \
    --to=damien.mattei@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=jean-paul.roy@unice.fr \
    --cc=taylan.kammer@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).