Closed p6rt closed 15 years ago
Hello,
Here is the p5chop patch that makes our tests pass the first 4 tests. To test it, please use the following command:
./perl6 t/spec/S29-str/p5chop.t 2>&1 | head
Thanks, Ahmad Zawawi
--- 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 p5chop chars index lc lcfirst rindex ord substr uc ucfirst', 'from'=>$P0) .end
@@ -79,7 +79,29 @@ .return ($I0) .end
+=item p5chop + + our Char multi P5emul::Str::p5chop ( Str $string is rw ) + our Char multi P5emul::Str::p5chop ( Str *@strings = ($+_) is rw ) + + Trims the last character from C\<$string>, and returns it. Called with a + list, it chops each item in turn, and returns the last character + chopped.
+=cut + +.sub 'p5chop' :method :multi(_) + .local string tmps + .local string lastchar + + tmps = self + substr lastchar, tmps, -1 + chopn tmps, 1 + self = tmps + + .return(lastchar) +.end + =item chop
our Str method Str::chop ( Str $string: )
Attaching the patch file
@azawawi - Status changed from 'new' to 'open'
Attached is the implementation of p5chop for any-list.pir
Together they make t/spec/S29-str/p5chop.t succeed with all of its tests. Although i think that p5chop.t can be enhanced.
./ahmad &
Please use the latest any-list.pir patch. It works perfectly. No need for the previous patch.
On Wed Oct 08 14:03:03 2008, ahmadz wrote:
Attached is the implementation of p5chop for any-list.pir
Together they make t/spec/S29-str/p5chop.t succeed with all of its tests. Although i think that p5chop.t can be enhanced.
./ahmad &
First of all thanks for the patch.
As mentioned on IRC I'm not too happy with applying these patches until Patrick (or somebody else) has sorted out the container/value and assignment/binding issues.
Here's why:
$ perl -wle 'chop "xy"' Can't modify constant item in chop at -e line 1, at EOF Execution of -e aborted due to compilation errors. $ # with your patch: $ ../../parrot perl6.pbc -e 'say "abc".p5chop' c $ ../../parrot perl6.pbc -e 'my $x = "abc"; my $y = $x; say $x.p5chop; say $x; say $y' c ab ab
In Perl 6 a string is immutable. The way that string modifying functions work is that they get hold of a the variable that holds the string, create a modified copy of the string, and store that into the variable.
So this patch is basically cheating by modifying an object that should be immutable. That might be a valid optimization, but only if we can ensure that it never leaks to the user land.
Which is why I'll wait with applying these patches until the assignment and binding issues are sorted out. If they (magically) continue to work, and don't erroneously modify copies of the string I'll apply them.
I apologize for not being clearer on these issues before.
Moritz
I'm going to go ahead and mark this ticket as "resolved" for now -- things have changed quite a bit since it was submitted.
I invite new implementations of p5chop and p5chomp, especially if they can be done as methods in the setting (possibly using inline PIR).
Thanks!
Pm
@pmichaud - Status changed from 'open' to 'resolved'
Migrated from rt.perl.org#59552 (status was 'resolved')
Searchable as RT59552$