Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH 1/3]: Add named references



This isn't a self-reference because the local levels would be different.
And "self reference" in the error message should be hyphenated.
  typeset -n ref=var
  foo() { typeset -n var=ref }
  foo
  foo:typeset:1: var: invalid self reference
With -g it would be, however.

I wrote:
> On the subject references to array elements, it does seem both powerful and
> dangerous that subscripts are evaluated on reference. The subscript

This is fairly sane:
  typeset -n ref1=arr[ref2] 
  typeset -n ref2=ref1     
  echo $ref1
  zsh: math recursion limit exceeded: ref2

This seems useful:
  arr=()
  typeset -n ref=arr[1,0]
  ref=4
  ref=5

Similar:
  idx=1
  typeset -n ref=arr[idx++]
  echo $ref $ref

This is where I worry about security:
  arr=( 1 2 3 4)
  typeset -n ref='arr[$(echo 4)]'
  echo $ref
  typeset -p ref  # it was only evaluated late thanks to quotes
Maybe the code should have a safer mode for subscript evaluation. This
could be useful but it is asking for trouble.

Also can see this being useful:
  str='one two three'
  typeset -n ref=str[(w)2]
  ref=zwei

We already talked about this error message. But now it is a substring.
  export ref
  export: ref: can't change type of a named reference

Oliver




Messages sorted by: Reverse Date, Date, Thread, Author