Skip to content
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

Closed
p6rt opened this issue Jan 14, 2015 · 6 comments
Closed

s{} mismatch on numeric #3645

p6rt opened this issue Jan 14, 2015 · 6 comments

Comments

@p6rt
Copy link

p6rt commented Jan 14, 2015

Migrated from rt.perl.org#123597 (status was 'resolved')

Searchable as RT123597$

@p6rt
Copy link
Author

p6rt commented Jan 14, 2015

From @Tux

$ perl6 -e'$_ = 0; s{^(\d+)$} = sprintf "%3d -", $_'
Cannot call 'subst-mutate'; none of these signatures match​:
  in method subst-mutate at src/gen/m-CORE.setting​:4177
  in block <unit> at -e​:1

--
H.Merijn Brand http://tux.nl Perl Monger http://amsterdam.pm.org/
using perl5.00307 .. 5.21 porting perl5 on HP-UX, AIX, and openSUSE
http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/
http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/

@p6rt
Copy link
Author

p6rt commented Feb 3, 2015

From @usev6

AFAIU 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'
Cannot call 'subst-mutate'; none of these signatures match​:
  in method subst-mutate at src/gen/m-CORE.setting​:4669
  in block <unit> at -e​:1

$ perl6 -e 'my $a = "43"; $a.subst-mutate(3,2); say $a'
42

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)'
42 21 7

Christian

1 similar comment
@p6rt
Copy link
Author

p6rt commented Feb 3, 2015

From @usev6

AFAIU 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'
Cannot call 'subst-mutate'; none of these signatures match​:
  in method subst-mutate at src/gen/m-CORE.setting​:4669
  in block <unit> at -e​:1

$ perl6 -e 'my $a = "43"; $a.subst-mutate(3,2); say $a'
42

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)'
42 21 7

Christian

@p6rt
Copy link
Author

p6rt commented Feb 3, 2015

@usev6 - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Apr 7, 2015

From @usev6

s{} can now be used with numeric input​:

$ perl6 -e '$_ = 0; s{^(\d+)$} = sprintf "%3d -", $_; say $_'
  0 -

I added a test to S05-substitution/subst.t with commit Raku/roast@15e0300059.

I'm closing this ticket as 'resolved'.

@p6rt p6rt closed this as completed Apr 7, 2015
@p6rt
Copy link
Author

p6rt commented Apr 7, 2015

@usev6 - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant