Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 56306d3c8d2c1de06f0b00b5ad2b4cd85a649ad7
Ticket: 1881766fffffffffffffffffffffffffffffffff
Mutability
User & Date: ferrieux on 2008-01-29 12:11:41
Changes

  1. assignee changed to: "msofer"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    This experimental patch, which could make it to a TIP eventually, adds optional "mutability" to container values (Lists, but the same could be done to Dicts).
    
    This means that when explicitly requested by the programmer (by the command prefix "mutant"), in-place operations may occur regardless of the sharedness of the object. Hence several other values may be simultaneously updated.
    
    The purpose is to allow passing a deeply nested substructure and modifying it in-place, without knowledge of its surroundings.
    
    Here are a few examples illustrating usage:
    
      # create a mutable
      set m [mutable [list 1 2 3]]
      # let another var hold it
      set n $m
    
      # mutate it
      mutant lappend m 4
      puts $m --> 1 2 3 4
      puts $n --> 1 2 3 4
    
      # use it like an immutable in all unaware code (no "mutant")
      lappend n 5 ;# this forks an immutable snapshot
      puts $n --> 1 2 3 4 5
      puts $m --> 1 2 3 4 (mutable value untouched)
    
      # now a deeper substructure
      set m [mutable [list 1 2 3]]
      set n [mutable [list 4 5 6]]
      set p [mutable [list 7 8 9]]
      mutant lappend m $n
      mutant lappend n $p
      puts $m --> 1 2 3 {4 5 6 {7 8 9}}
      mutant lset p 1 foo
      puts $m --> 1 2 3 {4 5 6 {7 foo 9}}
    
      # the cases that are not yet forbidden, but shoud shortly be:
      set l [list 1 2 3 [mutable [list 4 5 6]]] ;# contagion violation
      set m [mutable [list 1 2 3]];mutant lappend m $m; # cycle
    
  4. foundin changed to: "TIP Implementation"
  5. is_private changed to: "0"
  6. priority changed to: "5 Medium"
  7. resolution changed to: "None"
  8. status changed to: "Open"
  9. submitter changed to: "ferrieux"
  10. subsystem changed to: "10. Objects"
  11. title changed to: "Mutability"
  12. type changed to: "Patch"