[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: new function
From: |
Taylan Kammer |
Subject: |
Re: new function |
Date: |
Thu, 23 Sep 2021 22:27:31 +0200 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 |
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
- Re: new function, (continued)
- Re: new function, Damien Mattei, 2021/09/21
- Re: new function, Damien Mattei, 2021/09/22
- Re: new function, William ML Leslie, 2021/09/22
- Re: new function, Damien Mattei, 2021/09/22
- Re: new function, Taylan Kammer, 2021/09/22
- Re: new function, William ML Leslie, 2021/09/22
- Re: new function, Damien Mattei, 2021/09/23
- Re: new function, Taylan Kammer, 2021/09/23
- Re: new function, Damien Mattei, 2021/09/23
- Re: new function, Maxime Devos, 2021/09/23
- Re: new function,
Taylan Kammer <=
- Re: new function, Damien Mattei, 2021/09/23
- Re: new function, Taylan Kammer, 2021/09/23
- Re: new function, Damien Mattei, 2021/09/23
- Re: new function, Damien Mattei, 2021/09/24