Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Junctions Question

3 views
Skip to first unread message

Stevan Little

unread,
Mar 17, 2005, 11:43:58 PM3/17/05
to perl6-l...@perl.org
Hello All,

I have been working on some misc. junction tests for Pugs and I ran into an
item which I am not sure of. It has to do with a junction of variables which
is then assigned to variable itself, and how "bound" the variables inside the
junction are. This is best illustrated with code, so here is the test with
comments to explain:

my $a = 'a';
my $b = '';
my $c = '';

my $any_of_them = $b | $c | $a;
# this test passes
ok('a' eq $any_of_them, '($b | $c | $a) matches at least one "a"');

$b = 'b';
$c = 'c';

# this test passes ...
ok('a' eq $any_of_them, '($b | $c | $a) matches at least one "a"');
# but these two tests don't
ok('b' eq $any_of_them, '($a | $b | $c) matches at least one "b"');
ok('c' eq $any_of_them, '($c | $a | $b) matches at least one "c"');

Those last two tests do pass if I re-make the $any_of_them junction after
assigning $b and $c. This is actually best illustrated again with this code.

my $a = 'a';
my $b = '';
my $c = '';

my $any_of_them = $b | $c | $a;
say $any_of_them;

$b = 'b';
$c = 'c';
say $any_of_them;

my $any_of_them = $b | $c | $a;
say $any_of_them;

Which will print the following:

any(a)
any(a)
any(a,b,c)

So my question is; Is this correct? Or should $a, $b and $c be more tightly
bound within the $any_of_them junction?

Thanks in advance,

- Stevan

Luke Palmer

unread,
Mar 18, 2005, 12:44:54 AM3/18/05
to Stevan Little, perl6-l...@perl.org
Stevan Little writes:
> my $a = 'a';
> my $b = '';
> my $c = '';
>
> my $any_of_them = $b | $c | $a;
> # this test passes
> ok('a' eq $any_of_them, '($b | $c | $a) matches at least one "a"');
>
> $b = 'b';
> $c = 'c';
>
> # this test passes ...
> ok('a' eq $any_of_them, '($b | $c | $a) matches at least one "a"');
> # but these two tests don't
> ok('b' eq $any_of_them, '($a | $b | $c) matches at least one "b"');
> ok('c' eq $any_of_them, '($c | $a | $b) matches at least one "c"');

That behavior is correct. Just as if you said:

my $a = 'a';
my $b = $a;
$a = 'b';
say $b; # a

This should work, however:

my $a = 'a';
my $b = '';
my $c = '';

my $any_of_them = \$a | \$b | \$c;

$b = 'b';
$c = 'c';

ok('b' eq $$any_of_them); # passes

That second $ might not need to be there. I don't understand exactly
how transparent references are yet.

Luke

0 new messages