On Mon, May 27, 2013 at 3:08 PM, Roland Mainz <[email protected]> wrote:
> The following example...
> -- snip --
> $ ksh -c 'typeset -a ar=( 2 3 4 ) ; function fn { nameref n=$1 ; print
> -- "$n" ; } ; function main { integer i ; for ((i=0 ; i < ${#ar[@]} ;
> )) ; do fn ar[i++]  ; done ; } ; main ; true'
> -- snip --
> ... should AFAIK print...
> --- snip --
> 2
> 3
> 4
> -- snip --
> ... but ast-ksh.2013-05-24 runs in an endless loop (warning (mostly
> for myself): Any test module should have a 2nd integer aborting the
> endless loop) printing newlines...
>
> The workaround is to replace the ar[i++] with ar[$((i++))], e.g. ...
> -- snip --
> $ ksh -c 'typeset -a ar=( 2 3 4 ) ; function fn { nameref n=$1 ; print
> -- "$n" ; } ; function main { integer i ; for ((i=0 ; i < ${#ar[@]} ;
> )) ; do fn ar[$((i++))]  ; done ; } ; main ; true'
> 2
> 3
> 4
> -- snip --
> ... so that the nameref only gets a "static" string as index... the
> only issue is that this requires an internal integer-to-string
> conversion which is IMO unneccesary...

Uhm... Ok... here is a related issue... it seems the arithmetric
expression is exected in the wrong scope:
-- snip --
$ ksh -o nounset -c 'typeset -a ar=( 2 3 4 ) ; function fn { nameref
n=$1 ; print -- "$n" ; } ; function main { integer i ; for ((i=0 ; i <
${#ar[@]} ; )) ; do fn ar[i++]  ; done ; } ; main ; true' 2>&1 | head
-2
/home/test001/bin/ksh: main[1]: fn[1]: typeset: i: parameter not set
/home/test001/bin/ksh: main[1]: fn[1]: typeset: i: parameter not set
-- snip --
... AFAIK the issue is that the arithmetic expression should be
executed in the scope of the calling function... or we simply say that
this is not allowed and names passed to namerefs must not contain any
arithmetic expressions...

----

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]
http://lists.research.att.com/mailman/listinfo/ast-developers

Reply via email to