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

Chap. 6.4 substr example doesn't work #73

Open
muixirt opened this issue Jul 24, 2012 · 2 comments
Open

Chap. 6.4 substr example doesn't work #73

muixirt opened this issue Jul 24, 2012 · 2 comments
Labels

Comments

@muixirt
Copy link

muixirt commented Jul 24, 2012

When I try it:
$ perl6 -e 'my $p = "perl 5"; substr($p, 6, 1, '6'); say $p'
Too many positional parameters passed; got 4 but expected between 2 and 3
in sub substr at src/gen/CORE.setting:2034
in block at -e:1

Even in Perl 5 it doesn't work as expected :-)
$ perl -E 'my $p = "perl 5"; substr($p, 6, 1, '6'); say $p'
perl 56

@molecules
Copy link
Contributor

Did you mean this for the Perl 5 equivalent?

perl -E 'my $p="perl5";substr($p,4,1,'6');say $p'

-----Original Message-----
From: Klaus Brüssel [mailto:[email protected]]
Sent: Tuesday, July 24, 2012 10:29 AM
To: Christopher Bottoms
Subject: [book] Chap. 6.4 substr example doesn't work (#73)

When I try it:
$ perl6 -e 'my $p = "perl 5"; substr($p, 6, 1, '6'); say $p'
Too many positional parameters passed; got 4 but expected between 2 and 3
in sub substr at src/gen/CORE.setting:2034
in block at -e:1

Even in Perl 5 it doesn't work as expected :-) $ perl -E 'my $p = "perl 5"; substr($p, 6, 1, '6'); say $p'
perl 56


Reply to this email directly or view it on GitHub:
#73

@gdey
Copy link
Contributor

gdey commented Oct 30, 2012

I verified this.

I believe that the index starts at 0 not at 1, so the count should be 5, and not six. It seems that niecza correctly implements both, but rakudo only implements the 3 param version. Also, it seems that rakudo done not implement the lvalue version of the substr, and instead the spec has been changed to include substr-rw, which is the lvalue version of substr.

The section of the book should talk about these differences, or at least point to another part of the book that goes into detail.

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

No branches or pull requests

3 participants