cc: [email protected]
Subject: Re: [ast-developers] Problems with "typeset -m" to move a  
function-local variable into a  function-local compound variable array of the 
calling function...
--------

> 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
> 

This is fixed for the next update.  However,  do local output the following:

# do local
(
 [9]=(
 )
)

I am still investigating why.  However, when it goes to execute
        typeset -m pos=addvar
the function do_local_plain scope is not visible.

All the others give the output you expected.

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

Reply via email to