Prev: nice ticketing system in tcl?
Next: tcl for CGI?
From: Yaron on 10 Jun 2010 06:11 Hi, I have multidimensional array in a proc and which to return it. I.e Is there is a way to get 2 or 3 dimensional array from a procedure? Best Regards, Yaron
From: jr4412 on 10 Jun 2010 06:45 On Jun 10, 11:11 am, Yaron <cyaro...(a)yahoo.com> wrote: > Hi, > > I have multidimensional array in a proc and which to return it. > > I.e Is there is a way to get 2 or 3 dimensional array from a > procedure? > > Best Regards, > > Yaron upvar? eg. proc myProc {var} { upvar $var arr set arr(dim1,dim2) somevalue .... }
From: Harald Oehlmann on 10 Jun 2010 10:58 On 10 Jun., 12:11, Yaron <cyaro...(a)yahoo.com> wrote: > I.e Is there is a way to get 2 or 3 dimensional array from a > procedure? There might be confusion in the naming. A two dimensional array in the mathematical way may be represented as a list of lists: set a { { 0.0 0.1 } { 1.0 1.1 } } This may be returned by "return $a". If you speak about TCL array: ( multi-dimensional is done here often by special indexes set arr(dim1,dim2) v) You can not pass then in an effective manner back from a procedure: return [array get arr] returns it as list, what is quite ineffective. So, you may create them in the caller scope and use upvar to process it. Another possiblility would be to use a nested dict. set a [dict create] dict set a dim1 dim2 v return $a This is effective and IMHO very elegant, if you have survived the clumsy syntax... Hope this helps, Harald
|
Pages: 1 Prev: nice ticketing system in tcl? Next: tcl for CGI? |