Skip Menu |
Report information
Id: 123216
Status: resolved
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: moritz <moritz.lenz+perl [at] gmail.com>
zheglov1887 [at] gmail.com
Cc:
AdminCc:

Severity: (no value)
Tag: testneeded
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: Custom prefix- and postfix operators with the same precedence don't mix
Date: Sat, 29 Dec 2012 17:52:26 +0100
To: rakudobug [...] perl.org
From: Moritz Lenz <moritz [...] faui2k3.org>
Download (untitled) / with headers
text/plain 1.3k
Test file: sub postfix:<_post_l_>($a) is assoc<left> is equiv(&prefix:<+>) { "<$a>" } sub prefix:<_pre_l_> ($a) is assoc<left> is equiv(&prefix:<+>) { "($a)" } _pre_l_ 'a' _post_l_ ./perl6 -Ilib foo.pl ===SORRY!=== ResizablePMCArray: Can't pop from an empty array! Maybe also of interest: ./perl6 --ll-exception -Ilib foo.pl ResizablePMCArray: Can't pop from an empty array! current instr.: 'EXPR_reduce' pc 15766 (src/stage2/gen/NQPHLL.pir:5721) (src/stage2/gen/NQPHLL.pm:688) called from Sub 'EXPR' pc 15628 (src/stage2/gen/NQPHLL.pir:5657) (src/stage2/gen/NQPHLL.pm:489) called from Sub 'EXPR' pc 207808 (src/gen/perl6-grammar.pir:69050) (src/Perl6/Grammar.pm:2845) called from Sub 'statement' pc 58086 (src/gen/perl6-grammar.pir:20310) (src/Perl6/Grammar.pm:929) called from Sub 'statementlist' pc 56325 (src/gen/perl6-grammar.pir:19748) (src/Perl6/Grammar.pm:903) called from Sub 'comp_unit' pc 51125 (src/gen/perl6-grammar.pir:17855) (src/Perl6/Grammar.pm:702) called from Sub 'TOP' pc 20860 (src/gen/perl6-grammar.pir:7632) (src/Perl6/Grammar.pm:334) the exception comes from this part here: op_infix: .local pmc right, left right = pop termstack left = pop termstack # <-- HERE op[0] = left op[1] = right $P0 = opO['reducecheck'] if null $P0 goto op_infix_1 $S0 = $P0 self.$S0(op)
Date: Sat, 15 Nov 2014 21:05:31 +0000
Subject: [BUG] QRPA: Can't pop from an empty array!
To: rakudobug [...] perl.org
From: V V <zheglov1887 [...] gmail.com>
Download (untitled) / with headers
text/plain 787b
Not sure what is causing this (using Perl only a few days). I have the following example use v6 ; sub infix:«MYPLUS»(*@a) is assoc('list') { [+] @a ; } sub prefix:«MYMINUS»($a) is looser(&infix:<MYPLUS>) { -$a ; } # QRPA: Can't pop from an empty array! say (MYMINUS 1 MYPLUS 2 MYPLUS 3) ; However the following equivalent example works as expected use v6 ; sub prefix:«MYMINUS»($a) { -$a ; } sub infix:«MYPLUS»(*@a) is assoc('list') is tighter(&prefix:<MYMINUS>) { [+] @a ; } # prints -6 as expected say (MYMINUS 1 MYPLUS 2 MYPLUS 3) ; Output of perl6 --version is This is perl6 version 2014.10-121-g7dd7292 built on parrot 6.9.0 revision RELEASE_6_9_0-72-g4b90157 Thanks, Vladimir
Download (untitled) / with headers
text/plain 906b
The prefix op must be unary, so this works: sub infix:<MYPLUS>(*@a) is assoc('list') { [+] @a } sub prefix:<MYMINUS>($a) is looser(&infix:<MYPLUS>) is assoc('unary') { -$a } say (MYMINUS (1 MYPLUS 2 MYPLUS 3)); # -6 The problem and the weird (LTA) error message turn up when the prefix op has any other assoc, for example: sub prefix:<MYMINUS>($a) is assoc('unary') { -$a }; say (MYMINUS 1); # works sub prefix:<MYMINUS>($a) is assoc('left') { -$a }; say (MYMINUS 1); # fails sub prefix:<MYMINUS>($a) is assoc('right') { -$a }; say (MYMINUS 1); # fails sub prefix:<MYMINUS>($a) is assoc('list') { -$a }; say (MYMINUS 1); # fails sub prefix:<MYMINUS>($a) is assoc('non') { -$a }; say (MYMINUS 1); # fails I don't what would be the best way to solve that error message. 1) make prefix ops unary by default? 2) complain about prefix ops that are not unary, and suggest to make them unary? 3) both?
Download (untitled) / with headers
text/plain 1.1k
There is no unary associativity, according to S03: Using two ! symbols below generically to represent any pair of operators that have the same precedence, the associativities specified above for binary operators are interpreted as follows: Assoc Meaning of $a ! $b ! $c ===== ========================= L left ($a ! $b) ! $c R right $a ! ($b ! $c) N non ILLEGAL C chain ($a ! $b) and ($b ! $c) X list infix:<!>($a; $b; $c) O N/A (not really an operator) For unaries this is interpreted as: Assoc Meaning of !$a! ===== ========================= L left (!$a)! R right !($a!) N non ILLEGAL So on the surface I think the issue here is that rakudo is using a 'unary' associativity as a cheat, rather than correctly implementing unary associativities. (S03 further notes that standard Perl 6 doesn't take advantage of associativity on unaries, since it keeps each level consistently prefix/postfix, which would explain why rakudo can get away with a 'unary' assoc for standard P6)

Heh, what a clusterfuck! OK let's try to untangle this ticket.

The second issue mentioned in this ticket (MVMArray: Can't pop from an empty array) was fixed. ✓
Output on all releases: https://gist.github.com/Whateverable/5d30c8b09af4ddee8bdb67693cd0f6e0
Fixed in (2015-03-30) https://github.com/rakudo/rakudo/commit/2b303a0dcffdda7f833ff9bef01a6e833e2c2422

Therefore, 「testneeded」.


As for the OP, it seems to be fixed too, but the code is probably not supposed to work. See:

'a' _post_l_

↑ There's whitespace before the postfix and that's not supposed to work. It also doesn't help that the chosen operator is a valid identifier.

That said:
 
say _pre_l_ 'a'_post_l_ # OUTPUT:

Show quoted text
===SORRY!=== Error while compiling /home/alex/./deleteme.pm6
Operators '_pre_l_ ' and '_post_l_' are non-associative and require parentheses
at /home/alex/./deleteme.p6:7
------> say _pre_l_ 'a'_post_l_⏏<EOL>
    expecting any of:
        postfix


As per the last comment, there's no unary associativity, so my best guess is that it is not supposed to work (at least at this point).

So we can change the code like the error message suggests:

say (_pre_l_ 'a')_post_l_ # OUTPUT: «<(a)>␤»

Note that the other way is not going to work because it looks too much like a method call. But that works! ✓

Here's the output on all releases: https://gist.github.com/Whateverable/f80d6512dedef6a7914d9d24a7f27138
And that's when it was fixed: (2017-04-04) https://github.com/rakudo/rakudo/commit/f9f0883c6cef3695c5150d336f5e6552e1be4a4c

So I'd say 「testneeded」 (that is, two tests needed), but see RT#131099 for further progress on assoc with non-infix ops.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org