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

Re: All functions are equal...or ?



From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
Subject: Re: All functions are equal...or ?
Date: Thu, 15 Feb 2007 19:29:37 -0800

Hi Bart,

 thanks a lot ! This makes it MUCH clearer to me!
 :)

 keep zshing!
 mcc


> On Feb 15,  4:38am, Meino Christian Cramer wrote:
> >
> > lww () {
> [...]
> >                 cmdarray=("${(f)$(whence -pa $1)}")
> 
> At this point you have assigned to the global array $cmdarray.
> 
> >                 echo ${#cmdarray}                     ## 1
> >                 echo ${(F)cmdarray}
> >                 typeset -U cmdarray
> 
> "typeset" is equivalent to "local" when it appears within the body
> of a function, so now you have created a new local scalar (not array)
> which hides the global array.  That scalar has the "unique" property,
> but that's meaningless for scalars.
> 
> If you wanted to apply the "unique" property to the existing global
> array, you'd need to do
> 
>                   typeset -g -U cmdarray
> 
> >                 echo ${#cmdarray}                     ## 2
> >                 echo ${(F)cmdarray}
> >                 cmdarray=(${(o)cmdarray})
> 
> Now you've changed the type of the local scalar to array.  This would
> cause the "unique" property to take effect, except that it's an empty
> array (because the existing scalar referenced by ${(o)cmdarray} has
> never been assigned a value).
> 
> [...]
> > }
> 
> Does this clear things up?  You're always better off declaring your
> variables, even though the shell language doesn't require it.



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