home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / tcl / 1029 < prev    next >
Encoding:
Internet Message Format  |  1992-07-22  |  1.0 KB

  1. Path: sparky!uunet!ogicse!uwm.edu!cs.utexas.edu!tamsun.tamu.edu!inetg1!cgp
  2. From: cgp@Arco.COM (Chris Phillips  (214) 754-6419)
  3. Newsgroups: comp.lang.tcl
  4. Subject: uplevel/upvar and trace
  5. Message-ID: <1992Jul22.203440.15926@Arco.COM>
  6. Date: 22 Jul 92 20:34:40 GMT
  7. Article-I.D.: Arco.1992Jul22.203440.15926
  8. Distribution: usa
  9. Organization: ARCO Oil and Gas Company
  10. Lines: 47
  11.  
  12. Apparently there is no difference in
  13.  
  14.     proc s1 {n i op} {
  15.         set z [uplevel set [set n]]
  16.         puts stdout $z
  17.     }
  18. and
  19.     proc s2 {n i op} {
  20.         upvar $n z
  21.         puts stdout $z
  22.     }
  23.  
  24. For example,
  25.  
  26. tcl>trace var a w s1
  27. tcl>set a 5
  28. 5
  29. tcl>trace vdel a w s1
  30. tcl>trace var a w s2
  31. tcl>set a 5
  32. 5
  33. tcl>
  34.  
  35. However, the following extensions to arrays doesn't work
  36. for the upvar version:
  37.  
  38.     proc a1 {n i op} {
  39.         set z [uplevel set [set n]($i)]
  40.         puts stdout $z
  41.     }
  42.     proc a2 {n i op} {
  43.         upvar [set n]($i) z
  44.         puts stdout $z
  45.     }
  46.  
  47. tcl>trace var b(1) w a1   
  48. tcl>set b(1) 2
  49. 2
  50. tcl>trace vdel b(1) w a1
  51. tcl>trace var b(1) w a2
  52. tcl>set b(1) 2
  53. Error: can't set "b(1)": access disallowed by trace command
  54. tcl>
  55.  
  56. Why?
  57.  
  58. Chris
  59.