Listing cross cases within lists in TCL

Hello everyone, I am new here forgive me if I omit something,

I have a problem which I can't seem to solve using TCL so I am posting it here.
Here it is :

I retrieve a UNKNOWN number of lists from an XML file. Let's skip the part where I retrieve these lists and say for example that you have these lists hereunder.

set list1        [list toto titi tutu]
set list2        [list pvt1 pvt2 pvt3]
set list3       [list I12  I13]

I wanted to store every cross cases that I can find i.e.

case 1 : toto pvt1 I12
case 2 : toto pvt1 I13
case 3 : toto pvt2 I12
etc....

I thought about a recursive call but I can't manage to get an algorythm right like passing the number of cases or the lists or making directly lists of lists maybe someone can help me?

Thank you, again if something is missing please tell me.
Regards

Noob

Logically, you are talking about a join, where you decompose your lists into lines, tuples, database rows, like 'list1 toto' and 'case3 I12', one for one. They you can join the file/table/relation of lists with the file/table/relation of cases using the 'join' tool or other join oriented tactics. You have a many-to-many thing going on in cases, but you could use associative arrays to store list ids by item id and look list id up by case item ids.

When the structure of the data is wrong, the problem is hard. Fix the structure, don't try to solve two problems at once. It is simple if all item ids are in one column/attribute.

Hi.

I looked at this as a situation in enumeration/combination. Judging by the sample output, I would address it with nested loops -- 3 in this case.

Perhaps I don't have a sufficient grasp of the problem ... cheers, drl

Wel, in some languages you can have lists of lists, so you can say:
for every list of list1 of lists
get every item of the list and for it
get every list of list2 of lists
get every item of that list
compare item of list of list1 with item of list of list2
but you are decomposing the lists over and over, so for efficiency, you can decompose both once, sort them and do the sort-optimized cartesian join in 'join' or you can put one decomposed list of lists into one associative array and look up every line of the other list of lists.

It is important to see the disorder of having peer data elements in two dimensions, across and down the page. Disorder generates more code and less speed.

Hi.

This seems to produce sample output:

#!/usr/bin/env tclsh

# @(#) tcl2     Demonstrate nested loops and lists.

set version [ info tclversion ]
set message " Hello, world from tclsh ($version), $auto_path"
puts ""
puts stdout $message
puts ""

set list1 [ list toto titi tutu ]
set list2 [ list pvt1 pvt2 pvt3 ]
set list3 [ list I12  I13 ]

foreach i  $list1 {
  foreach j $list2 {
    foreach k $list3 {
      puts "$i $j $k"
    }
  }
}

puts ""

exit 0

producing:

% ./tcl2

 Hello, world from tclsh (8.4), /usr/share/tcltk/tcl8.4 /usr/lib /usr/local/lib/tcltk /usr/local/share/tcltk /usr/lib/tcltk /usr/share/tcltk

toto pvt1 I12
toto pvt1 I13
toto pvt2 I12
toto pvt2 I13
toto pvt3 I12
toto pvt3 I13
titi pvt1 I12
titi pvt1 I13
titi pvt2 I12
titi pvt2 I13
titi pvt3 I12
titi pvt3 I13
tutu pvt1 I12
tutu pvt1 I13
tutu pvt2 I12
tutu pvt2 I13
tutu pvt3 I12
tutu pvt3 I13

Best wishes ... cheers, drl