Full closures for D
Martin d Anjou
point14 at magma.ca
Tue Nov 6 10:17:25 PST 2007
>> It's not an optimal solution because the "does the function escape"
>> heuristic captures too many functions.
>
> You could let the programmer specify explicitly whether or not to make a
> function a closure or not, maybe with a key word or something.
A programming language called Vera uses the "shadow" keyword to acheive a
somewhat related effect.
>From http://www.asic-world.com/vera/concurrency_control1.html:
program shadow_variable {
spawn_process() ;
delay(100) ;
spawn_process_with_shawdow();
delay(100) ;
}
task print(integer i) {
printf(" n = %0d\n", i);
}
task spawn_process () {
integer n;
printf("In spawn_process\n");
for(n=0; n<3 ; n++) {
fork
print(n) ;
join none
}
}
task spawn_process_with_shawdow () {
shadow integer n;
printf("In spawn_process_with_shadow_variable\n");
for(n=0; n<3 ; n++) {
fork
print(n) ;
join none
}
}
Executing this code gives:
In spawn_process
n = 3
n = 3
n = 3
In spawn_process_with_shadow_variable
n = 0
n = 1
n = 2
I am not a language expert, but this seemed related.
Martin
More information about the Digitalmars-d
mailing list