New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
s{} mismatch on numeric #3645
Comments
From @Tux$ perl6 -e'$_ = 0; s{^(\d+)$} = sprintf "%3d -", $_' -- |
From @usev6AFAIU this error happens because s/// is implemented in terms of .subst-mutate (see commit rakudo/rakudo@5a06ace5c5) and .subst-mutate currently only works for Str. $ perl6 -e 'my $a = 43; $a.subst-mutate(3,2); say $a' $ perl6 -e 'my $a = "43"; $a.subst-mutate(3,2); say $a' I'm not sure if .subst-mutate is supposed to work with other types than Str -- and in case it is I don't know what should happen to the type of $a when .subst-mutate is applied. I played a bit and (naively) added a version of .subst-mutate (only locally, not in Rakudo) which accepts input of type Numeric, which is transformed to Str: https://gist.github.com/usev6/19baafe3390a274d87d0 But that approach looks a bit murky to me (e.g. calling .subst-mutate on a variable holding a Rat like 2/5). And what about Arrays or other types? Please note that it is possible to call .subst on an Array: $ perl6 -e 'my @a = <43 21 7>; say @a.subst(3,2)' Christian |
1 similar comment
From @usev6AFAIU this error happens because s/// is implemented in terms of .subst-mutate (see commit rakudo/rakudo@5a06ace5c5) and .subst-mutate currently only works for Str. $ perl6 -e 'my $a = 43; $a.subst-mutate(3,2); say $a' $ perl6 -e 'my $a = "43"; $a.subst-mutate(3,2); say $a' I'm not sure if .subst-mutate is supposed to work with other types than Str -- and in case it is I don't know what should happen to the type of $a when .subst-mutate is applied. I played a bit and (naively) added a version of .subst-mutate (only locally, not in Rakudo) which accepts input of type Numeric, which is transformed to Str: https://gist.github.com/usev6/19baafe3390a274d87d0 But that approach looks a bit murky to me (e.g. calling .subst-mutate on a variable holding a Rat like 2/5). And what about Arrays or other types? Please note that it is possible to call .subst on an Array: $ perl6 -e 'my @a = <43 21 7>; say @a.subst(3,2)' Christian |
@usev6 - Status changed from 'new' to 'open' |
From @usev6s{} can now be used with numeric input: $ perl6 -e '$_ = 0; s{^(\d+)$} = sprintf "%3d -", $_; say $_' I added a test to S05-substitution/subst.t with commit Raku/roast@15e0300059. I'm closing this ticket as 'resolved'. |
@usev6 - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#123597 (status was 'resolved')
Searchable as RT123597$
The text was updated successfully, but these errors were encountered: