Autrijus & Co.

I have managed to track down two different bugs/issues with PUGS. I explain them here in detail with examples, and todo_* tests for them are included in the following test files:
t/op/shift.t
t/op/pop.t
t/op/push.t
t/op/unshift.t


Note that these issues may not be related to these operators at all. I think the first issue is probably related to how the AST gets evaluated, and the second issue might be a problem with the Array/List type itself (or it could be these operators (push, unshift)). Either way, my Haskell skills are very weak at this point, so I will leave the real bug tracking to the more lambda inclined.

- Steve

1) It seems that when functions are inlined as arguments to another function, they will be evaluated twice.

Here is some simple code to illustrate this:
pugs -e 'my @l = (1, 2, 3); my $a = shift(@l); say $a'
prints:
1
and this code:
pugs -e 'my @l = (1, 2, 3); say shift(@l);'
also prints:
1
but this code:
pugs -e 'my @l = (1, 2, 3); say shift(@l); say shift(@l);'
should print
1
2
but it actually prints:
1
3
This issue is illustrated in the t/op/shift.t and t/op/pop.t test file, as the same issue will come up with inlined pop(@list) as well.


2) I have also found an oddity with push(), which is documented in t/op/push.t, but I am describing here in more detail.

This code:
    pugs -e 'my @l; push @l, 10; say join ", ", @l; say [EMAIL PROTECTED];'
Produces the following output:
    , 10
    2

Note the leading comma. It seems that if the @l array is not initialized, then the first element is occupied by an undef value, and the first push will go into the second slot. I tried changing the way I write push()

    pugs -e 'my @l; push @l, (10); say join ", ", @l;'
    pugs -e 'my @l; push(@l, 10); say join ", ", @l;'

NOTE: @l.push(10) is currently a syntax error

But all three versions produce the same 2 element list. However, if the @l array is initialized (even as an empty array), then the issue disappears.

The following code:
    pugs -e 'my @l = (); push(@l, 10); say join ", ", @l; say [EMAIL 
PROTECTED];'
Produces the following output:
    10
    1

The same issue comes up with unshift() as well. The following code:
    pugs -e 'my @l; unshift @l, 42; say join ", ", @l; say [EMAIL PROTECTED];'
Produces the following output (note the extra comma):
    42,
    2
And then if the @l array is initialized:
    pugs -e 'my @l = (); unshift @l, 42; say join ", ", @l; say [EMAIL 
PROTECTED];'
Produces the following output:
    42
    1



Reply via email to