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

RE: named references



This does not touch everything (I need some time to swallow the rest :-)

>
> > So I'd suggest adding to the union:
> >         HashNode ref;           /* value if declared nameref
> (PM_NAMEREF) */
>
> Using a pointer for the reference is something I considered when I
> started out. The problem is how to deal with references to unset
> parameters.

... and ...

>
> > I don't think that's necessary, but it raises the question of
> what really
> > happens when a reference-to-a-reference is made.  That is:
> >
> >         typeset v1 v2
> >         typeset -n r1=v1
> >         typeset -n r2=r1
> >         typeset -n r1=v2
> >
> > At this point, is r2 still a reference to v1, or has it become
> a reference
> > to v2?  That is, is r1 dereferenced at the time of assignment to r2, or
> > not until time of dereference of r2?  This ...
>
> not until time of dereference of r2. r2 will be and will remain a
> reference to `r1' whatever r1 is whether that be unset, another
> reference, an array or scalar.
>

What happens in this case:

foo() {
  typeset -n r=v
  local v=foo
  echo $r
}

v=bar
foo

I.e. does r refer to outer v ("by address" could you say) or to inner v ("by
name" would it be then)? The latter would be badly broken; but to implement
the former you must have reference to pm not the name.

-andrej



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