Full closures for D
Bruce Adams
tortoise_74 at yeah.who.co.uk
Tue Nov 6 13:50:23 PST 2007
Martin d Anjou Wrote:
> >> 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
I see the analogy but this is actually about whether a variable should be shared between 2 threads / processes. I don't think there is a native D equivalent but "shared" has been proposed several times.
This would be more like "export".
More information about the Digitalmars-d
mailing list