Hi!

----

While developing an application we hit a couple of problems with
"typeset -m" (=move/rename variable). The basic idea is to create a
variable locally and only move it into the (compound) variable array
of the caller if certain conditions are met.
The following testcase shows the problem:
-- snip --

function add_eval
{
        nameref pos=$1
        source /dev/stdin <<<"$2"
        typeset -m pos=addvar
        return 0
}


function do_global_plain
{
        print "# do global"
        add_eval global_tree[9].fish "typeset -i addvar=4"
        
        print -v global_tree
        return 0
}

function do_local_plain
{
        print "# do local"
        compound -A local_tree

        add_eval local_tree[9].fish "typeset -i addvar=4"
        
        print -v local_tree
        return 0
}

function do_global_throughnameref
{
        print "# do global_throughnameref"
        nameref tr=global_tree
        add_eval tr[9].fish "typeset -i addvar=4"
        
        print -v tr
        return 0
}

function do_local_throughnameref
{
        print "# do local_throughnameref"
        compound -A local_tree
        nameref tr=local_tree

        add_eval tr[9].fish "typeset -i addvar=4"
        
        print -v tr
        return 0
}

compound -A global_tree
do_global_plain "$@"
do_local_plain  "$@"

unset global_tree
compound -A global_tree
do_global_throughnameref "$@"
do_local_throughnameref "$@"
-- snip --

ast-ksh.2011-02-08 prints this:
-- snip --
$ ksh93 ../m1.sh
# do global
(
        [9]=(
                fish=4
        )
)
# do local
(
        )
# do global_throughnameref
(
        )
# do local_throughnameref
(
        )
-- snip --
... but AFAIK it should print the following output four times:
-- snip --
(
        [9]=(
                typeset -i fish=4
        )
)
-- snip --

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [email protected]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)

_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to