-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Additions to the Perl family of languages #4066
Changes from all commits
1732850
9d57d6f
13d5ebd
d3cf280
f437f0c
2d8cd85
3466074
f46e876
ff4f40a
c1796bc
f1491a6
22bd264
0dca075
a3aed35
2d85463
cc2e8a7
4eaa4b3
5601865
6ce294d
072e774
648e8cb
0bd8636
a33ad3e
9dd0975
5f74ba4
52b5b91
2b46d79
679bb4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3386,6 +3386,8 @@ Perl: | |
- ".psgi" | ||
- ".t" | ||
filenames: | ||
- Makefile.PL | ||
- Rexfile | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In-the-wild usage is a little questionable... only ~155 results, although they appear to be well-distributed across users/repositories (which technically meets the criteria of "being used in hundreds of repositories"). I think it's okay, particularly since it's an uncommon filename unlikely to cause conflict. @pchaigno, thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll defer to @lildude 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Problem here is that Rexfile was actually in the Perl6 field (my fault: https://github.com/github/linguist/pull/2005/files). It should better be here, Rexfile is in no way Perl6 code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine. It slipped under the radar before when it was initially added so no point removing it now. |
||
- ack | ||
- cpanfile | ||
interpreters: | ||
|
@@ -3409,8 +3411,6 @@ Perl 6: | |
- ".pm" | ||
- ".pm6" | ||
- ".t" | ||
filenames: | ||
- Rexfile | ||
interpreters: | ||
- perl6 | ||
aliases: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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???"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use strict; | ||
use warnings; | ||
use ExtUtils::MakeMaker; | ||
|
||
WriteMakefile( | ||
NAME => 'Algorithm::Evolutionary::Simple', | ||
AUTHOR => 'JJ Merelo <[email protected]>', | ||
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-*' }, | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is redundant, because it'll be matched against the
*.pl
file extension.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Alhadis That extension is shared between Perl, Perl 6, and Prolog. Adding the
Makefile.PL
might improve detection for that particular case. Are we sureMakefile.PL
is always Perl and not Perl 6 though?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I stand corrected, then. 😉 @pchaigno knows more about the Bayesian classifier than I do.
I don't recall ever seeing a Perl 6 version of
Makefile.PL
... it's always ever been used by Perl 5 modules downloaded/installed from CPAN. I could be wrong though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure. Perl6 has pretty much normalized to .pl6 or .p6 now. It's not using this particular file, either. This is the repo for all modules https://github.com/moritz/perl6-all-modules/search?utf8=%E2%9C%93&q=%22Makefile.PL%22&type= and it's not there even once. Makefile.PL is kind of a Rakefile used for some CPAN distributions; Perl6 uses zef and META6.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know much about the classifier either, but in this particular case, there's a specific filename strategy before we reach the classifier.
PS: Not sure why I keep using "particular case" today...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping... Is there anything missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it looks fine to me. For the sake of quicker review, it might be better to omit
.pod6
since #3366 is more appropriate for discussion its inclusion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem there is that it might need a bit (or a lot) of work. If you want, you can close that one and I'll redo this one, and then that one...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eliminated
.pod6
. I can try and work on that one, although I can't add or modify that pull request...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't worry about #3366. :) I believe that PR needs formal approval from GitHub staff more than anything.