Difficult problem to solve: Tcl 7.3 to Tcl 8.0p2 Array of Array Problem 
Author Message
 Difficult problem to solve: Tcl 7.3 to Tcl 8.0p2 Array of Array Problem

I have found a problem in switching form Tcl 7.3 to Tcl 8.0 in the area
of multi-dimensional arrays formatted as follows:

array1(hi)
array1(hello)
array2(hi2)
array2(hello2)

arrayofarray(1)
arrayofarray(2)

BTW the array of arrays was created by doing this, which also doesn't
work in Tcl 8.0:

ArrayCopy arrayofarray(1) array1
ArrayCopy arrayofarray(2) array2

This would in essence create the arrayofarray to be
arrayofarray(1)(hi) value
arrayofarray(1)(hello) value
arrayofarray(2)(hi2) etc.

In Tcl 7.3 this was allowed:
  Performing an array names on arrayofarray gives {1 2}
  Performing an array names on array1 gives {hi hello}

  ArrayCopy aTmpArray arrayofarray(1)
                          aDst             aSrc

The above command would put array1 into aTmpArray to access {hi hello}
or whatever variable we wanted.

In Tcl 8.0p2:

Now when we do the:

Arraycopy aTmpArray arrayofarray(1)

We get:

can't set "aDst(hi)": variable isn't array

I believe in Tcl 7.3 the set command didn't care what the name of the
variable was, and it could have the (brackets) in the name without
thinking it was an array because it was being represented by another
name.  And Tcl 8.0 patch 2 takes the variable name that has the
(brackets) in it literally and makes it an array, and then can't perform
the multi array operation e.g. set array(1)(1) value.

I could not do this directly in 7.3 either
    set array(1)(1) value

and have the interpreter think the above name was an array, however
through the ArrayCopy routine/ fancy name subsititution and upvarring it
we were able to store and retrieve these arrays within arrays along with
the values.

Does anyone know of an elegant workaround or a fix to keep the
functionality the same in Tcl 8.0 in regards to this problem?????
PLEASE HELP...  We have 4 important scripts that depend on this and we
are moving to Tcl 8.0 in less than a week.  Otherwise I will have a lot
of extra coding to do..... :-).



Sun, 31 Mar 2002 03:00:00 GMT  
 Difficult problem to solve: Tcl 7.3 to Tcl 8.0p2 Array of Array Problem

Quote:

> I have found a problem in switching form Tcl 7.3 to Tcl 8.0 in the area
> of multi-dimensional arrays formatted as follows:

> array1(hi)
        ...
> arrayofarray(1)

First of all, the syntax for arrays became more strict in 8 (I'm
not sure at which version this started).  You used to be able to
upvar into an array index, and then use that as an array.  This
is no longer legal (it was never 'legal' before, just possible).

The proper way to do multi-dim arrays is:
        set ary(1,1) {foo}
or      array set ary [list 1,1 foo 1,2 bar]

Note that this is still string based, and "1, 1" is not the same
as "1,1" or "1,01", but it works for most peoples needs.  With
the new Tcl_Obj mechanism, the use of lists, and lists of lists
became MUCH more efficient.  If you coded such that these structures
are localized through accessor functions, then you can redo that
back-end with something that is a combo of lists and arrays.

--
   Jeffrey Hobbs                          The Tcl Guy
   jeffrey.hobbs at scriptics.com         Scriptics Corp.



Sun, 31 Mar 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. 7.3 TCL - regexp problem

2. Key Maping problem TCL 7.3 TK 4.0 on irix 5.3

3. Q: TCL 7.3 malloc/free problems on a Cray

4. Problem with with Array of U8 to Array of Array of Boolean

5. Tcl pipes with Tcl 7.3

6. Tcl 7.3 pass infor to Tcl 8.0

7. porting wishx under tcl 7.3 to tcl 7.5

8. regsub in tcl 7.3 and tcl 7.4

9. ANNOUNCE: Tknt36r6beta4 (Tcl 7.3/Tk 3.6/Tcl-DP 3.2) for NT

10. Problems receiving an array from a tcl webservice

11. Tcl Array Looping Problem

12. Question On TCL-DP: Problem using Arrays with Callbacks

 

 
Powered by phpBB® Forum Software