Posted to tcl by sebres at Tue Jul 24 13:59:34 GMT 2018view raw

  1. The question is: should the TIP 283 provide an opportunity to switch back to the caller-resolution: caller (special-area below) wins, so interacts like a global here, and decides which unknown should be used).
  2. Possibly like an option `configure ?-resolve caller|ensemble|...?` or similar.
  3.  
  4. If the TIP, as it currently is, gets accepted, someone can't implement anymore the things like in example.
  5.  
  6. ```tcl
  7. proc create-request {} {
  8. catch {namespace delete ::req}
  9. namespace eval ::req {
  10. namespace ensemble create
  11. namespace ensemble configure [namespace current] -prefixes 1 -unknown inplace-mixin
  12. }
  13. return ::req
  14. }
  15.  
  16. namespace eval special-area {
  17. proc inplace-mixin {args} {
  18. ::puts "we are in inplace-mixin, called $args"
  19. # reset handler (or set to other):
  20. namespace ensemble configure [lindex $args 0] -unknown ""
  21. # create input/output handler:
  22. namespace eval [lindex $args 0] {
  23. proc puts {args} {::puts [list RESPONSE {*}$args]}
  24. proc gets {args} {return INPUT; #::gets}
  25. namespace export *
  26. }
  27. # uplevel $args
  28. }
  29. }
  30.  
  31. namespace eval special-area-test {
  32. proc log {args} {::puts "# \[DEBUG\] [info level [info level]]"}
  33. namespace export log
  34. proc inplace-mixin {args} {
  35. log "we are in inplace-mixin of test, called $args"
  36. # reset handler (or set to other):
  37. namespace ensemble configure [lindex $args 0] -unknown ""
  38. # create log handler:
  39. namespace eval [lindex $args 0] [list namespace import [namespace current]::*]
  40. # create input/output handler:
  41. namespace eval [lindex $args 0] {
  42. proc puts {args} {log $args}
  43. proc gets {args} {return TEST; #::gets}
  44. namespace export *
  45. }
  46. # uplevel $args
  47. }
  48. }
  49.  
  50. set code [list {r} { $r puts "test response for [$r gets]" }]
  51. apply [linsert $code end [namespace current]::special-area] [create-request]
  52. apply [linsert $code end [namespace current]::special-area-test] [create-request]
  53. ```
  54.  

Comments

Posted by sebres at Tue Jul 24 15:46:33 GMT 2018 [text] [code]

Just small amend, as the consistence question: ```tcl % proc unknown {args} {::puts global} % namespace eval foo {namespace unknown unknown; proc unknown {args} {::puts local}} % namespace inscope foo {some-thing} local % foo::some-thing global # and if it'll be an ensemble with same unknown-handler: % foo some-thing ????? ``` Therefore, I would like to make it consistently for all unknown-handler, and provide an option to decide... Among other things to allow: ```tcl namespace eval xxx {foo::boom; bar::boom} namespace eval xxx { foo boom; bar boom } ``` where "foo" can call unknown in caller, "bar" can call unknown in ensemble/namespace. In this case "foo boom" invokes method "boom" of "xxx", and "bar boom" invokes its own "boom" method (both after unknown callee); And the strategy is simple: only the namespaces/ensembles know, what they should call, only the caller knows about its unknown handling.