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

Owner: Nobody
Requestors: masak <cmasak [at] gmail.com>
Cc:
AdminCc:

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



Subject: [BUG] Variable in string in <{ }> interpolator in regex doesn't get a proper lookup in Rakudo
Date: Thu, 1 Mar 2012 22:07:04 +0100
To: rakudobug [...] perl.org
From: Carl Mäsak <cmasak [...] gmail.com>
Download (untitled) / with headers
text/plain 572b
<masak> nom: https://gist.github.com/1951347 <p6eval> nom 48af8c: OUTPUT«===SORRY!===␤Variable $a is not declared␤at eval_0:1␤» <masak> huh! <jnthn> nom: "x" ~~ /:my $a = 42; { say $a } <?>/ <p6eval> nom 48af8c: OUTPUT«42␤» <jnthn> oh... <jnthn> it's eval'ing that regex, no? <jnthn> masak: if you can golf that one it'd be nice... <masak> gotcha. <masak> I'll golf it and then RT it. <masak> nom: '' ~~ / :my $a; <{ '$a' }> / <p6eval> nom 48af8c: OUTPUT«===SORRY!===␤Variable $a is not declared␤at eval_0:1␤» <masak> golf'd. * masak submits rakudobug
Download (untitled) / with headers
text/plain 740b
There are weird things goind on: good: <FROGGS> r: '' ~~ / :my $a; <{ '$a' }> / <p6eval> rakudo 123dfa: ( no output ) good: <FROGGS> r: say '' ~~ / :my $a; <{ '$a' }> / <p6eval> rakudo 123dfa: OUTPUT«#<failed match>␤» weird: <FROGGS> r: say '123' ~~ / :my $a=2; <{ '$a' }> / <p6eval> rakudo 123dfa: OUTPUT«「1」␤␤» good: <FROGGS> r: say '123' ~~ / :my $a=2; <{ "$a" }> / <p6eval> rakudo 123dfa: OUTPUT«「2」␤␤» weird: <FROGGS> r: say '$a' ~~ / :my $a=2; <{ '$a' }> / <p6eval> rakudo 123dfa: OUTPUT«#<failed match>␤» good: <FROGGS> std: say '$a' ~~ / <{ '$a' }> / <p6eval> std 52fe6d2: OUTPUT«ok 00:00 43m␤» IMO only variables in double quotes should interpolate. so '$a' should be treatet as that string.
Download (untitled) / with headers
text/plain 492b
On Thu, 01 Mar 2012 13:07:28 -0800, masak wrote: Show quoted text
> <masak> nom: '' ~~ / :my $a; <{ '$a' }> / > <p6eval> nom 48af8c: OUTPUT«===SORRY!===␤Variable $a is not > declared␤at eval_0:1␤»
This works fine now - and has so for a while¹, apparently since a commit² in May 2015: say '123' ~~ / :my $a=2; <{ '$a' }> /, # '2' --- [1] https://gist.github.com/Whateverable/1df76358c7486886538f9ead60b13d1f [2] https://github.com/rakudo/rakudo/commit/f0e142b3a24e60f4bdde145286d508b916f3ecde
Download (untitled) / with headers
text/plain 1.2k
On Sun, 03 Mar 2013 10:47:32 -0800, FROGGS.de wrote: Show quoted text
> There are weird things goind on: > > good: > <FROGGS> r: '' ~~ / :my $a; <{ '$a' }> / > <p6eval> rakudo 123dfa: ( no output ) > > good: > <FROGGS> r: say '' ~~ / :my $a; <{ '$a' }> / > <p6eval> rakudo 123dfa: OUTPUT«#<failed match>␤» > > weird: > <FROGGS> r: say '123' ~~ / :my $a=2; <{ '$a' }> / > <p6eval> rakudo 123dfa: OUTPUT«「1」␤␤» > > good: > <FROGGS> r: say '123' ~~ / :my $a=2; <{ "$a" }> / > <p6eval> rakudo 123dfa: OUTPUT«「2」␤␤» > > weird: > <FROGGS> r: say '$a' ~~ / :my $a=2; <{ '$a' }> / > <p6eval> rakudo 123dfa: OUTPUT«#<failed match>␤» > > good: > <FROGGS> std: say '$a' ~~ / <{ '$a' }> / > <p6eval> std 52fe6d2: OUTPUT«ok 00:00 43m␤» > > IMO only variables in double quotes should interpolate. so '$a' should > be treatet as that string.
As per the other reply, first { '$a' } produces the string $a, then that string is interpreted as a regex which contains a variable lookup, and the lexical lookup for $a is expected too work, so the second "weird" example is functioning as intended. Tests, including making sure $a is not expanded before the closure returns, were added in roast commit 1bbe3c9d3, so resolving this ticket.


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