develooper Front page | perl.perl6.language | Postings from July 2005

How do I... create a value type?

Thread Next
From:
Ingo Blechschmidt
Date:
July 11, 2005 06:21
Subject:
How do I... create a value type?
Message ID:
datrgd$rul$2@sea.gmane.org
Hi,

  my $x = 42;
  my $y = $x;
  $y++;
  say $x;         # Still 42, of course


  class Foo {
    has $.data;
    method incr () { $.data++ }

    # Please fill in appropriate magic here
  }

  my Foo $x .= new(:data(42));
  my Foo $y  = $x;
  $y.incr();
  say $x.data;    # Should still be 42
  say $x =:= $y;  # Should be false


--Ingo

-- 
Linux, the choice of a GNU | The computer revolution is over.
generation on a dual AMD   | The computers won.
Athlon!                    | -- Eduard Bloch


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About