Posted to tcl by dgp at Fri Jan 16 16:50:20 GMT 2015view raw

  1.  
  2. % package require Itcl 3
  3. 3.4
  4. % itcl::class Base {
  5. method do {args} {eval $args}
  6. method foo {} {bar}
  7. method bar {} {puts Base::bar}
  8. }
  9. % itcl::class Derived {
  10. inherit Base
  11. method bar {} {puts Derived::bar}
  12. }
  13. % proc bar {} {puts proc::bar}
  14. % Derived demo
  15. demo
  16.  
  17. First we demo the expected "polymorphic" dispatch.
  18. An implicit "$this" is prepended to "bar" so we
  19. get the derived "bar" method called.
  20.  
  21. % demo foo
  22. Derived::bar
  23.  
  24. Then we demo that sticking an [eval] in the middle
  25. doesn't change that
  26.  
  27. % demo do bar
  28. Derived::bar
  29.  
  30. The builtin method "info" does the same -- we get the
  31. heritage info for the $this object.
  32.  
  33. % demo info heritage
  34. ::Derived ::Base
  35.  
  36. ***BUT!!!!*** if we stick an [eval] in the middle,
  37. things change!
  38.  
  39. % demo do info heritage
  40. ::Base
  41.  
  42. WTF!!!
  43.  
  44. Itcl test info-4.3b insists this is the expected
  45. behavior, but that makes the info method bizarrely
  46. magical in suspending the rules applied to all
  47. other methods.
  48.  
  49. Porting to Itcl 4 makes use of TclOO machinery, and trying to
  50. force this magic into that is leading to a royal mess!
  51. The attempts have broken other things.
  52.  
  53. Someone please explain this nonsense.
  54.