This repository has been archived by the owner on Feb 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
565 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/perl | ||
# Copyright (C) 2008, The Perl Foundation. | ||
# $Id$ | ||
|
||
use strict; | ||
use warnings; | ||
|
||
my @files = @ARGV; | ||
|
||
print <<"END_SETTING"; | ||
|
||
# This file automatically generated by $0. | ||
|
||
END_SETTING | ||
|
||
my %classnames; | ||
foreach my $file (@files) { | ||
print "# From $file\n\n"; | ||
open(my $fh, "<", $file) or die $!; | ||
local $/; | ||
my $x = <$fh>; | ||
close $fh; | ||
print $x; | ||
} | ||
|
||
print "\n# vim: set ft=perl6 nomodifiable :\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
=begin | ||
|
||
=head2 Array Methods | ||
These methods extend the native NQP Array class to support more of the basic | ||
functionality expected for Perl 6 Hashes. | ||
|
||
=end | ||
|
||
module ResizablePMCArray { | ||
|
||
|
||
=begin | ||
|
||
=over 4 | ||
=item @reversed := @array.reverse | ||
Return a C<@reversed> copy of the C<@array>. | ||
|
||
=end | ||
|
||
method reverse () { | ||
my @reversed; | ||
for self { @reversed.unshift($_); } | ||
@reversed; | ||
} | ||
|
||
=begin | ||
|
||
=item $string := @array.join($join_string) | ||
Join C<@array> using C<$join_string> | ||
|
||
=end | ||
|
||
method join ($join_string) { | ||
return Q:PIR{ | ||
$P0 = find_lex '$join_string' | ||
$S0 = $P0 | ||
$S1 = join $S0, self | ||
%r = box $S1 | ||
} | ||
} | ||
=begin | ||
=back | ||
=end | ||
} | ||
sub join($join_string, *@list) { @list.join($join_string) } | ||
sub list(*@list) { @list }; | ||
# vim: ft=perl6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#! nqp | ||
|
||
=begin | ||
|
||
=head2 Basic Functions | ||
These functions provide basic functionality that would be part of the standard | ||
setting in Perl 6, but are not provided with NQP by default. | ||
|
||
=over 4 | ||
=item @mapped := map(&code, @originals) | ||
Pretty much as you would expect, except there is no flattening or other | ||
coersion, due to the current semantics of NQP. This means that every | ||
application of C<&code> to an item in the C<@originals> produces exactly | ||
one entry in the C<@mapped> output. | ||
|
||
=end | ||
|
||
sub map (&code, @originals) { | ||
my @mapped; | ||
|
||
for @originals { | ||
@mapped.push(&code($_)); | ||
} | ||
|
||
return @mapped; | ||
} | ||
|
||
|
||
=begin | ||
|
||
=item @matches := grep(&code, @all) | ||
Select all members of C<@all> for which C<&code($member)> returns true. | ||
Order is retained, and duplicates are handled independently. | ||
|
||
=end | ||
|
||
sub grep (&code, @all) { | ||
my @matches; | ||
|
||
for @all { | ||
@matches.push($_) if &code($_); | ||
} | ||
|
||
return @matches; | ||
} | ||
|
||
|
||
=begin | ||
|
||
=item $result := reduce(&code, @array, $initial?) | ||
Loop over the C<@array>, applying the binary function C<&code> to the current | ||
C<$result> and next element of the C<@array>, each time saving the return | ||
value of the C<&code> as the new C<$result>. When all elements of the array | ||
have been processed, the last C<$result> computed is returned. | ||
|
||
If an C<$initial> value is supplied, it is used as the starting value for | ||
C<$result> when iterating over the C<@array>. This automatically works with | ||
any length C<@array>, even an empty one. | ||
|
||
Without an C<$initial> value, C<reduce()> applies the C<&code> to the first two | ||
elements in the C<@array> to determine the inital C<$result> (and skips these | ||
first two elements when looping). If the C<@array> has only one element, it | ||
is returned directly as the final C<$result>. If the C<@array> is empty, the | ||
C<$result> is an undefined value. | ||
|
||
=end | ||
|
||
sub reduce (&code, @array, *@initial) { | ||
my $init_elems := pir::elements(@initial); | ||
if $init_elems > 1 { | ||
pir::die('Only one initial value allowed in reduce()'); | ||
} | ||
elsif $init_elems == 1 { | ||
return _reduce(&code, @array, @initial[0]); | ||
} | ||
else { | ||
my $array_elems := pir::elements(@array); | ||
if $array_elems == 0 { | ||
return my $undef; | ||
} | ||
elsif $array_elems == 1 { | ||
return @array[0]; | ||
} | ||
else { | ||
my $initial := &code(@array[0], @array[1]); | ||
my $iter := pir::iter__PP(@array); | ||
|
||
pir::shift($iter); | ||
pir::shift($iter); | ||
|
||
return _reduce(&code, $iter, $initial); | ||
} | ||
} | ||
} | ||
|
||
sub _reduce(&code, $iter, $initial) { | ||
my $result := $initial; | ||
|
||
for $iter { | ||
$result := &code($result, $_); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
# vim: ft=perl6 |
Oops, something went wrong.