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

any-pir p5chomp implementation #353

Closed
p6rt opened this issue Oct 2, 2008 · 10 comments
Closed

any-pir p5chomp implementation #353

p6rt opened this issue Oct 2, 2008 · 10 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Oct 2, 2008

Migrated from rt.perl.org#59560 (status was 'rejected')

Searchable as RT59560$

@p6rt
Copy link
Author

p6rt commented Oct 2, 2008

From @azawawi

Hello,

Here is the p5chomp patch that makes the first four tests to pass.
To test it, please use the following command​:

./perl6 t/spec/S29-str/p5chomp.t 2>&1 | head

Thanks,
Ahmad Zawawi

Index​: src/builtins/any-str.pir

--- src/builtins/any-str.pir (revision 31564)
+++ src/builtins/any-str.pir (working copy)
@​@​ -21,7 +21,7 @​@​
.namespace []
.sub 'onload' :anon :init :load
  $P0 = get_hll_namespace ['Any']
- '!EXPORT'('capitalize chop chars index lc lcfirst rindex ord
substr uc ucfirst', 'from'=>$P0)
+ '!EXPORT'('capitalize chop p5chomp chars index lc lcfirst rindex
ord substr uc ucfirst', 'from'=>$P0)
.end

@​@​ -99,7 +99,33 @​@​
  .return(retv)
.end

+=item p5chomp

+ our Int multi P5emul​::Str​::p5chomp ( Str $string is rw )
+ our Int multi P5emul​::Str​::p5chomp ( Str *@​strings = ($+_) is rw )
+
+ Related to C<p5chop>, only removes trailing chars that match C</\n/>. In
+ either case, it returns the number of chars removed.
+
+=cut
+
+.sub 'p5chomp' :method :multi(_)
+ .local string tmps
+ .local string lastchar
+ .local pmc retv
+
+ tmps = self
+ retv = new 'Int'
+ retv = 0
+ lastchar = substr tmps,-1
+ if lastchar != "\n" goto done
+ chopn tmps, 1
+ self = tmps
+ retv += 1
+ done​:
+ .return(retv)
+.end
+
=item comb()

Partial implementation for now, returns a list of strings

@p6rt
Copy link
Author

p6rt commented Oct 2, 2008

From @azawawi

Attaching the patch file

@p6rt
Copy link
Author

p6rt commented Oct 2, 2008

From @azawawi

str_p5chomp.patch
Index: src/builtins/any-str.pir
===================================================================
--- src/builtins/any-str.pir    (revision 31564)
+++ src/builtins/any-str.pir    (working copy)
@@ -21,7 +21,7 @@
 .namespace []
 .sub 'onload' :anon :init :load
     $P0 = get_hll_namespace ['Any']
-    '!EXPORT'('capitalize chop chars index lc lcfirst rindex ord substr uc ucfirst', 'from'=>$P0)
+    '!EXPORT'('capitalize chop p5chomp chars index lc lcfirst rindex ord substr uc ucfirst', 'from'=>$P0)
 .end


@@ -99,7 +99,33 @@
     .return(retv)
 .end

+=item p5chomp

+  our Int multi P5emul::Str::p5chomp ( Str  $string is rw )
+  our Int multi P5emul::Str::p5chomp ( Str *@strings = ($+_) is rw )
+
+  Related to C<p5chop>, only removes trailing chars that match C</\n/>. In
+  either case, it returns the number of chars removed.
+
+=cut
+
+.sub 'p5chomp' :method :multi(_)
+    .local string tmps
+    .local string lastchar
+    .local pmc retv
+
+    tmps = self
+    retv = new 'Int'
+    retv = 0
+    lastchar = substr tmps,-1
+    if lastchar != "\n" goto done
+    chopn tmps, 1
+    self = tmps
+    retv += 1
+  done:
+    .return(retv)
+.end
+
 =item comb()

 Partial implementation for now, returns a list of strings

@p6rt
Copy link
Author

p6rt commented Oct 2, 2008

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

@p6rt
Copy link
Author

p6rt commented Oct 8, 2008

From @azawawi

any-list.pir implementation. All p5chomp.t run ok (finally ;-)

./ahmad &

@p6rt
Copy link
Author

p6rt commented Oct 8, 2008

From @azawawi

p5chomp_list.patch
Index: src/builtins/any-list.pir
===================================================================
--- src/builtins/any-list.pir   (revision 31798)
+++ src/builtins/any-list.pir   (working copy)
@@ -21,7 +21,7 @@
 .namespace ['Any']
 .sub 'onload' :anon :init :load
     $P0 = get_hll_namespace ['Any']
-    '!EXPORT'('abs', 'from'=>$P0)
+    '!EXPORT'('abs p5chomp', 'from'=>$P0)
 .end


@@ -43,7 +43,33 @@
     .return ($I0)
 .end

+=item p5chomp

+=cut
+.namespace ['Any']
+.sub 'p5chomp' :method :multi(_)
+    .local string tmps
+    .local pmc it
+
+    $P0 = self.'list'()
+    it = $P0.'iterator'()
+    $N0 = 0
+  loop:
+    unless it goto done
+    $P0 = shift it
+    tmps = $P0
+    $S0 = substr tmps,-1
+    if $S0 != "\n" goto loop
+    chopn tmps, 1
+    $P0 = tmps
+    $N0 += 1
+    goto loop
+  done:
+    $P0 = new 'Int'
+    $P0 = $N0
+    .return($P0)
+.end
+
 =item join

 =cut

@p6rt
Copy link
Author

p6rt commented Oct 8, 2008

From @azawawi

Please use the latest any-list.pir patch. It works perfectly.

On Wed Oct 08 14​:50​:33 2008, ahmadz wrote​:

any-list.pir implementation. All p5chomp.t run ok (finally ;-)

./ahmad &

@p6rt
Copy link
Author

p6rt commented Nov 8, 2008

From @bacek

On Wed Oct 08 14​:55​:25 2008, ahmadz wrote​:

Please use the latest any-list.pir patch. It works perfectly.

On Wed Oct 08 14​:50​:33 2008, ahmadz wrote​:

any-list.pir implementation. All p5chomp.t run ok (finally ;-)

./ahmad &

One note. It should be $I0 instead of $N0. $In registers are integers,
$Nn - floats.

--
Bacek

@p6rt
Copy link
Author

p6rt commented Mar 29, 2009

From @moritz

We now have a Perl 6 version of p5chomp in Rakudo (which wasn't possible
at the time this patch was written), which is preferable over a PIR
implementation; so rejecting this patch.

Anyway, thanks for your contribution.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Mar 29, 2009

@moritz - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed Mar 29, 2009
@p6rt p6rt added the patch label Jan 5, 2020
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

1 participant