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

Discussion in 'Perl' started by Calvin, Jul 31, 2004.

  1. Calvin

    Calvin Guest

    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.
     
    Calvin, Jul 31, 2004
    #1
    1. Advertising

  2. Calvin

    Joe Smith Guest

    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
     
    Joe Smith, Jul 31, 2004
    #2
    1. Advertising

  3. Calvin

    Calvin Guest

    Joe Smith <> 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
     
    Calvin, Aug 1, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jzakiya

    Multiple equates

    jzakiya, Nov 17, 2008, in forum: Python
    Replies:
    27
    Views:
    607
    Andreas Waldenburger
    Dec 4, 2008
  2. Mike Copeland

    Equates or Synonyms?

    Mike Copeland, Nov 27, 2011, in forum: C++
    Replies:
    14
    Views:
    472
    Jorgen Grahn
    Nov 29, 2011
  3. Martin Kahlert

    Does Ruby have anything like isprint?

    Martin Kahlert, Dec 2, 2004, in forum: Ruby
    Replies:
    3
    Views:
    373
    Robert Klemme
    Dec 2, 2004
  4. PerlFAQ Server
    Replies:
    0
    Views:
    393
    PerlFAQ Server
    Jan 6, 2011
  5. Peter
    Replies:
    18
    Views:
    301
    James Kanze
    Sep 2, 2013
Loading...

Share This Page