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
Added functionality for strings to be reversed like lists #2994
Comments
From z@chary.meCurrently, Perl6 is lacking the built-in functionality of running 'this is a string'.reverse or reverse 'this is a string' and getting the desired result. With this patch, I have added the sub for ## Z. Bornheimer |
From z@chary.me0002-Added-the-functionality-to-reverse-strings-with-a-re.patchFrom a159724ab2125ba9f61534ae2d6de3c1b98485ce Mon Sep 17 00:00:00 2001
From: Z. Bornheimer <z@chary.me>
Date: Sat, 8 Dec 2012 11:47:26 -0500
Subject: [PATCH 2/2] Added the functionality to reverse strings with a reverse method or reverse sub
---
src/core/List.pm | 4 +++-
src/core/Str.pm | 5 +++++
2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/src/core/List.pm b/src/core/List.pm
index b89b3d2..6f35347 100644
--- a/src/core/List.pm
+++ b/src/core/List.pm
@@ -7,6 +7,7 @@ my class List does Positional {
method new(|) {
my Mu $args := pir::perl6_current_args_rpa__P();
+ say $args.perl;
nqp::shift($args);
nqp::p6list($args, self.WHAT, Mu);
}
@@ -411,7 +412,8 @@ multi sub unshift(\a, *@elems) { a.unshift: @elems }
proto sub push(|) {*}
multi sub push(\a, *@elems) { a.push: @elems }
-sub reverse(*@a) { @a.reverse }
+multi sub reverse(*@a) { @a.reverse }
+multi sub reverse(*$a) { return $a.split('').reverse.join('') }
sub rotate(@a, Int $n = 1) { @a.rotate($n) }
sub reduce (&with, *@list) { @list.reduce(&with) }
sub categorize(&mapper, *@a){ @a.categorize(&mapper)}
diff --git a/src/core/Str.pm b/src/core/Str.pm
index 279e278..5042008 100644
--- a/src/core/Str.pm
+++ b/src/core/Str.pm
@@ -68,6 +68,11 @@ my class Str does Stringy {
nqp::p6box_s(pir::chopn__Ssi(nqp::unbox_s(self), 1))
}
+ method reverse(Str:D:) {
+ my $var = self.split('').reverse.join('');
+ $var;
+ }
+
method substr(Str:D: $start, $length? is copy) {
my str $sself = nqp::unbox_s(self);
my int $istart = nqp::unbox_i(
--
1.7.1
|
From z@chary.meI'm not sure my patch was received, so here it is in the body of this email: ================Patch Start============================ From a159724ab2125ba9f61534ae2d6de3c1b98485ce Mon Sep 17 00:00:00 2001 src/core/List.pm | 4 +++- Inline Patchdiff --git a/src/core/List.pm b/src/core/List.pm
index b89b3d2..6f35347 100644
--- a/src/core/List.pm
+++ b/src/core/List.pm
@@ -7,6 +7,7 @@ my class List does Positional {
method new(|) {
my Mu $args := pir::perl6_current_args_rpa__P();
+ say $args.perl;
nqp::shift($args);
nqp::p6list($args, self.WHAT, Mu);
}
@@ -411,7 +412,8 @@ multi sub unshift(\a, *@elems) { a.unshift: @elems }
proto sub push(|) {*}
multi sub push(\a, *@elems) { a.push: @elems }
-sub reverse(*@a) { @a.reverse }
+multi sub reverse(*@a) { @a.reverse }
+multi sub reverse(*$a) { return $a.split('').reverse.join('') }
sub rotate(@a, Int $n = 1) { @a.rotate($n) }
sub reduce (&with, *@list) { @list.reduce(&with) }
sub categorize(&mapper, *@a){ @a.categorize(&mapper)}
diff --git a/src/core/Str.pm b/src/core/Str.pm
index 279e278..5042008 100644
--- a/src/core/Str.pm
+++ b/src/core/Str.pm
@@ -68,6 +68,11 @@ my class Str does Stringy {
nqp::p6box_s(pir::chopn__Ssi(nqp::unbox_s(self), 1))
}
+ method reverse(Str:D:) {
+ my $var = self.split('').reverse.join('');
+ $var;
+ }
+
method substr(Str:D: $start, $length? is copy) {
my str $sself = nqp::unbox_s(self);
my int $istart = nqp::unbox_i(
--
================Patch End============================ ## Z. Bornheimer On Sat, Dec 8, 2012 at 12:32 PM, perl6 via RT
|
From @moritzSorry, this patch is wrong. Strings are reversed with flip, not with reverse. The reason is basically that there are too many corner cases with Cheers, |
The RT System itself - Status changed from 'new' to 'open' |
@moritz - Status changed from 'open' to 'rejected' |
Migrated from rt.perl.org#116026 (status was 'rejected')
Searchable as RT116026$
The text was updated successfully, but these errors were encountered: