Hi Galt,

I wrote a code more similar to the work of the interpreters of
some other languages:

make-adder: func [x /local new-context-func container] [
     ; new-context-func means a new context
     ; any time make-adder is called...
     new-context-func: func [x] [
          func [y] append reduce [container] [add x y]
      ]
      ; Make New-context-func GC - proof during the lifetime of
its result
      container: reduce [:new-context-func]
      new-context-func x
]

Let the freedom be with you.

    Ladislav

> I think this is quite amusing.
> I am using contexts, combined with the use of compose first
> mentioned by Ladislav.
>
> Of course it is an awful perversion, but it can't be helped:
>
> >> make-adder: func [
>      x
>      /reset
>     ][
>      if reset [exit]
>      func [y] compose [
>            make-adder/reset (x)
>            add x y
>          ]
>     ]
>
> >> add6: make-adder 6
> >> add6 1
> == 7
>
> >> add5: make-adder 5
> >> add5 1
> == 6
>
> >> add6 1
> == 7
>
> >> source add6
> add6: func [y] [
>    make-adder/reset 6
>     add x y
> ]
>
> So, it actually works!
> Can you go to jail for this?
> Free variables want to be free!
>
> -galt
>
>
>


Reply via email to