Guest User

Untitled

a guest
Nov 18th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. siddhant@siddhant-laptop:~/perl6 code$ cat class-point
  2. use v6;
  3.  
  4. class Point {
  5. has $.x;
  6. has $.y;
  7. has $.d;
  8.  
  9. method distance_from_origin {
  10. $!d = sqrt($!x**2 + $!y**2);
  11. }
  12. }
  13.  
  14. my $A = Point.new;
  15.  
  16. $A.x = 1;
  17. $A.y = 2;
  18.  
  19. say $A.distance_from_origin;
  20. siddhant@siddhant-laptop:~/perl6 code$ perl6 class-point
  21. Cannot assign to a readonly variable or a value
  22. in block <anon> at class-point:1
Add Comment
Please, Sign In to add comment