Posted to tcl by aspect at Thu Mar 19 01:05:34 GMT 2015view pretty

proc threet {} {
    tailcall ::foreach _ {1 2 3} {puts t:[incr three]}
}

proc threeu {} {
    uplevel 1 [list ::foreach _ {1 2 3} {puts u:[incr three]}]
}

proc aa {} {
    threet
    threeu
    expr {$three == 6}
}

puts aa:[aa]        ;# aa:1 - as expected

namespace eval ens {
    namespace ensemble create
}
namespace ensemble configure ens -map {threet ::threet threeu ::threeu}

proc ab {} {
    ens threet
    ens threeu
    expr {$three == 6}
}

puts ab:[ab]        ;# ab:1 - as expected

set map [namespace ensemble configure array -map]
dict set map threet ::threet
dict set map threeu ::threeu
namespace ensemble configure array -map $map

proc ac {} {
    array threet
    array threeu
    expr {$three == 6}
}

puts ac:[ac]        ;# "ac:" - explain that!

if 0 {
    # full output:
    t:1
    t:2
    t:3
    u:4
    u:5
    u:6
    aa:1
    t:1
    t:2
    t:3
    u:4
    u:5
    u:6
    ab:1
    u:1    *
    u:2    *
    u:3    *
    t:1    *
    t:2    *
    t:3    *
    ac:    *
}