txt: ## is-20rw.md
  is rw
  
  Combined from primary sources listed below.
  
  # [In Type system](#___top "go to top of document")[§](#(Type_system)_trait_is_rw "direct link")
  
  See primary documentation
  [in context](/language/typesystem#trait_is_rw)
  for **trait is rw**.
  
  ```raku
  sub trait_mod:<is>(Mu:U $type, :$rw!)
  ```
  
  The [trait](/type/Sub#Traits) `is rw` on a class will create writable accessor methods on all public attributes of that class.
  
  ```raku
  class C is rw {
      has $.a;
  };
  my $c = C.new.a = 42;
  say $c; # OUTPUT: «42␤»
  ```
  
  # [In Routine](#___top "go to top of document")[§](#(Routine)_trait_is_rw "direct link")
  
  See primary documentation
  [in context](/type/Routine#trait_is_rw)
  for **trait is rw**.
  
  ```raku
  multi trait_mod:<is>(Routine $r, :$rw!)
  ```
  
  When a routine is modified with this trait, its return value will be writable. This is useful when returning variables or writable elements of hashes or arrays, for example:
  
  ```raku
  sub walk(\thing, *@keys) is rw {
      my $current := thing;
      for @keys -> $k {
          if $k ~~ Int {
              $current := $current[$k];
          }
          else {
              $current := $current{$k};
          }
      }
      $current;
  }
  
  my %hash;
  walk(%hash, 'some', 'key', 1, 2) = 'autovivified';
  
  say %hash.raku;
  
  ```
  
  produces
  
  ```raku
  ("some" => {"key" => [Any, [Any, Any, "autovivified"]]}).hash
  
  ```
  
  Note that `return` marks return values as read only; if you need an early exit from an `is rw` routine, you have to use `return-rw` instead.
  