[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tcl list functions



Hi Haobo,

Thanks for tackling another question, you help out all of us on the list a
lot!

I looked at the srm.tcl code for setting an array:
       $self array set stats_ [list    (etc)
I am now trying to initialize an array this way in an init function, but
I'm having trouble with two parts that aren't covered in the file.

1) I'm trying to add this new array to the Simulator class, so I need to
have it initialized in the 'init' function.  What I wrote was the
following, but it doesn't work:

Simulator instproc init {args} {
  $self array set two-d [$self make-array 10]
  eval $self next $args
}

2) I'm trying to initialize 10 lists to null (later as the program runs,
these lists would be added to).  

Simulator instproc make-array {n} {
	$self array set pGroupList_  ""
	for {set i 1} {$i <= $n} {incr $i} {
	$self array set pGroupList_($i) [list ""]
}

Any ideas how to deal with this?  I'm going to check if we have
Ousterhout's book in our library tomorrow.

Thanks for your help!
Lori

On Mon, 24 May 1999, Haobo Yu wrote:

> It should be easier to implement a 2d array using tcl's 1d array. E.g.: 
> 	set a(1:2) 0
> SRM's retransmission timer management is an example. Also see Ousterhout's
> tcl book. 
> 
> - Haobo
> 
> On Mon, 24 May 1999, Lori Flynn wrote:
> 
> > I'd like to make a 2-d array in tcl. I'm trying to use what appear to be
> > built-in tcl list functions (llength, lindex, concat).  Does anyone know
> > how?
> > 
> > Thanks,
> > Lori
> > 
> > 
> 
>