Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Does Perl have anything that equates to the C++ this pointer?

Reply
Thread Tools

Does Perl have anything that equates to the C++ this pointer?

 
 
Calvin
Guest
Posts: n/a
 
      07-31-2004
use AI::Genetic;
my $ga = new AI::Genetic( -fitness => sub { rand },
-type => 'bitvector',
-population => 500,
-crossover => 0.89,
-mutation => 0.01,
-terminate => sub {
$ga->getFittest->score() > 0.9 } );
$ga->init(10);
$ga->evolve('rouletteTwoPoint', 100);
print "Best score = ", $ga->getFittest->score(), "\n";

The above code is taken from the man page for AI::Genetic (with a bit
of cleanup and modification).

What I'm trying to do is replace "sub { rand }" with something more
meaningful. But to do that I need to be able to say something, in
C++, to the effect of "this.genes()". Any help that could be provided
would be greatly apreciated.
 
Reply With Quote
 
 
 
 
Joe Smith
Guest
Posts: n/a
 
      07-31-2004
Calvin wrote:

> What I'm trying to do is replace "sub { rand }" with something more
> meaningful. But to do that I need to be able to say something, in
> C++, to the effect of "this.genes()". Any help that could be provided
> would be greatly apreciated.


Your subject line is very confusing. I assume your use of 'this' in
the subject is not the same as the regular English definition of the word.

sub foo {
my $this = shift; # Pointer to self
my $arg = shift; # First argument given to method call
$this->genes($arg); # Call another method in the same class
}

-Joe

P.S. Next time, post to comp.lang.perl.misc instead of comp.lang.perl
 
Reply With Quote
 
 
 
 
Calvin
Guest
Posts: n/a
 
      08-01-2004
Joe Smith <(E-Mail Removed)> wrote in message news:<UuSOc.188251$a24.171398@attbi_s03>...
>
> Your subject line is very confusing. I assume your use of 'this' in
> the subject is not the same as the regular English definition of the word.
>
> sub foo {
> my $this = shift; # Pointer to self
> my $arg = shift; # First argument given to method call
> $this->genes($arg); # Call another method in the same class
> }
>
> -Joe
>
> P.S. Next time, post to comp.lang.perl.misc instead of comp.lang.perl


Thanks for the help. As it turns out there was an undocumented
variable that's passed into the function in question that does the job
much more efficiently than the work-around I was thinking of.

Calvin
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Equates or Synonyms? Mike Copeland C++ 14 11-29-2011 12:10 PM
FAQ 4.18 Does Perl have a Year 2000 or 2038 problem? Is Perl Y2K compliant? PerlFAQ Server Perl Misc 0 01-06-2011 11:00 AM
Multiple equates jzakiya Python 27 12-04-2008 07:21 PM
Refilling your printer cartridges now equates to committing a crime? XP NZ Computing 8 09-17-2005 03:55 AM
Does Ruby have anything like isprint? Martin Kahlert Ruby 3 12-02-2004 10:48 AM



Advertisments