Posted to tcl by egavilan at Fri Apr 26 00:52:01 GMT 2024view raw

  1. proc ::tcl::dict::pop {var args} {
  2. upvar 1 $var lvar
  3. ::set value [get $lvar {*}$args]
  4. unset lvar {*}$args
  5. return $value
  6. }
  7. namespace ensemble configure ::dict -map [dict merge \
  8. [namespace ensemble configure ::dict -map] \
  9. [dict create pop ::tcl::dict::pop]]
  10.  
  11.  
  12. # usage:
  13. # % set var {a 1 b 2 c 3}
  14. # a 1 b 2 c 3
  15. # % dict pop var a
  16. # 1
  17. # % set var
  18. # b 2 c 3
  19. # % dict pop var c
  20. # 3
  21. # % set var
  22. # b 2