[REBOL] Re: CORE experimental 2.4.39
From: lmecir:mbox:vol:cz at: 24-Nov-2000 2:55
After repairing the GC bug, Rebol is a *much* more elegant language!
Congratulations to RT. The /skip refinement is a big breakthrough too.
Jeff wrote:
> Howdy, Gabriele:
>
> > [jeff--rebol--net] wrote:
> >> Functions in the newest experimental do not exhibit indefinite
> >> extent.
> >
> > You mean, using recursion?
>
> In general, like:
>
> f: func [/x][x: random 10 'x]
> b: [] loop 10 [append b w: f probe get w] reduce b
>
> You wind up with all the same number in the block, though 'x in f's
> context had been 10 different random numbers.
>
To celebrate the GC bug removal I wrote:
Rebol [
Title: "EFunc"
Date: 24/11/2000
File: %efunc.r
Author: "Ladislav Mecir"
Email: [lmecir--mbox--vol--cz]
Purpose: {
A function creating "indefinite extent" functions.
}
Category: [Advanced]
]
e-func: function [
{Indefinite extent func}
[catch]
spec [block!]
body [block!]
] [
set-args args set-fresh-args locals
] [
set-args: func [args-supplied] [args: args-supplied]
set-fresh-args: func [fresh-args] [
while [not tail? fresh-args] [
set/any first fresh-args get/any first args
fresh-args: next fresh-args
args: next args
]
]
locals: copy []
foreach item spec [
if all [any-word? :item not set-word? :item] [
append locals to word! :item
]
]
throw-on-error [
func spec reduce [
:set-args locals
:use locals reduce [
:set-fresh-args locals
:do body
]
]
]
]
Now, the Jeff's example behaves as follows:
>> f: e-func [/x][x: random 10 'x]
>> b: [] loop 10 [append b w: f probe get w] reduce b
5
4
9
10
5
7
6
9
6
6
== [5 4 9 10 5 7 6 9 6 6]
Nice, eh?