From 173285096d597780e615476c8ca996305d4a887f Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Sat, 31 Oct 2015 19:35:04 +0100 Subject: [PATCH 01/20] Mainly fixing problems with Perl heuristics And also adding a little bit of text to the README file to help with local use and test. --- README.md | 39 +++++++++++++++++++++++++++++++++++++- lib/linguist/heuristics.rb | 4 ++-- lib/linguist/languages.yml | 4 ++++ samples/Perl/Makefile.PL | 20 +++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 samples/Perl/Makefile.PL diff --git a/README.md b/README.md index 33b976d295..744e65675a 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,44 @@ This library is used on GitHub.com to detect blob languages, ignore binary or vendored files, suppress generated files in diffs, and generate language breakdown graphs. -See [Troubleshooting](#troubleshooting) and [`CONTRIBUTING.md`](/CONTRIBUTING.md) before filing an issue or creating a pull request. +See [Troubleshooting](#troubleshooting) and +[`CONTRIBUTING.md`](/CONTRIBUTING.md) before filing an issue or +creating a pull request. + +## Install + +You might want to install this very version from GitHub or to test +your local changes locally. You will need to install some +prerrequisite libraries first. Run: + + sudo apt-get install cmake + +which is required to install `rugged` + +Then + + bundle install + +to install all dependencies and finally + + rake samples + +to generate `samples.json` file, which is needed for checking out +samples. Then you can simply run + + bundle exec linguist --breakdown + +to check the languages on the repository itself, or + + bundle exec git-linguist --commit=362d300cb021f11fe1c66f69b7f1bb0c246f01b0 breakdown + +to get a breakdown in JSON format of an specific commit. + +Try it too in some other directory, for instance: + + bundle exec linguist ../../CPAN/Algorithm-Evolutionary + + ## Troubleshooting diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 11f58b2809..85c4db7a99 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -274,7 +274,7 @@ def call(data) end disambiguate ".pl" do |data| - if /^(use v6|(my )?class|module)/.match(data) + if /^(use v6|(my)? class|module)/.match(data) #class might be a variable name in Perl 5 Language["Perl6"] elsif /use strict|use\s+v?5\./.match(data) Language["Perl"] @@ -284,7 +284,7 @@ def call(data) end disambiguate ".pm", ".t" do |data| - if /^(use v6|(my )?class|module)/.match(data) + if /^(use v6|(my)? class|module)/.match(data) Language["Perl6"] elsif /use strict|use\s+v?5\./.match(data) Language["Perl"] diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 0558ecdc78..7caea51a68 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -2580,6 +2580,10 @@ Perl: - .pod - .psgi - .t + filenames: + - Rexfile + - Makefile.PL + - cpanfile interpreters: - perl diff --git a/samples/Perl/Makefile.PL b/samples/Perl/Makefile.PL new file mode 100644 index 0000000000..0492ba5ffd --- /dev/null +++ b/samples/Perl/Makefile.PL @@ -0,0 +1,20 @@ +use strict; +use warnings; +use ExtUtils::MakeMaker; + +WriteMakefile( + NAME => 'Algorithm::Evolutionary::Simple', + AUTHOR => 'JJ Merelo ', + VERSION_FROM => 'lib/Algorithm/Evolutionary/Simple.pm', + ABSTRACT_FROM => 'lib/Algorithm/Evolutionary/Simple.pm', + LICENSE => 'gpl', + EXE_FILES => [ 'script/simple-EA.pl', 'script/maxones.pl'], + PREREQ_PM => { + 'Test::More' => 0, + 'Carp' => 0, + 'Exporter' => 0, + 'Sort::Key::Top' => 0 + }, + dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, + clean => { FILES => 'Algorithm-Evolutionary-Simple-*' }, +); From 9d57d6f218015d9ea8f62b1abbb240ea05031cd2 Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Sun, 1 Nov 2015 18:30:30 +0100 Subject: [PATCH 02/20] Adds new sample --- samples/Perl/Any.pm | 100 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 samples/Perl/Any.pm diff --git a/samples/Perl/Any.pm b/samples/Perl/Any.pm new file mode 100644 index 0000000000..6c53e12c60 --- /dev/null +++ b/samples/Perl/Any.pm @@ -0,0 +1,100 @@ +use strict; #-*-cperl-*- +use warnings; + +use lib qw( ../../../../lib ); + +=encoding utf8 + +=head1 NAME + +Algorithm::Evolutionary::Fitness::Any - Façade for any function so that it can be used as fitness + +=head1 SYNOPSIS + + use Algorithm::Evolutionary::Utils qw( string_decode ) + + sub squares { + my $chrom = shift; + my @values = string_decode( $chrom, 10, -1, 1 ); + return $values[0] * $values[1]; + } + + my $any_eval = new Algorithm::Evolutionary::Fitness::Any \&squares; + + +=head1 DESCRIPTION + +Turns any subroutine or closure into a fitness function. Useful mainly +if you want results cached; it's not really needed otherwise. + +=head1 METHODS + +=cut + +package Algorithm::Evolutionary::Fitness::Any; + +use Carp; + +use base 'Algorithm::Evolutionary::Fitness::Base'; + +our $VERSION = '3.2'; + +=head2 new( $function ) + +Assigns default variables + +=cut + +sub new { + my $class = shift; + my $self = { _function => shift || croak "No functiona rray" }; + bless $self, $class; + $self->initialize(); + return $self; +} + +=head2 apply( $individual ) + +Applies the instantiated problem to a chromosome. It is actually a +wrapper around C<_apply>. + +=cut + +sub apply { + my $self = shift; + my $individual = shift || croak "Nobody here!!!"; + $self->{'_counter'}++; + return $self->_apply( $individual ); +} + +=head2 _apply( $individual ) + +This is the one that really does the stuff. It applies the defined +function to each individual. Itis cached for efficiency. + +=cut + +sub _apply { + my $self = shift; + my $individual = shift || croak "Nobody here!"; + my $chrom = $individual->Chrom(); + my $cache = $self->{'_cache'}; + if ( $cache->{$chrom} ) { + return $cache->{$chrom}; + } + my $result = $self->{'_function'}->($chrom); + if ( (scalar $chrom ) eq $chrom ) { + $cache->{$chrom} = $result; + } + return $result; +} + + +=head1 Copyright + + This file is released under the GPL. See the LICENSE file included in this distribution, + or go to http://www.fsf.org/licenses/gpl.txt + +=cut + +"What???"; From 13d5ebd170e2d4b11926d877525026556c2d1583 Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Sun, 1 Nov 2015 18:36:45 +0100 Subject: [PATCH 03/20] Adds a couple of samples more, not represented before --- samples/Perl/Rexfile | 9 +++++++++ samples/Perl/cpanfile | 5 +++++ 2 files changed, 14 insertions(+) create mode 100644 samples/Perl/Rexfile create mode 100644 samples/Perl/cpanfile diff --git a/samples/Perl/Rexfile b/samples/Perl/Rexfile new file mode 100644 index 0000000000..a88b48a7e9 --- /dev/null +++ b/samples/Perl/Rexfile @@ -0,0 +1,9 @@ +use Rex -feature => ['1.0']; + +user "eleccionesugr"; +group eleccionesugr => "elecciones-ugr.cloudapp.net"; + +desc "Install perlbrew"; +task "perlbrew", group => "eleccionesugr", sub { +}; + diff --git a/samples/Perl/cpanfile b/samples/Perl/cpanfile new file mode 100644 index 0000000000..72d9953a5b --- /dev/null +++ b/samples/Perl/cpanfile @@ -0,0 +1,5 @@ +requires 'Test::More'; +requires 'version'; +requires 'Mojo::DOM'; +requires 'Mojo::UserAgent'; +requires 'Moose'; \ No newline at end of file From d3cf280f1315ec93227b73bcc372ddf4a191a51d Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Mon, 2 Nov 2015 08:11:10 +0100 Subject: [PATCH 04/20] Moves installation intructions to CONTRIBUTING.md Refs #2309 and also changes github.com to an uniform capitalization. --- CONTRIBUTING.md | 37 ++++++++++++++++++++++++++++++++++++- README.md | 39 ++------------------------------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 56ef275fd8..7ac1538d65 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,7 +4,42 @@ Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great. This project adheres to the [Open Code of Conduct][code-of-conduct]. By participating, you are expected to uphold this code. -The majority of contributions won't need to touch any Ruby code at all. +The majority of contributions won't need to touch any Ruby code at +all. + +## Installation how to + +You might want to get Linguist running in order to test locally whatever +changes you might be doing to it. You will need to install some +prerrequisite libraries first. Run: + + sudo apt-get install cmake + +which is required to install `rugged` + +Then + + bundle install + +to install all dependencies and finally + + rake samples + +to generate `samples.json` file, which is needed for checking out +samples. Then you can simply run + + bundle exec linguist --breakdown + +to check the languages on the repository itself, or + + bundle exec git-linguist --commit=362d300cb021f11fe1c66f69b7f1bb0c246f01b0 breakdown + +to get a breakdown in JSON format of an specific commit. + +Try it too in some other directory, for instance: + + bundle exec linguist ../../CPAN/Algorithm-Evolutionary + ## Adding an extension to a language diff --git a/README.md b/README.md index 744e65675a..c16d37a9a4 100644 --- a/README.md +++ b/README.md @@ -3,47 +3,12 @@ [issues]: https://github.com/github/linguist/issues [new-issue]: https://github.com/github/linguist/issues/new -This library is used on GitHub.com to detect blob languages, ignore binary or vendored files, suppress generated files in diffs, and generate language breakdown graphs. +This library is used on github.com to detect blob languages, ignore binary or vendored files, suppress generated files in diffs, and generate language breakdown graphs. See [Troubleshooting](#troubleshooting) and [`CONTRIBUTING.md`](/CONTRIBUTING.md) before filing an issue or creating a pull request. -## Install - -You might want to install this very version from GitHub or to test -your local changes locally. You will need to install some -prerrequisite libraries first. Run: - - sudo apt-get install cmake - -which is required to install `rugged` - -Then - - bundle install - -to install all dependencies and finally - - rake samples - -to generate `samples.json` file, which is needed for checking out -samples. Then you can simply run - - bundle exec linguist --breakdown - -to check the languages on the repository itself, or - - bundle exec git-linguist --commit=362d300cb021f11fe1c66f69b7f1bb0c246f01b0 breakdown - -to get a breakdown in JSON format of an specific commit. - -Try it too in some other directory, for instance: - - bundle exec linguist ../../CPAN/Algorithm-Evolutionary - - - ## Troubleshooting ### My repository is detected as the wrong language @@ -92,7 +57,7 @@ docs/formatter.rb linguist-documentation=false ### Using Emacs or Vim modelines -Alternatively, you can use Vim or Emacs style modelines to set the language for a single file. Modelines can be placed anywhere within a file and are respected when determining how to syntax-highlight a file on GitHub.com +Alternatively, you can use Vim or Emacs style modelines to set the language for a single file. Modelines can be placed anywhere within a file and are respected when determining how to syntax-highlight a file on github.com ##### Vim ``` From f437f0cf1b2496c82483b1a71c9d4b00d69f96d9 Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Mon, 2 Nov 2015 11:50:19 +0100 Subject: [PATCH 05/20] Correcting error. Great job, CI --- lib/linguist/languages.yml | 4 +--- samples/Perl/{ => filenames}/Rexfile | 0 samples/Perl/{ => filenames}/cpanfile | 0 3 files changed, 1 insertion(+), 3 deletions(-) rename samples/Perl/{ => filenames}/Rexfile (100%) rename samples/Perl/{ => filenames}/cpanfile (100%) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 7caea51a68..386ce17c29 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -2581,8 +2581,8 @@ Perl: - .psgi - .t filenames: - - Rexfile - Makefile.PL + - Rexfile - cpanfile interpreters: - perl @@ -2602,8 +2602,6 @@ Perl6: - .pm - .pm6 - .t - filenames: - - Rexfile interpreters: - perl6 tm_scope: source.perl.6 diff --git a/samples/Perl/Rexfile b/samples/Perl/filenames/Rexfile similarity index 100% rename from samples/Perl/Rexfile rename to samples/Perl/filenames/Rexfile diff --git a/samples/Perl/cpanfile b/samples/Perl/filenames/cpanfile similarity index 100% rename from samples/Perl/cpanfile rename to samples/Perl/filenames/cpanfile From 2d8cd85ca8b419486e6ffbf0131edee544965dc1 Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Mon, 2 Nov 2015 12:01:09 +0100 Subject: [PATCH 06/20] Moving another file --- samples/Perl/{ => filenames}/Makefile.PL | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename samples/Perl/{ => filenames}/Makefile.PL (100%) diff --git a/samples/Perl/Makefile.PL b/samples/Perl/filenames/Makefile.PL similarity index 100% rename from samples/Perl/Makefile.PL rename to samples/Perl/filenames/Makefile.PL From f46e876e9ef356aa072d67563f4381c1c8a1e278 Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Sun, 13 Dec 2015 11:00:31 +0100 Subject: [PATCH 07/20] Adds samples and new checks for perl/perl6 --- CONTRIBUTING.md | 6 +++--- lib/linguist/heuristics.rb | 4 ++-- lib/linguist/languages.yml | 2 ++ samples/Perl/chromosome.pl | 9 +++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 samples/Perl/chromosome.pl diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7ac1538d65..c26365bb83 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,7 +15,7 @@ prerrequisite libraries first. Run: sudo apt-get install cmake -which is required to install `rugged` +which is required to install `rugged`. Then @@ -34,9 +34,9 @@ to check the languages on the repository itself, or bundle exec git-linguist --commit=362d300cb021f11fe1c66f69b7f1bb0c246f01b0 breakdown -to get a breakdown in JSON format of an specific commit. +to get a breakdown in JSON format for an specific commit. -Try it too in some other directory, for instance: +You can try it too in some other directory this way: bundle exec linguist ../../CPAN/Algorithm-Evolutionary diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index b0ba3ec433..9c671a126c 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -276,7 +276,7 @@ def call(data) end disambiguate ".pl" do |data| - if /^(use v6|(my)? class|module)/.match(data) #class might be a variable name in Perl 5 + if /^(use v6|(my)? class|class|module)/.match(data) #class might be a variable name in Perl 5 Language["Perl6"] elsif /use strict|use\s+v?5\./.match(data) Language["Perl"] @@ -286,7 +286,7 @@ def call(data) end disambiguate ".pm", ".t" do |data| - if /^(use v6|(my)? class|module)/.match(data) + if /^(use v6|(my)? class|class|module)/.match(data) Language["Perl6"] elsif /use strict|use\s+v?5\./.match(data) Language["Perl"] diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 8da53455b0..e3c2d05c9d 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -2604,6 +2604,8 @@ Perl: type: programming tm_scope: source.perl ace_mode: perl + aliases: + - cperl color: "#0298c3" extensions: - .pl diff --git a/samples/Perl/chromosome.pl b/samples/Perl/chromosome.pl new file mode 100644 index 0000000000..82fb719d7c --- /dev/null +++ b/samples/Perl/chromosome.pl @@ -0,0 +1,9 @@ +class Chromosome { + has Seq $.chromosome is rw; + has $.fitness is rw; + +} + +my $len = 32; +my $this-chromosome = Chromosome.new( chromosome => map( { rand >= 0.5 ?? True !! False }, 1..$len ) ); +say $this-chromosome.chromosome(); From ff4f40ae40736f27c8c6eadcd53619c9ecd87cbd Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Sun, 13 Dec 2015 11:09:09 +0100 Subject: [PATCH 08/20] Stupid mistake --- samples/{Perl => Perl6}/chromosome.pl | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename samples/{Perl => Perl6}/chromosome.pl (100%) diff --git a/samples/Perl/chromosome.pl b/samples/Perl6/chromosome.pl similarity index 100% rename from samples/Perl/chromosome.pl rename to samples/Perl6/chromosome.pl From c1796bc0a901a4e6be16cca145ffb6d0077b3e1b Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Sun, 13 Dec 2015 12:17:46 +0100 Subject: [PATCH 09/20] Changing regex for perl5 vs perl6 Initial suggestion by @pchaigno, slightly changed to eliminate false positives such as "classes" or "modules" at the beginning of a line in the =pod BTW, it would be interesting to just eliminate these areas for language detection. --- lib/linguist/heuristics.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 9c671a126c..f3ff312968 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -275,8 +275,9 @@ def call(data) end end + perl5_vs_6_re = /^\s*(use v6|(my )?class |module )/ # Suggested by Paul Chaignon disambiguate ".pl" do |data| - if /^(use v6|(my)? class|class|module)/.match(data) #class might be a variable name in Perl 5 + if perl5_vs_6_re.match(data) Language["Perl6"] elsif /use strict|use\s+v?5\./.match(data) Language["Perl"] @@ -286,7 +287,7 @@ def call(data) end disambiguate ".pm", ".t" do |data| - if /^(use v6|(my)? class|class|module)/.match(data) + if perl5_vs_6_re.match(data) Language["Perl6"] elsif /use strict|use\s+v?5\./.match(data) Language["Perl"] From 22bd2647da1710ea6efb3b9a3422fa73e498b603 Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Tue, 13 Mar 2018 07:38:17 +0100 Subject: [PATCH 10/20] Eliminates Rexfile from Perl6 And adds .pod6 --- lib/linguist/languages.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 60dfed01a2..1d36fbbc6b 100755 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -3390,9 +3390,8 @@ Perl 6: - ".pl6" - ".pm" - ".pm6" + - ".pod6" - ".t" - filenames: - - Rexfile interpreters: - perl6 aliases: From 0dca0754b04d6d8b49b4bbaf70c8144fd58bc2a1 Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Tue, 13 Mar 2018 07:43:35 +0100 Subject: [PATCH 11/20] Followup to #2709 I just found I had this sitting here, so I might as well follow instructions to fix it. --- CONTRIBUTING.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3255fc31ba..21a238205f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,11 +13,8 @@ all. You might want to get Linguist running in order to test locally whatever changes you might be doing to it. You will need to install some -prerrequisite libraries first. Run: - - sudo apt-get install cmake - -which is required to install `rugged`. +prerrequisite libraries +first. [Install CMake](https://cmake.org/install/) which is required to install `rugged`. Then From a3aed35906bb25f2cdac4bfdf698f401ad23d1ae Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Tue, 13 Mar 2018 07:53:32 +0100 Subject: [PATCH 12/20] Adds example for pod6 --- samples/Perl6/Any.pod6 | 987 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 987 insertions(+) create mode 100644 samples/Perl6/Any.pod6 diff --git a/samples/Perl6/Any.pod6 b/samples/Perl6/Any.pod6 new file mode 100644 index 0000000000..22e186124b --- /dev/null +++ b/samples/Perl6/Any.pod6 @@ -0,0 +1,987 @@ +=begin pod + +=TITLE class Any + +=SUBTITLE Thing/object + + class Any is Mu {} + +While L is the root of the Perl 6 class hierarchy, L is the class +that serves as a default base class for new classes, and as the base class for +most built-in classes. + +Since Perl 6 intentionally confuses items and single-element lists, most +methods in L are also present on class L, and coerce to +List or a list-like type. + +=head1 Methods + +=head2 method ACCEPTS + +Defined as: + + multi method ACCEPTS(Any:D: Mu $other) + +Usage: + +=begin code :lang +EXPR.ACCEPTS(EXPR); +=end code + +Returns C if C<$other === self> (i.e. it checks object identity). + +Many built-in types override this for more specific comparisons + +=head2 method any + +Defined as: + + method any(--> Junction:D) + +Interprets the invocant as a list and creates an +L-L from it. + + say so 2 == <1 2 3>.any; # OUTPUT: «True␤» + say so 5 == <1 2 3>.any; # OUTPUT: «False␤» + +=head2 method all + +Defined as: + + method all(--> Junction:D) + +Interprets the invocant as a list and creates an +L-L from it. + + say so 1 < <2 3 4>.all; # OUTPUT: «True␤» + say so 3 < <2 3 4>.all; # OUTPUT: «False␤» + +=head2 method one + +Defined as: + + method one(--> Junction:D) + +Interprets the invocant as a list and creates a +L-L from it. + + say so 1 == (1, 2, 3).one; # OUTPUT: «True␤» + say so 1 == (1, 2, 1).one; # OUTPUT: «False␤» + +=head2 method none + +Defined as: + + method none(--> Junction:D) + +Interprets the invocant as a list and creates a +L-L from it. + + say so 1 == (1, 2, 3).none; # OUTPUT: «False␤» + say so 4 == (1, 2, 3).none; # OUTPUT: «True␤» + +=head2 method list + +Defined as: + + multi method list(Any:U: -->List) + multi method list(Any:D \SELF: -->List) + + +Applies the infix L«C<,>|/routine/,» +operator to the invocant +and returns the resulting L: + + say 42.list.^name; # OUTPUT: «List␤» + say 42.list.elems; # OUTPUT: «1␤» + +=head2 method push + +Defined as: + + method push(|values --> Positional:D) + +The method push is defined for undefined invocants and allows for +autovivifying undefined to an empty L, unless the undefined value +implements L already. The argument provided will then be pushed +into the newly created Array. + + my %h; + say %h; # OUTPUT: «(Any)␤» <-- Undefined + %h.push(1); # .push on Any + say %h; # OUTPUT: «{a => [1]}␤» <-- Note the Array + +=head2 routine reverse + +Defined as: + + multi sub reverse(*@list --> Seq:D) + multi method reverse(List:D: --> Seq:D) + +Returns a L with the same elements in reverse order. + +Note that C always refers to reversing elements of a list; +to reverse the characters in a string, use L. + +Examples: + + say .reverse; # OUTPUT: «(world! hello)␤» + say reverse ^10; # OUTPUT: «(9 8 7 6 5 4 3 2 1 0)␤» + +=head2 method sort + +Defined as: + + multi method sort() + multi method sort(&custom-routine-to-use) + +Sorts iterables with L or given code object and returns a new L. +Optionally, takes a L as a positional parameter, specifying how to +sort. + +Examples: + + say .sort; # OUTPUT: «(a b c)␤» + say 'bca'.comb.sort.join; # OUTPUT: «abc␤» + say 'bca'.comb.sort({$^b cmp $^a}).join; # OUTPUT: «cba␤» + say '231'.comb.sort(&infix:«<=>»).join; # OUTPUT: «123␤» + +=head2 method map + +Defined as: + + multi method map(\SELF: █; :$label, :$item) + +C will iterate over the invocant and apply the number of positional +parameters of the code object from the invocant per call. The returned values +of the code object will become elements of the returned L. + +The C<:$label> and C<:$item> are useful only internally, since C loops +get converted to Cs. The C<:$label> takes an existing L.duckmap(-> $_ where .any { .uc }).say; + # OUTPUT: «(a b C D E f g)␤» + (('d', 'e'), 'f').duckmap(-> $_ where .any { .uc }).say; + # OUTPUT: «((d E) F)␤» + +=head2 method nodemap + +Defined as: + + method nodemap(&block --> List) is nodal + +C will apply C<&block> to each element and return a new L with +the return values of C<&block>. In contrast to L it will B descend +recursively into sublists if it finds elements which L the L role. + + say [[1,2,3], [[4,5],6,7], 7].nodemap(*+1); + # OUTPUT: «(4, 4, 8)␤» + + say [[2, 3], [4, [5, 6]]]».nodemap(*+1) + # OUTPUT: «((3 4) (5 3))␤» + +The examples above would have produced the exact same results if we had used +L instead of C. The difference between the two lies in the +fact that L flattens out L while C doesn't. + + say [[2,3], [[4,5],6,7], 7].nodemap({.elems == 1 ?? $_ !! slip}); + # OUTPUT: «(() () 7)␤» + say [[2,3], [[4,5],6,7], 7].map({.elems == 1 ?? $_ !! slip}); + # OUTPUT: «(7)␤» + +=head2 method flat + +Defined as: + + method flat(--> Seq:D) is nodal + +Interprets the invocant as a list, flattens +L Ls +into a flat list, and returns that list. Keep in mind L and +L types are L and so will be flattened into lists +of pairs. + + say ((1, 2), (3), %(:42a)); # OUTPUT: «((1 2) 3 {a => 42})␤» + say ((1, 2), (3), %(:42a)).flat; # OUTPUT: «(1 2 3 a => 42)␤» + +Note that L containerize their elements by default, and so +C will not flatten them. You can use +L to call +L«C<.List>|/routine/List» method on all the inner L +and so de-containerize them, so that C can flatten them: + + say [[1, 2, 3], [(4, 5), 6, 7]] .flat; # OUTPUT: «([1 2 3] [(4 5) 6 7])␤» + say [[1, 2, 3], [(4, 5), 6, 7]]».List.flat; # OUTPUT: «(1 2 3 4 5 6 7)␤» + +For more fine-tuned options, see L, +L, and +L + +=head2 method eager + +Defined as: + + method eager(--> Seq:D) is nodal + +Interprets the invocant as a L, evaluates it eagerly, and returns that +L. + + my $range = 1..5; + say $range; # OUTPUT: «1..5␤» + say $range.eager; # OUTPUT: «(1 2 3 4 5)␤» + +=head2 method elems + +Defined as: + + method elems(--> Int:D) is nodal + +Interprets the invocant as a list, and returns the number of elements in the +list. + + say 42.elems; # OUTPUT: «1␤» + say .elems; # OUTPUT: «3␤» + +=head2 method end + + method end(--> Any:D) is nodal + +Interprets the invocant as a list, and returns the last index of that list. + + say 6.end; # OUTPUT: «0␤» + say .end; # OUTPUT: «2␤» + +=head2 method pairup + +Defined as: + + method pairup(--> Seq:D) is nodal + +Interprets the invocant as a list, and constructs a list of +L from it, in the same way that assignment to a +L does. That is, it takes two consecutive elements and +constructs a pair from them, unless the item in the key position already is a +pair (in which case the pair is passed is passed through, and the next +list item, if any, is considered to be a key again). + + say (a => 1, 'b', 'c').pairup.perl; # OUTPUT: «(:a(1), :b("c")).Seq␤» + +=head2 sub exit + +Defined as: + + sub exit(Int() $status = 0) + +Exits the current process with return code C<$status> or zero if no value has been specified. +The exit value (C<$status>), when different from zero, has to be opportunely evaluated from the +process that catches it (e.g., a shell). + +C does prevent the L phaser to be executed. + +C should be used as last resort only to signal the parent process about an exit code different from zero, +and should not be used to terminate exceptionally a method or a sub: use L instead. + +It is worth noting that the only way to return an exit code different from zero from a L function +is by means of using C. + +=comment TODO maybe find a better place to document &exit + +=head2 sub item + +X<|$ (item contextualizer)> + +Defined as: + + proto sub item(|) is pure + multi item(\x) + multi item(|c) + multi item(Mu $a) + +Forces given object to be evaluated in item context and returns the value of it. + + say item([1,2,3]).perl; # OUTPUT: «$[1, 2, 3]␤» + say item( %( apple => 10 ) ).perl; # OUTPUT: «${:apple(10)}␤» + say item("abc").perl; # OUTPUT: «"abc"␤» + +You can also use C<$> as item contextualizer. + + say $[1,2,3].perl; # OUTPUT: «$[1, 2, 3]␤» + say $("abc").perl; # OUTPUT: «"abc"␤» + +=head2 method Array + +Defined as: + + method Array(--> Array:D) is nodal + +Coerce the invocant to L. + +=head2 method List + +Defined as: + + method List(--> List:D) is nodal + +Coerce the invocant to L, using the L method. + +=head2 serial + +Defined as + + proto method serial(|) is nodal + multi method serial( --> Any) + +Returns the self-reference to the instance itself: + +=begin code +my $b; # defaults to Any +say $b.serial.^name; # OUTPUT: Any +=end code + +=head2 method Hash + +Defined as: + + proto method Hash(|) is nodal + multi method Hash( --> Hash:D) + + +Coerce the invocant to L by invoking the method C on it. + +=head2 method hash + +Defined as: + + proto method hash(|) is nodal + multi method hash(Any:U: --> Hash:D) + multi method hash(Any:D: --> Hash:D) + +Creates a new L, empty in the case the invocant is +undefined, or coerces the invocant to an C in the case it is +defined. + +=begin code +my $d; # $d is Any +say $d.hash; # OUTPUT: {} +$d.append: 'a', 'b'; +say $d.hash; # OUTPUT: {a => b} +=end code + +=head2 method Slip + +Defined as: + + method Slip(--> Slip:D) is nodal + +Coerce the invocant to L. + +=head2 method Map + +Defined as: + + method Map(--> Map:D) is nodal + +Coerce the invocant to L. + +=head2 method Bag + +Defined as: + + method Bag(--> Bag:D) is nodal + +Coerce the invocant to L, whereby L +are treated as lists of values. + +=head2 method BagHash + +Defined as: + + method BagHash(--> BagHash:D) is nodal + +Coerce the invocant to L, whereby L +are treated as lists of values. + +=head2 method Set + +Defined as: + + method Set(--> Set:D) is nodal + +Coerce the invocant to L, whereby L +are treated as lists of values. + +=head2 method SetHash + +Defined as: + + method SetHash(--> SetHash:D) is nodal + +Coerce the invocant to L, whereby L +are treated as lists of values. + +=head2 method Mix + +Defined as: + + method Mix(--> Mix:D) is nodal + +Coerce the invocant to L, whereby L +are treated as lists of values. + +=head2 method MixHash + +Defined as: + + method MixHash(--> MixHash:D) is nodal + +Coerce the invocant to L, whereby L +are treated as lists of values. + +=head2 method Supply + +Defined as: + + method Supply(--> Supply:D) is nodal + +Coerce the invocant first to a C by applying the invocant's +L«C<.list>|/routine/list» method, and then to a L. + +=head2 method min + +Defined As: + + multi method min(--> Any:D) + multi method min(&filter --> Any:D) + +Coerces to L and returns the numerically smallest element. + +If a L positional argument is provided, each value is passed +into the filter, and its return value is compared instead of the +original value. The original value is still the one returned from C. + + say (1,7,3).min(); # OUTPUT:«1␤» + say (1,7,3).min({1/$_}); # OUTPUT:«7␤» + +=head2 method max + +Defined As: + + multi method max(--> Any:D) + multi method max(&filter --> Any:D) + +Coerces to L and returns the numerically largest element. + +If a L positional argument is provided, each value is passed +into the filter, and its return value is compared instead of the +original value. The original value is still the one returned from C. + + say (1,7,3).max(); # OUTPUT:«7␤» + say (1,7,3).max({1/$_}); # OUTPUT:«1␤» + +=head2 method minmax + +Defined As: + + multi method minmax(--> Range:D) + multi method minmax(&filter --> Range:D) + +Returns a Range from the smallest to the largest element. + +If a L positional argument is provided, each value is passed +into the filter, and its return value is compared instead of the +original value. The original values are still used in the returned +Range. + + say (1,7,3).minmax(); # OUTPUT:«1..7␤» + say (1,7,3).minmax({-$_}); # OUTPUT:«7..1␤» + +=head2 method minpairs + +Defined As: + + multi method minpairs(Any:D: --> Seq:D) + +Calls L«C<.pairs>|/routine/pairs» and returns a L with +all of the Pairs with minimum values, as judged by the +L«C operator|/routine/cmp»: + + .minpairs.perl.put; # OUTPUT: «(0 => "a", 3 => "a").Seq␤» + %(:42a, :75b).minpairs.perl.put; # OUTPUT: «(:a(42),).Seq␤» + +=head2 method maxpairs + +Defined As: + + multi method maxpairs(Any:D: --> Seq:D) + +Calls L«C<.pairs>|/routine/pairs» and returns a L with +all of the Pairs with maximum values, as judged by the +L«C operator|/routine/cmp»: + + .maxpairs.perl.put; # OUTPUT: «(2 => "c", 5 => "c").Seq␤» + %(:42a, :75b).maxpairs.perl.put; # OUTPUT: «(:b(75),).Seq␤» + +=head2 method keys + +Defined As: + + multi method keys(Any:U: --> List) + multi method keys(Any:D: --> List) + +For defined L returns its L after calling `list` on it, otherwise calls `list` and returns it. + + say Any.keys; # OUTPUT: «()␤» + +=head2 method flatmap + +Defined As: + + method flatmap(Any:U: &code --> Seq) + +Coerces the L to a C by applying the +L«C<.list>|/routine/list» method and uses +L«C|/type/List#method_flatmap» on it. + + say Any.flatmap({.reverse}); # OUTPUT: «((Any))␤» + +In the case of L, C returns a 1-item list, as is shown. + +=head2 method roll + +Defined As: + + multi method roll(--> Any) + multi method roll($n --> Seq) + +Coerces the invocant L to a C by applying +the L«C<.list>|/routine/list» method and uses +L«C|/type/List#routine_roll» on it. + + say Any.roll; # OUTPUT: «(Any)␤» + say Any.roll(5); # OUTPUT: «((Any) (Any) (Any) (Any) (Any))␤» + +=head2 method pick + +Defined As: + + multi method pick(--> Any) + multi method pick($n --> Seq) + +Coerces the L to a C by applying the +L«C<.list>|/routine/list» method and uses +L«C|/type/List#routine_pick» on it. + + say Any.pick; # OUTPUT: «(Any)␤» + say Any.pick(5); # OUTPUT: «((Any))␤» + +=head2 method skip + +Defined As: + + multi method skip(--> Seq) + multi method skip($n --> Seq) + +Creates a L from 1-item list's iterator and uses +L«C|/type/Seq#method_skip» on it. + + say Any.skip; # OUTPUT: «()␤» + say Any.skip(5); # OUTPUT: «()␤» + say Any.skip(-1); # OUTPUT: «((Any))␤» + say Any.skip(*-1); # OUTPUT: «((Any))␤» + +=head2 method prepend + +Defined As: + + multi method prepend(--> Array) + multi method prepend(@values --> Array) + +Initializes L variable as empty L and calls +L«C|/type/Array#method_prepend» on it. + + my $a; + say $a.prepend; # OUTPUT: «[]␤» + say $a; # OUTPUT: «[]␤» + my $b; + say $b.prepend(1,2,3); # OUTPUT: «[1 2 3]␤» + +=head2 method unshift + +Defined As: + + multi method unshift(--> Array) + multi method unshift(@values --> Array) + +Initializes L variable as empty L and calls +L«C|/type/Array#routine_unshift» on it. + + my $a; + say $a.unshift; # OUTPUT: «[]␤» + say $a; # OUTPUT: «[]␤» + my $b; + say $b.unshift([1,2,3]); # OUTPUT: «[[1 2 3]]␤» + +=head2 method first + +Defined As: + + method first(Mu $matcher?, :$k, :$kv, :$p, :$end) + +Treats the C as a 1-item list and uses +L«C|/type/List#routine_first» on it. + + say Any.first; # OUTPUT: «(Any)␤» + +=head2 method unique + +Defined As: + + method unique(:&as, :&with --> Seq:D) + +Treats the C as a 1-item list and uses +L«C|/type/List#routine_unique» on it. + + say Any.unique; # OUTPUT: «((Any))␤» + +=head2 method repeated + +Defined As: + + method repeated(:&as, :&with --> Seq) + +Treats the C as a 1-item list and uses +L«C|/type/List#routine_repeated» on it. + + say Any.repeated; # OUTPUT: «()␤» + +=head2 method squish + +Defined As: + + method squish(:&as, :&with --> Seq) + +Treats the C as a 1-item list and uses +L«C|/type/List#routine_squish» on it. + + say Any.squish; # OUTPUT: «((Any))␤» + + +=head2 method permutations + +Defined As: + + method permutations(--> Seq) + +Treats the C as a 1-item list and uses +L«C|/type/List#routine_permutations» on it. + + say Any.permutations; # OUTPUT: «(((Any)))␤» + +=head2 method categorize + +Defined As: + + method categorize(&mapper --> Hash:D) + +Treats the C as a 1-item list and uses +L«C|/type/List#routine_categorize» on it. + + say Any.categorize({ $_ }); # OUTPUT: «{(Any) => [(Any)]}␤» + +=head2 method classify + +Defined As: + + method classify(&mapper -->Hash:D) + +Treats the C as a 1-item list and uses +L«C|/type/List#routine_classify» on it. + + say Any.classify({ $_ }); # OUTPUT: «{(Any) => [(Any)]}␤» + +=head2 method produce + + +=head2 method pairs + +Defined As: + + multi method pairs(Any:U: -->List) + multi method pairs(Any:D: -->List) + +Returns an empty L if the invocant is undefined, otherwise +converts the invocant to a L via the C method +and calls L on it: + + say Any.pairs; # OUTPUT: «()␤» + my $a; + say $a.pairs; # OUTPUT: «()» + $a = Any.new; + say $a.pairs; # OUTPUT: «(0 => Any.new)» + + +=head2 method antipairs + +Defined As: + + multi method antipairs(Any:U: -->List) + multi method antipairs(Any:D: -->List) + +Applies the method L to the invocant, if it is defined, +after having invoked C on it. If the invocant is not defined, +it returns an empty L: + + my $a; + say $a.antipairs; # OUTPUT: «()» + $a = Any.new; + say $a.antipairs; # OUTPUT: «(Any.new => 0)» + + +=head2 method kv + +Defined As: + + multi method kv(Any:U: -->List) + multi method kv(Any:D: -->List) + +Returns an empty L if the invocant is not defined, otherwise it +does invoke C on the invocant and then returns the result +of L on the latter: + + my $a; + say $a.kv; # OUTPUT: «()» + $a = Any.new; + say $a.kv; # OUTPUT: «(0 Any.new)» + say Any.kv; # OUTPUT: «()␤» + +=head2 method toggle + +Defined as: + + method toggle(Any:D: *@conditions where .all ~~ Callable:D, Bool :$off --> Seq:D) + +L over the invocant, producing a L, toggling +whether the received values are propagated to the result on and off, depending +on the results of calling L in C<@conditions>: + + say ^10 .toggle: * < 4, * %% 2, &is-prime; # OUTPUT: «(0 1 2 3 6 7)␤» + say ^10 .toggle: :off, * > 4; # OUTPUT: «(5 6 7 8 9)␤» + +Imagine a switch that's either on or off (C or C), and values are +produced if it's on. By default, the initial state of that switch is in "on" +position, unless C<:$off> is set to a true value, in which case the initial +state will be "off". + +A L from the L of C<@conditions> is taken (if any are available) +and it becomes the current tester. Each value from the original sequence is +tested by calling the tester L with that value. The state of our +imaginary switch is set to the return value from the tester: if it's truthy, +set switch to "on", otherwise set it to "off". + +Whenever the switch is I (i.e. switched from "off" to "on" or +from "on" to "off"), the current tester L is replaced by the next +L in C<@conditions>, if available, which will be used to test any +further values. If no more tester Callables are available, the switch will +remain in its current state until the end of iteration. + + =begin code + # our original sequence of elements: + say list ^10; # OUTPUT: «(0 1 2 3 4 5 6 7 8 9)␤» + # toggled result: + say ^10 .toggle: * < 4, * %% 2, &is-prime; # OUTPUT: «(0 1 2 3 6 7)␤» + + # First tester Callable is `* < 4` and initial state of switch is "on". + # As we iterate over our original sequence: + # 0 => 0 < 4 === True switch is on, value gets into result, switch is + # toggled, so we keep using the same Callable: + # 1 => 1 < 4 === True same + # 2 => 2 < 4 === True same + # 3 => 3 < 4 === True same + # 4 => 4 < 4 === False switch is now off, "4" does not make it into the + # result. In addition, our switch got toggled, so + # we're switching to the next tester Callable + # 5 => 5 %% 2 === False switch is still off, keep trying to find a value + # 6 => 6 %% 2 === True switch is now on, take "6" into result. The switch + # toggled, so we'll use the next tester Callable + # 7 => is-prime(7) === True switch is still on, take value and keep going + # 8 => is-prime(8) === False switch is now off, "8" does not make it into + # the result. The switch got toggled, but we + # don't have any more tester Callables, so it + # will remain off for the rest of the sequence. + =end code + +Since the toggle of the switch's state loads the next tester L, +setting C<:$off> to a C value affects when first tester is discarded: + + =begin code + # our original sequence of elements: + say <0 1 2>; # OUTPUT: «(0 1 2)␤» + # toggled result: + say <0 1 2>.toggle: * > 1; # OUTPUT: «()␤» + + # First tester Callable is `* > 1` and initial state of switch is "on". + # As we iterate over our original sequence: + # 0 => 0 > 1 === False switch is off, "0" does not make it into result. + # In addition, switch got toggled, so we change the + # tester Callable, and since we don't have any more + # of them, the switch will remain "off" until the end + =end code + + =begin code + # our original sequence of elements: + say <0 1 2>; # OUTPUT: «(0 1 2)␤» + # toggled result: + say <0 1 2>.toggle: :off, * > 1; # OUTPUT: «(2)␤» + + # First tester Callable is `* > 1` and initial state of switch is "off". + # As we iterate over our original sequence: + # 0 => 0 > 1 === False switch is off, "0" does not make it into result. + # The switch did NOT get toggled this time, so we + # keep using our current tester Callable + # 1 => 1 > 1 === False same + # 2 => 2 > 1 === True switch is on, "2" makes it into the result + =end code + + +=head2 method tree + +Defined As: + + method tree(--> Any) + +Returns the class if it's undefined or if it's not iterable, returns the result of applying the `tree` method to the elements if it's `Iterable`. + + say Any.tree; # OUTPUT: «Any␤» + +=head2 method nl-out + +Defined As: + + method nl-out(--> Str) + +Returns Str with the value of "\n". See +L«C|/type/IO::Handle#method_nl-out» for the +details. + + say Any.nl-out; # OUTPUT: «␤␤» + +=head2 method invert + +Defined As: + + method invert(--> List) + +Returns an empty List. + + say Any.invert; # OUTPUT: «()␤» + +=head2 method combinations + +Defined As: + + method combinations(--> Seq) + +Treats the C as a 1-item list and uses +L«C|/type/List#routine_combinations» on it. + + say Any.combinations; # OUTPUT: «(() ((Any)))␤» + +=head2 method iterator + +Defined As: + + method iterator(--> Iterator) + +Coerces the C to a C by applying the C<.list> method and uses +L«C|/type/Iterable#method_iterator» on it. + + my $it = Any.iterator; + say $it.pull-one; # OUTPUT: «(Any)␤» + say $it.pull-one; # OUTPUT: «IterationEnd␤» + +=head2 method grep + +Defined As: + + method grep(Mu $matcher, :$k, :$kv, :$p, :$v --> Seq) + +Coerces the C to a C by applying the C<.list> method and uses +L«C|/type/List#routine_grep» on it. + +Based on C<$matcher> value can be either C<((Any))> or empty List. + + my $a; + say $a.grep({ True }); # OUTPUT: «((Any))␤» + say $a.grep({ $_ }); # OUTPUT: «()␤» + +=head2 method append + +Defined As: + + proto method append(|) is nodal {*} + multi method append(Any:U \SELF: |values --> Array) + +In the case the instance is not a positional-thing, it instantiate it +as a new L, otherwise clone the current +instance. +After that, it appends the values passed as arguments to +the array obtained calling L«C|/type/Array#method_append» on it. + + my $a; + say $a.append; # OUTPUT: «[]␤» + my $b; + say $b.append((1,2,3)); # OUTPUT: «[1 2 3]␤» + +=head2 method values + +Defined As: + + method values(--> List) + +Returns an empty List. + +=head2 method collate + +Defined As: + + method collate(--> Seq) + +TODO + +=head2 method cache + +Defined As: + + method cache(--> List) + +Provides a L representation of the object itself, calling +the method C on the instance. + +=end pod + +# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 From 2d854639e6eb1d1fb2b23a5e11158184ceaa5d42 Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Tue, 13 Mar 2018 07:56:51 +0100 Subject: [PATCH 13/20] Eliminates .pod because it's its own language --- lib/linguist/languages.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 1d36fbbc6b..572d69a7be 100755 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -3366,7 +3366,6 @@ Perl: - ".ph" - ".plx" - ".pm" - - ".pod" - ".psgi" - ".t" filenames: From cc2e8a7e61e87984803a107f020825569d77f9bc Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Tue, 13 Mar 2018 08:20:32 +0100 Subject: [PATCH 14/20] Removes bad directory --- lib/linguist/languages.yml | 4 ++-- samples/{Perl6 => Perl 6}/Any.pod6 | 0 samples/{Perl6 => Perl 6}/chromosome.pl | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename samples/{Perl6 => Perl 6}/Any.pod6 (100%) rename samples/{Perl6 => Perl 6}/chromosome.pl (100%) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 572d69a7be..d22945e823 100755 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -3369,9 +3369,9 @@ Perl: - ".psgi" - ".t" filenames: - - cpanfile - - Rexfile - Makefile.PL + - Rexfile + - cpanfile interpreters: - perl language_id: 282 diff --git a/samples/Perl6/Any.pod6 b/samples/Perl 6/Any.pod6 similarity index 100% rename from samples/Perl6/Any.pod6 rename to samples/Perl 6/Any.pod6 diff --git a/samples/Perl6/chromosome.pl b/samples/Perl 6/chromosome.pl similarity index 100% rename from samples/Perl6/chromosome.pl rename to samples/Perl 6/chromosome.pl From 4eaa4b337eb0a535bb57f4f0243a89251778961f Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Tue, 13 Mar 2018 08:24:41 +0100 Subject: [PATCH 15/20] Reverting changes that were already there --- CONTRIBUTING.md | 36 ++++-------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 21a238205f..953dcb4a1d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,40 +9,12 @@ This project adheres to the [Contributor Covenant Code of Conduct](http://contri The majority of contributions won't need to touch any Ruby code at all. -## Installation how to - -You might want to get Linguist running in order to test locally whatever -changes you might be doing to it. You will need to install some -prerrequisite libraries -first. [Install CMake](https://cmake.org/install/) which is required to install `rugged`. - -Then - - bundle install - -to install all dependencies and finally - - rake samples - -to generate `samples.json` file, which is needed for checking out -samples. Then you can simply run - - bundle exec linguist --breakdown - -to check the languages on the repository itself, or - - bundle exec git-linguist --commit=362d300cb021f11fe1c66f69b7f1bb0c246f01b0 breakdown - -to get a breakdown in JSON format for an specific commit. - -You can try it too in some other directory this way: - - bundle exec linguist ../../CPAN/Algorithm-Evolutionary - - ## Getting started -Before you can start contributing to Linguist, you'll need to set up your environment first. Clone the repo and run `script/bootstrap` to install its dependencies. +Before you can start contributing to Linguist, you'll need to set up +your environment first. [Install CMake](https://cmake.org/install/) +which is required to install `rugged` and then clone the repo and run +`script/bootstrap` to install its dependencies. git clone https://github.com/github/linguist.git cd linguist/ From 560186529dd3555dddc5113a75fa60b252e1395e Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Tue, 13 Mar 2018 10:05:47 +0100 Subject: [PATCH 16/20] Restored CONTRIBUTING.md from head I see installation of cmake is advised in README.md --- CONTRIBUTING.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 953dcb4a1d..28e427d756 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,15 +6,11 @@ Contributions to this project are [released](https://help.github.com/articles/gi This project adheres to the [Contributor Covenant Code of Conduct](http://contributor-covenant.org/). By participating, you are expected to uphold this code. -The majority of contributions won't need to touch any Ruby code at -all. +The majority of contributions won't need to touch any Ruby code at all. ## Getting started -Before you can start contributing to Linguist, you'll need to set up -your environment first. [Install CMake](https://cmake.org/install/) -which is required to install `rugged` and then clone the repo and run -`script/bootstrap` to install its dependencies. +Before you can start contributing to Linguist, you'll need to set up your environment first. Clone the repo and run `script/bootstrap` to install its dependencies. git clone https://github.com/github/linguist.git cd linguist/ From 6ce294dc83f71fba4fb6bf7420fbd164e4c8bc96 Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Wed, 28 Mar 2018 12:26:10 +0200 Subject: [PATCH 17/20] Eliminates `.pod6` To leave way for #3366 or succeeding PRs. --- lib/linguist/languages.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index d22945e823..cb71d08f8d 100755 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -3389,7 +3389,6 @@ Perl 6: - ".pl6" - ".pm" - ".pm6" - - ".pod6" - ".t" interpreters: - perl6 From 0bd8636441fc3167adbfed5c5faf05fc0e1c43c0 Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Wed, 28 Mar 2018 18:30:02 +0200 Subject: [PATCH 18/20] Removed by request, since we're no longer adding this extension --- samples/Perl 6/Any.pod6 | 987 ---------------------------------------- 1 file changed, 987 deletions(-) delete mode 100644 samples/Perl 6/Any.pod6 diff --git a/samples/Perl 6/Any.pod6 b/samples/Perl 6/Any.pod6 deleted file mode 100644 index 22e186124b..0000000000 --- a/samples/Perl 6/Any.pod6 +++ /dev/null @@ -1,987 +0,0 @@ -=begin pod - -=TITLE class Any - -=SUBTITLE Thing/object - - class Any is Mu {} - -While L is the root of the Perl 6 class hierarchy, L is the class -that serves as a default base class for new classes, and as the base class for -most built-in classes. - -Since Perl 6 intentionally confuses items and single-element lists, most -methods in L are also present on class L, and coerce to -List or a list-like type. - -=head1 Methods - -=head2 method ACCEPTS - -Defined as: - - multi method ACCEPTS(Any:D: Mu $other) - -Usage: - -=begin code :lang -EXPR.ACCEPTS(EXPR); -=end code - -Returns C if C<$other === self> (i.e. it checks object identity). - -Many built-in types override this for more specific comparisons - -=head2 method any - -Defined as: - - method any(--> Junction:D) - -Interprets the invocant as a list and creates an -L-L from it. - - say so 2 == <1 2 3>.any; # OUTPUT: «True␤» - say so 5 == <1 2 3>.any; # OUTPUT: «False␤» - -=head2 method all - -Defined as: - - method all(--> Junction:D) - -Interprets the invocant as a list and creates an -L-L from it. - - say so 1 < <2 3 4>.all; # OUTPUT: «True␤» - say so 3 < <2 3 4>.all; # OUTPUT: «False␤» - -=head2 method one - -Defined as: - - method one(--> Junction:D) - -Interprets the invocant as a list and creates a -L-L from it. - - say so 1 == (1, 2, 3).one; # OUTPUT: «True␤» - say so 1 == (1, 2, 1).one; # OUTPUT: «False␤» - -=head2 method none - -Defined as: - - method none(--> Junction:D) - -Interprets the invocant as a list and creates a -L-L from it. - - say so 1 == (1, 2, 3).none; # OUTPUT: «False␤» - say so 4 == (1, 2, 3).none; # OUTPUT: «True␤» - -=head2 method list - -Defined as: - - multi method list(Any:U: -->List) - multi method list(Any:D \SELF: -->List) - - -Applies the infix L«C<,>|/routine/,» -operator to the invocant -and returns the resulting L: - - say 42.list.^name; # OUTPUT: «List␤» - say 42.list.elems; # OUTPUT: «1␤» - -=head2 method push - -Defined as: - - method push(|values --> Positional:D) - -The method push is defined for undefined invocants and allows for -autovivifying undefined to an empty L, unless the undefined value -implements L already. The argument provided will then be pushed -into the newly created Array. - - my %h; - say %h; # OUTPUT: «(Any)␤» <-- Undefined - %h.push(1); # .push on Any - say %h; # OUTPUT: «{a => [1]}␤» <-- Note the Array - -=head2 routine reverse - -Defined as: - - multi sub reverse(*@list --> Seq:D) - multi method reverse(List:D: --> Seq:D) - -Returns a L with the same elements in reverse order. - -Note that C always refers to reversing elements of a list; -to reverse the characters in a string, use L. - -Examples: - - say .reverse; # OUTPUT: «(world! hello)␤» - say reverse ^10; # OUTPUT: «(9 8 7 6 5 4 3 2 1 0)␤» - -=head2 method sort - -Defined as: - - multi method sort() - multi method sort(&custom-routine-to-use) - -Sorts iterables with L or given code object and returns a new L. -Optionally, takes a L as a positional parameter, specifying how to -sort. - -Examples: - - say .sort; # OUTPUT: «(a b c)␤» - say 'bca'.comb.sort.join; # OUTPUT: «abc␤» - say 'bca'.comb.sort({$^b cmp $^a}).join; # OUTPUT: «cba␤» - say '231'.comb.sort(&infix:«<=>»).join; # OUTPUT: «123␤» - -=head2 method map - -Defined as: - - multi method map(\SELF: █; :$label, :$item) - -C will iterate over the invocant and apply the number of positional -parameters of the code object from the invocant per call. The returned values -of the code object will become elements of the returned L. - -The C<:$label> and C<:$item> are useful only internally, since C loops -get converted to Cs. The C<:$label> takes an existing L.duckmap(-> $_ where .any { .uc }).say; - # OUTPUT: «(a b C D E f g)␤» - (('d', 'e'), 'f').duckmap(-> $_ where .any { .uc }).say; - # OUTPUT: «((d E) F)␤» - -=head2 method nodemap - -Defined as: - - method nodemap(&block --> List) is nodal - -C will apply C<&block> to each element and return a new L with -the return values of C<&block>. In contrast to L it will B descend -recursively into sublists if it finds elements which L the L role. - - say [[1,2,3], [[4,5],6,7], 7].nodemap(*+1); - # OUTPUT: «(4, 4, 8)␤» - - say [[2, 3], [4, [5, 6]]]».nodemap(*+1) - # OUTPUT: «((3 4) (5 3))␤» - -The examples above would have produced the exact same results if we had used -L instead of C. The difference between the two lies in the -fact that L flattens out L while C doesn't. - - say [[2,3], [[4,5],6,7], 7].nodemap({.elems == 1 ?? $_ !! slip}); - # OUTPUT: «(() () 7)␤» - say [[2,3], [[4,5],6,7], 7].map({.elems == 1 ?? $_ !! slip}); - # OUTPUT: «(7)␤» - -=head2 method flat - -Defined as: - - method flat(--> Seq:D) is nodal - -Interprets the invocant as a list, flattens -L Ls -into a flat list, and returns that list. Keep in mind L and -L types are L and so will be flattened into lists -of pairs. - - say ((1, 2), (3), %(:42a)); # OUTPUT: «((1 2) 3 {a => 42})␤» - say ((1, 2), (3), %(:42a)).flat; # OUTPUT: «(1 2 3 a => 42)␤» - -Note that L containerize their elements by default, and so -C will not flatten them. You can use -L to call -L«C<.List>|/routine/List» method on all the inner L -and so de-containerize them, so that C can flatten them: - - say [[1, 2, 3], [(4, 5), 6, 7]] .flat; # OUTPUT: «([1 2 3] [(4 5) 6 7])␤» - say [[1, 2, 3], [(4, 5), 6, 7]]».List.flat; # OUTPUT: «(1 2 3 4 5 6 7)␤» - -For more fine-tuned options, see L, -L, and -L - -=head2 method eager - -Defined as: - - method eager(--> Seq:D) is nodal - -Interprets the invocant as a L, evaluates it eagerly, and returns that -L. - - my $range = 1..5; - say $range; # OUTPUT: «1..5␤» - say $range.eager; # OUTPUT: «(1 2 3 4 5)␤» - -=head2 method elems - -Defined as: - - method elems(--> Int:D) is nodal - -Interprets the invocant as a list, and returns the number of elements in the -list. - - say 42.elems; # OUTPUT: «1␤» - say .elems; # OUTPUT: «3␤» - -=head2 method end - - method end(--> Any:D) is nodal - -Interprets the invocant as a list, and returns the last index of that list. - - say 6.end; # OUTPUT: «0␤» - say .end; # OUTPUT: «2␤» - -=head2 method pairup - -Defined as: - - method pairup(--> Seq:D) is nodal - -Interprets the invocant as a list, and constructs a list of -L from it, in the same way that assignment to a -L does. That is, it takes two consecutive elements and -constructs a pair from them, unless the item in the key position already is a -pair (in which case the pair is passed is passed through, and the next -list item, if any, is considered to be a key again). - - say (a => 1, 'b', 'c').pairup.perl; # OUTPUT: «(:a(1), :b("c")).Seq␤» - -=head2 sub exit - -Defined as: - - sub exit(Int() $status = 0) - -Exits the current process with return code C<$status> or zero if no value has been specified. -The exit value (C<$status>), when different from zero, has to be opportunely evaluated from the -process that catches it (e.g., a shell). - -C does prevent the L phaser to be executed. - -C should be used as last resort only to signal the parent process about an exit code different from zero, -and should not be used to terminate exceptionally a method or a sub: use L instead. - -It is worth noting that the only way to return an exit code different from zero from a L function -is by means of using C. - -=comment TODO maybe find a better place to document &exit - -=head2 sub item - -X<|$ (item contextualizer)> - -Defined as: - - proto sub item(|) is pure - multi item(\x) - multi item(|c) - multi item(Mu $a) - -Forces given object to be evaluated in item context and returns the value of it. - - say item([1,2,3]).perl; # OUTPUT: «$[1, 2, 3]␤» - say item( %( apple => 10 ) ).perl; # OUTPUT: «${:apple(10)}␤» - say item("abc").perl; # OUTPUT: «"abc"␤» - -You can also use C<$> as item contextualizer. - - say $[1,2,3].perl; # OUTPUT: «$[1, 2, 3]␤» - say $("abc").perl; # OUTPUT: «"abc"␤» - -=head2 method Array - -Defined as: - - method Array(--> Array:D) is nodal - -Coerce the invocant to L. - -=head2 method List - -Defined as: - - method List(--> List:D) is nodal - -Coerce the invocant to L, using the L method. - -=head2 serial - -Defined as - - proto method serial(|) is nodal - multi method serial( --> Any) - -Returns the self-reference to the instance itself: - -=begin code -my $b; # defaults to Any -say $b.serial.^name; # OUTPUT: Any -=end code - -=head2 method Hash - -Defined as: - - proto method Hash(|) is nodal - multi method Hash( --> Hash:D) - - -Coerce the invocant to L by invoking the method C on it. - -=head2 method hash - -Defined as: - - proto method hash(|) is nodal - multi method hash(Any:U: --> Hash:D) - multi method hash(Any:D: --> Hash:D) - -Creates a new L, empty in the case the invocant is -undefined, or coerces the invocant to an C in the case it is -defined. - -=begin code -my $d; # $d is Any -say $d.hash; # OUTPUT: {} -$d.append: 'a', 'b'; -say $d.hash; # OUTPUT: {a => b} -=end code - -=head2 method Slip - -Defined as: - - method Slip(--> Slip:D) is nodal - -Coerce the invocant to L. - -=head2 method Map - -Defined as: - - method Map(--> Map:D) is nodal - -Coerce the invocant to L. - -=head2 method Bag - -Defined as: - - method Bag(--> Bag:D) is nodal - -Coerce the invocant to L, whereby L -are treated as lists of values. - -=head2 method BagHash - -Defined as: - - method BagHash(--> BagHash:D) is nodal - -Coerce the invocant to L, whereby L -are treated as lists of values. - -=head2 method Set - -Defined as: - - method Set(--> Set:D) is nodal - -Coerce the invocant to L, whereby L -are treated as lists of values. - -=head2 method SetHash - -Defined as: - - method SetHash(--> SetHash:D) is nodal - -Coerce the invocant to L, whereby L -are treated as lists of values. - -=head2 method Mix - -Defined as: - - method Mix(--> Mix:D) is nodal - -Coerce the invocant to L, whereby L -are treated as lists of values. - -=head2 method MixHash - -Defined as: - - method MixHash(--> MixHash:D) is nodal - -Coerce the invocant to L, whereby L -are treated as lists of values. - -=head2 method Supply - -Defined as: - - method Supply(--> Supply:D) is nodal - -Coerce the invocant first to a C by applying the invocant's -L«C<.list>|/routine/list» method, and then to a L. - -=head2 method min - -Defined As: - - multi method min(--> Any:D) - multi method min(&filter --> Any:D) - -Coerces to L and returns the numerically smallest element. - -If a L positional argument is provided, each value is passed -into the filter, and its return value is compared instead of the -original value. The original value is still the one returned from C. - - say (1,7,3).min(); # OUTPUT:«1␤» - say (1,7,3).min({1/$_}); # OUTPUT:«7␤» - -=head2 method max - -Defined As: - - multi method max(--> Any:D) - multi method max(&filter --> Any:D) - -Coerces to L and returns the numerically largest element. - -If a L positional argument is provided, each value is passed -into the filter, and its return value is compared instead of the -original value. The original value is still the one returned from C. - - say (1,7,3).max(); # OUTPUT:«7␤» - say (1,7,3).max({1/$_}); # OUTPUT:«1␤» - -=head2 method minmax - -Defined As: - - multi method minmax(--> Range:D) - multi method minmax(&filter --> Range:D) - -Returns a Range from the smallest to the largest element. - -If a L positional argument is provided, each value is passed -into the filter, and its return value is compared instead of the -original value. The original values are still used in the returned -Range. - - say (1,7,3).minmax(); # OUTPUT:«1..7␤» - say (1,7,3).minmax({-$_}); # OUTPUT:«7..1␤» - -=head2 method minpairs - -Defined As: - - multi method minpairs(Any:D: --> Seq:D) - -Calls L«C<.pairs>|/routine/pairs» and returns a L with -all of the Pairs with minimum values, as judged by the -L«C operator|/routine/cmp»: - - .minpairs.perl.put; # OUTPUT: «(0 => "a", 3 => "a").Seq␤» - %(:42a, :75b).minpairs.perl.put; # OUTPUT: «(:a(42),).Seq␤» - -=head2 method maxpairs - -Defined As: - - multi method maxpairs(Any:D: --> Seq:D) - -Calls L«C<.pairs>|/routine/pairs» and returns a L with -all of the Pairs with maximum values, as judged by the -L«C operator|/routine/cmp»: - - .maxpairs.perl.put; # OUTPUT: «(2 => "c", 5 => "c").Seq␤» - %(:42a, :75b).maxpairs.perl.put; # OUTPUT: «(:b(75),).Seq␤» - -=head2 method keys - -Defined As: - - multi method keys(Any:U: --> List) - multi method keys(Any:D: --> List) - -For defined L returns its L after calling `list` on it, otherwise calls `list` and returns it. - - say Any.keys; # OUTPUT: «()␤» - -=head2 method flatmap - -Defined As: - - method flatmap(Any:U: &code --> Seq) - -Coerces the L to a C by applying the -L«C<.list>|/routine/list» method and uses -L«C|/type/List#method_flatmap» on it. - - say Any.flatmap({.reverse}); # OUTPUT: «((Any))␤» - -In the case of L, C returns a 1-item list, as is shown. - -=head2 method roll - -Defined As: - - multi method roll(--> Any) - multi method roll($n --> Seq) - -Coerces the invocant L to a C by applying -the L«C<.list>|/routine/list» method and uses -L«C|/type/List#routine_roll» on it. - - say Any.roll; # OUTPUT: «(Any)␤» - say Any.roll(5); # OUTPUT: «((Any) (Any) (Any) (Any) (Any))␤» - -=head2 method pick - -Defined As: - - multi method pick(--> Any) - multi method pick($n --> Seq) - -Coerces the L to a C by applying the -L«C<.list>|/routine/list» method and uses -L«C|/type/List#routine_pick» on it. - - say Any.pick; # OUTPUT: «(Any)␤» - say Any.pick(5); # OUTPUT: «((Any))␤» - -=head2 method skip - -Defined As: - - multi method skip(--> Seq) - multi method skip($n --> Seq) - -Creates a L from 1-item list's iterator and uses -L«C|/type/Seq#method_skip» on it. - - say Any.skip; # OUTPUT: «()␤» - say Any.skip(5); # OUTPUT: «()␤» - say Any.skip(-1); # OUTPUT: «((Any))␤» - say Any.skip(*-1); # OUTPUT: «((Any))␤» - -=head2 method prepend - -Defined As: - - multi method prepend(--> Array) - multi method prepend(@values --> Array) - -Initializes L variable as empty L and calls -L«C|/type/Array#method_prepend» on it. - - my $a; - say $a.prepend; # OUTPUT: «[]␤» - say $a; # OUTPUT: «[]␤» - my $b; - say $b.prepend(1,2,3); # OUTPUT: «[1 2 3]␤» - -=head2 method unshift - -Defined As: - - multi method unshift(--> Array) - multi method unshift(@values --> Array) - -Initializes L variable as empty L and calls -L«C|/type/Array#routine_unshift» on it. - - my $a; - say $a.unshift; # OUTPUT: «[]␤» - say $a; # OUTPUT: «[]␤» - my $b; - say $b.unshift([1,2,3]); # OUTPUT: «[[1 2 3]]␤» - -=head2 method first - -Defined As: - - method first(Mu $matcher?, :$k, :$kv, :$p, :$end) - -Treats the C as a 1-item list and uses -L«C|/type/List#routine_first» on it. - - say Any.first; # OUTPUT: «(Any)␤» - -=head2 method unique - -Defined As: - - method unique(:&as, :&with --> Seq:D) - -Treats the C as a 1-item list and uses -L«C|/type/List#routine_unique» on it. - - say Any.unique; # OUTPUT: «((Any))␤» - -=head2 method repeated - -Defined As: - - method repeated(:&as, :&with --> Seq) - -Treats the C as a 1-item list and uses -L«C|/type/List#routine_repeated» on it. - - say Any.repeated; # OUTPUT: «()␤» - -=head2 method squish - -Defined As: - - method squish(:&as, :&with --> Seq) - -Treats the C as a 1-item list and uses -L«C|/type/List#routine_squish» on it. - - say Any.squish; # OUTPUT: «((Any))␤» - - -=head2 method permutations - -Defined As: - - method permutations(--> Seq) - -Treats the C as a 1-item list and uses -L«C|/type/List#routine_permutations» on it. - - say Any.permutations; # OUTPUT: «(((Any)))␤» - -=head2 method categorize - -Defined As: - - method categorize(&mapper --> Hash:D) - -Treats the C as a 1-item list and uses -L«C|/type/List#routine_categorize» on it. - - say Any.categorize({ $_ }); # OUTPUT: «{(Any) => [(Any)]}␤» - -=head2 method classify - -Defined As: - - method classify(&mapper -->Hash:D) - -Treats the C as a 1-item list and uses -L«C|/type/List#routine_classify» on it. - - say Any.classify({ $_ }); # OUTPUT: «{(Any) => [(Any)]}␤» - -=head2 method produce - - -=head2 method pairs - -Defined As: - - multi method pairs(Any:U: -->List) - multi method pairs(Any:D: -->List) - -Returns an empty L if the invocant is undefined, otherwise -converts the invocant to a L via the C method -and calls L on it: - - say Any.pairs; # OUTPUT: «()␤» - my $a; - say $a.pairs; # OUTPUT: «()» - $a = Any.new; - say $a.pairs; # OUTPUT: «(0 => Any.new)» - - -=head2 method antipairs - -Defined As: - - multi method antipairs(Any:U: -->List) - multi method antipairs(Any:D: -->List) - -Applies the method L to the invocant, if it is defined, -after having invoked C on it. If the invocant is not defined, -it returns an empty L: - - my $a; - say $a.antipairs; # OUTPUT: «()» - $a = Any.new; - say $a.antipairs; # OUTPUT: «(Any.new => 0)» - - -=head2 method kv - -Defined As: - - multi method kv(Any:U: -->List) - multi method kv(Any:D: -->List) - -Returns an empty L if the invocant is not defined, otherwise it -does invoke C on the invocant and then returns the result -of L on the latter: - - my $a; - say $a.kv; # OUTPUT: «()» - $a = Any.new; - say $a.kv; # OUTPUT: «(0 Any.new)» - say Any.kv; # OUTPUT: «()␤» - -=head2 method toggle - -Defined as: - - method toggle(Any:D: *@conditions where .all ~~ Callable:D, Bool :$off --> Seq:D) - -L over the invocant, producing a L, toggling -whether the received values are propagated to the result on and off, depending -on the results of calling L in C<@conditions>: - - say ^10 .toggle: * < 4, * %% 2, &is-prime; # OUTPUT: «(0 1 2 3 6 7)␤» - say ^10 .toggle: :off, * > 4; # OUTPUT: «(5 6 7 8 9)␤» - -Imagine a switch that's either on or off (C or C), and values are -produced if it's on. By default, the initial state of that switch is in "on" -position, unless C<:$off> is set to a true value, in which case the initial -state will be "off". - -A L from the L of C<@conditions> is taken (if any are available) -and it becomes the current tester. Each value from the original sequence is -tested by calling the tester L with that value. The state of our -imaginary switch is set to the return value from the tester: if it's truthy, -set switch to "on", otherwise set it to "off". - -Whenever the switch is I (i.e. switched from "off" to "on" or -from "on" to "off"), the current tester L is replaced by the next -L in C<@conditions>, if available, which will be used to test any -further values. If no more tester Callables are available, the switch will -remain in its current state until the end of iteration. - - =begin code - # our original sequence of elements: - say list ^10; # OUTPUT: «(0 1 2 3 4 5 6 7 8 9)␤» - # toggled result: - say ^10 .toggle: * < 4, * %% 2, &is-prime; # OUTPUT: «(0 1 2 3 6 7)␤» - - # First tester Callable is `* < 4` and initial state of switch is "on". - # As we iterate over our original sequence: - # 0 => 0 < 4 === True switch is on, value gets into result, switch is - # toggled, so we keep using the same Callable: - # 1 => 1 < 4 === True same - # 2 => 2 < 4 === True same - # 3 => 3 < 4 === True same - # 4 => 4 < 4 === False switch is now off, "4" does not make it into the - # result. In addition, our switch got toggled, so - # we're switching to the next tester Callable - # 5 => 5 %% 2 === False switch is still off, keep trying to find a value - # 6 => 6 %% 2 === True switch is now on, take "6" into result. The switch - # toggled, so we'll use the next tester Callable - # 7 => is-prime(7) === True switch is still on, take value and keep going - # 8 => is-prime(8) === False switch is now off, "8" does not make it into - # the result. The switch got toggled, but we - # don't have any more tester Callables, so it - # will remain off for the rest of the sequence. - =end code - -Since the toggle of the switch's state loads the next tester L, -setting C<:$off> to a C value affects when first tester is discarded: - - =begin code - # our original sequence of elements: - say <0 1 2>; # OUTPUT: «(0 1 2)␤» - # toggled result: - say <0 1 2>.toggle: * > 1; # OUTPUT: «()␤» - - # First tester Callable is `* > 1` and initial state of switch is "on". - # As we iterate over our original sequence: - # 0 => 0 > 1 === False switch is off, "0" does not make it into result. - # In addition, switch got toggled, so we change the - # tester Callable, and since we don't have any more - # of them, the switch will remain "off" until the end - =end code - - =begin code - # our original sequence of elements: - say <0 1 2>; # OUTPUT: «(0 1 2)␤» - # toggled result: - say <0 1 2>.toggle: :off, * > 1; # OUTPUT: «(2)␤» - - # First tester Callable is `* > 1` and initial state of switch is "off". - # As we iterate over our original sequence: - # 0 => 0 > 1 === False switch is off, "0" does not make it into result. - # The switch did NOT get toggled this time, so we - # keep using our current tester Callable - # 1 => 1 > 1 === False same - # 2 => 2 > 1 === True switch is on, "2" makes it into the result - =end code - - -=head2 method tree - -Defined As: - - method tree(--> Any) - -Returns the class if it's undefined or if it's not iterable, returns the result of applying the `tree` method to the elements if it's `Iterable`. - - say Any.tree; # OUTPUT: «Any␤» - -=head2 method nl-out - -Defined As: - - method nl-out(--> Str) - -Returns Str with the value of "\n". See -L«C|/type/IO::Handle#method_nl-out» for the -details. - - say Any.nl-out; # OUTPUT: «␤␤» - -=head2 method invert - -Defined As: - - method invert(--> List) - -Returns an empty List. - - say Any.invert; # OUTPUT: «()␤» - -=head2 method combinations - -Defined As: - - method combinations(--> Seq) - -Treats the C as a 1-item list and uses -L«C|/type/List#routine_combinations» on it. - - say Any.combinations; # OUTPUT: «(() ((Any)))␤» - -=head2 method iterator - -Defined As: - - method iterator(--> Iterator) - -Coerces the C to a C by applying the C<.list> method and uses -L«C|/type/Iterable#method_iterator» on it. - - my $it = Any.iterator; - say $it.pull-one; # OUTPUT: «(Any)␤» - say $it.pull-one; # OUTPUT: «IterationEnd␤» - -=head2 method grep - -Defined As: - - method grep(Mu $matcher, :$k, :$kv, :$p, :$v --> Seq) - -Coerces the C to a C by applying the C<.list> method and uses -L«C|/type/List#routine_grep» on it. - -Based on C<$matcher> value can be either C<((Any))> or empty List. - - my $a; - say $a.grep({ True }); # OUTPUT: «((Any))␤» - say $a.grep({ $_ }); # OUTPUT: «()␤» - -=head2 method append - -Defined As: - - proto method append(|) is nodal {*} - multi method append(Any:U \SELF: |values --> Array) - -In the case the instance is not a positional-thing, it instantiate it -as a new L, otherwise clone the current -instance. -After that, it appends the values passed as arguments to -the array obtained calling L«C|/type/Array#method_append» on it. - - my $a; - say $a.append; # OUTPUT: «[]␤» - my $b; - say $b.append((1,2,3)); # OUTPUT: «[1 2 3]␤» - -=head2 method values - -Defined As: - - method values(--> List) - -Returns an empty List. - -=head2 method collate - -Defined As: - - method collate(--> Seq) - -TODO - -=head2 method cache - -Defined As: - - method cache(--> List) - -Provides a L representation of the object itself, calling -the method C on the instance. - -=end pod - -# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6 From 9dd09758b26725d9cfe4eb129f55768081001f09 Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Sat, 7 Apr 2018 11:05:51 +0200 Subject: [PATCH 19/20] Sorting by alphabetical order filenames --- lib/linguist/languages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index cff1e5bd21..5d94138379 100755 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -3380,9 +3380,9 @@ Perl: - ".t" filenames: - ack + - cpanfile - Makefile.PL - Rexfile - - cpanfile interpreters: - cperl - perl From 679bb4c3ed9db665aa674e6c08e8addcefb10c1d Mon Sep 17 00:00:00 2001 From: JJ Merelo Date: Wed, 11 Apr 2018 17:03:22 +0200 Subject: [PATCH 20/20] Moved from sample to test fixtures --- {samples => test/fixtures}/Perl 6/chromosome.pl | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {samples => test/fixtures}/Perl 6/chromosome.pl (100%) diff --git a/samples/Perl 6/chromosome.pl b/test/fixtures/Perl 6/chromosome.pl similarity index 100% rename from samples/Perl 6/chromosome.pl rename to test/fixtures/Perl 6/chromosome.pl