proc lexpr {a op b} {
     set res {}
     set la [llength $a]
     set lb [llength $b]
     if {$la == 1 && $lb == 1} {
         set res [expr $a $op $b]
     } elseif {$la==1} {
         foreach j $b {lappend res [lexpr $a $op $j]}
     } elseif {$lb==1} {
         foreach i $a {lappend res [lexpr $i $op $b]}
     } elseif {$la == $lb} {
         foreach i $a j $b {lappend res [lexpr $i $op $j]}
     } else {error "list length mismatch $la/$lb"}
     set res
 }#--- Testing: % lexpr {{1 2} {3 4}} * 2
 {2 4} {6 8}
 % lexpr {{1 2} {3 4}} + 0.1
 {1.1 2.1} {3.1 4.1}
 % lexpr {{1 2} {3 4}} * {{10 100} {1 0}}
 {10 200} {3 0}
 % lexpr {1 2 3} + {10 20 30}
 11 22 33
 % lexpr {1 2 3} * {4 5 6 7}
 error: list length mismatch 3/4See also

