Hi, with PIL-Run (Perl 6 to Perl 5 compiler) progressing rapidly, the topic "binding" came up on #perl6.
"Binding is a simple symbol table manipulation, right?" "No, consider @array[$idx] := $var or more generally $sub(@args) := $var." Then we wondered what should happen to array elements which are bound to other variables if some things happen to the array. (Of course, the same thoughts apply to hashes as well). Consider an element @array[$idx] being bound to a variable $var, i.e. @array[$idx] := $var; After the binding, what happens if you do... * @array[$idx] = $new_value; # $var is now $new_value * @array.delete($idx); # $var unchanged, but assigning to $var doesn't modify @array any # longer; similarily, changing @array[$idx] doesn't modify $var now. * @array = (); # $var unchanged, but assigning to $var doesn't modify @array any # longer; similarily, changing @array[$idx] doesn't modify $var now. * @array := @other_array; # $var unchanged, but assigning to $var doesn't modify @array any # longer; similarily, changing @array[$idx] doesn't modify $var now. * sub foo (@arr) { @arr[$idx] = $new_value } foo @array; # $var and @array[$idx] are now $new_value * sub bar (Array $arr) { $arr[$idx] = $new_value } foo @array; # $var and @array[$idx] are now $new_value * sub grtz ([EMAIL PROTECTED] is rw) { @args[$idx] = $new_value } grtz @array; # $var and @array[$idx] are now $new_value * sub baka ([EMAIL PROTECTED]) { push @args, $some_value } baka @array; # $var, @array[$idx] and @array unchanged Sane? * What happens if @array gets spliced? More precisely, does &splice call .delete before changing an array element? I.e. does &splice call... @array.delete($some_index); @array[$some_index] = $some_value; # or @array[$some_index] = $some_value; * What happens if the array becomes tied (or was already)? --Ingo -- Linux, the choice of a GNU | The computer revolution is over. The generation on a dual AMD | computers won. -- Eduard Bloch Athlon! |