Ok, I see my mistake. I assumed that let and the rest could create
enclosing environments, when only a function call can.

Another example I made of how to use 'up:

: (de f () (and 1000 (up 1 @) @))
-> f
: (and 10 (f))
-> 10

Thanks for the clarification alex!

On Mon, May 24, 2021 at 12:55 AM Alexander Burger <a...@software-lab.de>
wrote:

> On Sun, May 23, 2021 at 08:44:32PM -0500, polifemo wrote:
> > `(let @ 1 (let @ 10 (let @ 20 (up 2 @))))`
>
> This are two misunderstandings in this example:
>
> 1. It has not a good idea to bind '@' in a 'let' expression. '@' is set
>    implicitly by flow- and logic-functions, so a correct usage would be
>
>       (and 1 (or 10 (while 20 (up 2 @))))
>
>    or - more realistically -
>
>       (and (foo) (or (bar) (while (zup) (up 2 @))))
>
> 2. 'up' does not care about 'let', 'use', 'for' etc. They are ignored. An
> up
>    "enclosing environment" always means the enclosing *function*
> environment. So
>    all the above 'let's all run in the same environment. The same rule
> applies
>    to the environment offsets to 'eval' and 'run'.
>
>
> > returns 1, as I expected, if I enclose the 'up expression inside a
> function
>
> This return value of '1' just happens because the environment setup in
> bindeng
> '@' in 'let' is undefined.
>
>
> Let me try to give an example.
>
>    (when 7  # The result of 'when' is what we are interested in
>       (extract
>          '((N)  # Here we are in a function
>             (when (num? N)  # 'when' sets '@'
>                (+ N @) ) )  # so we add the wrong '@'
>          (1 a 2 b 3)))
>    -> (2 4 6)
>
>    (when 7
>       (extract
>          '((N)  # in a function
>             (when (num? N)
>                (+ N (up 1 @)) ) )  # Here we get the '7'
>          (1 a 2 b 3)))
>    -> (8 9 10)
>
> ☺/ A!ex
>
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>

Reply via email to