librasteve / raku-Dan

Top level raku Data ANalysis Module
Artistic License 2.0
7 stars 2 forks source link

Decide "immutability" strategy - viz. Math::Matrix #5

Open librasteve opened 2 years ago

librasteve commented 2 years ago

Currently only splice() and .data[] = are a Series/DataFrame mutators So to make these objects read only (ie a soft version of immutable) can be done this way:

  1. add a new has Bool $!ro = True; attr
  2. add a new override method rw { $!ro = False } (you can manually override ro behaviour twiw)
  3. and a new reset method ro { $!ro = False }
  4. and a new clone method clone { ... } with :rw adverb
  5. error if splice() or data[]= operations are attempted if $!ro [ie. splice is forbidden]
  6. check that dyadic operations now work like this c = a.concat(b); [ie. a,b immutable]
  7. implement this by psuedo-code:
method concat( \b ) {
    my c = a.clone( :rw );
    c.concat(b);      #the mutating concat we have now (which may contain mutating c.splice(b) operations)
    c.ro;
    c
}

oh and check grep

there are some interesting comments here

maybe concat can just use concat eg.. method concat( @b ) { |self, |@b }

oh and prevent write access to .data (eg. wrapper)