FAQ
# New Ticket Created by Zachary Bornheimer
# Please include the string: [perl #116026]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=116026 >


Currently, 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
reversing strings and also the Str method and fixes this problem

## Z. Bornheimer

Search Discussions

  • Zachary Bornheimer at Dec 8, 2012 at 5:34 pm
    I'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
    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


    ================Patch End============================


    ## Z. Bornheimer


    On Sat, Dec 8, 2012 at 12:32 PM, perl6 via RT
    wrote:
    Greetings,

    This message has been automatically generated in response to the
    creation of a trouble ticket regarding:
    "[PATCH] Added functionality for strings to be reversed like
    lists",
    a summary of which appears below.

    There is no need to reply to this message right now. Your ticket has been
    assigned an ID of [perl #116026].

    Please include the string:

    [perl #116026]

    in the subject line of all future correspondence about this issue. To do
    so,
    you may reply to this message.

    Thank you,
    perl6-bugs-followup@perl.org

    -------------------------------------------------------------------------
    Currently, 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
    reversing strings and also the Str method and fixes this problem

    ## Z. Bornheimer

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl6-compiler @
categoriesperl
postedDec 8, '12 at 5:32p
activeDec 8, '12 at 5:34p
posts2
users2
websiteperl6.org

People

Translate

site design / logo © 2018 Grokbase