1)
typeset -T oset=(
    typeset -A s

    function add {
        nameref var=${.sh.name}
        typeset elem
        for elem; do
            : ${var.s[$elem]:=0}
        done
    }
)
oset foo bar
foo.add a b
bar.add d e
print "${foo.s[*]} : ${!foo.s[*]} \n${bar.s[*]} : ${!bar.s[*]}"

gives:
0 0 0 0 : a b d e
0 0 0 0 : a b d e

as though s is being shared.

2)
typeset -T olist=(
    typeset -a l
)
olist foo
foo.l[1]=x
print "${!foo.l[*]}"

gives:
0 1
(A spurious '0' index is created)

3)
typeset -T oset=( typeset -A foo )
oset bar
bar.foo=( [a]=b [c]=d )
print ${!bar[*]}

gives:
0

4)
(typeset -T foo=( integer i ) )
typeset -T foo=( integer i )

gives:
typeset: foo: type cannot be redefined
despite the first typeset nominally being done in a subshell.

        John
-- 
John DuBois     [email protected]   KC6QKZ/AE
I wish to God these calculations had been executed by steam. - Charles Babbage
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to