home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / tcl / 2281 < prev    next >
Encoding:
Text File  |  1993-01-03  |  1.2 KB  |  34 lines

  1. Newsgroups: comp.lang.tcl
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!brucet
  3. From: brucet@extro.ucc.su.OZ.AU (Bruce Tulloch)
  4. Subject: How do I return an array as a list ?
  5. Message-ID: <brucet.726113122@extro.ucc.su.OZ.AU>
  6. Keywords: array list procedure
  7. Sender: news@ucc.su.OZ.AU
  8. Nntp-Posting-Host: extro.ucc.su.oz.au
  9. Organization: Sydney University Computing Service, Sydney, NSW, Australia
  10. Date: Mon, 4 Jan 1993 02:05:22 GMT
  11. Lines: 21
  12.  
  13. Tcl Programmers,
  14.  
  15. I'm new to tcl so maybe I've missed something, but is there an easier or 
  16. more elegant way write a procedure which returns the contents of an array 
  17. which exists in the context of the caller (or another explicit context) 
  18. as a list of {index value} pairs than this ?
  19.  
  20. proc arrayToList {array {context 1}} {
  21.     set names [uplevel $context array names $array]
  22.     if {![llength $names]} {return}
  23.     foreach name $names {
  24.         set item [echo $name [uplevel $context echo $[uplevel $context echo $array]($name)]]
  25.         lappend contents $item
  26.     }
  27.     return $contents
  28. }
  29.  
  30. thank, bruce
  31. -- 
  32.           bruce tulloch sydney australia - brucet@extro.ucc.su.oz.au
  33. ***complex problems have straight forward, easy to understand wrong answers***
  34.