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

Re: [PATCH 1/3] Extended ksh compatibility: namespace parameter syntax



On 2023-05-21 at 21:35 -0700, Bart Schaefer wrote:
> On Sun, May 21, 2023 at 7:36 PM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> > > So, to match the intent of ksh as I understand it:
> > >  * .identifier.x is always treating identifier as a namespace
> > >  * identifier.x is always treating identifier as a compound var
> > >  * this is consistent across assignment LHS and expansion
> >
> > Does this mean compound vars can't be namespaced?
> 
> No, but it does mean namespaces can't be nested.

Bart is (as per 99.9% of the time) correct.  The examples below might
make it clearer (and are original to me so fine to grab into the test
suite).  Note though that ksh does have nested collection types, which
would make full zsh compatibility trickier:

    Attributes assigned by the typeset special built-in command ap‐
    ply  to  all  elements of the array.  An array element can be a
    simple variable, a compound variable or an array variable.   An
    element  of  an indexed array can be either an indexed array or
    an associative array.  An element of an associative  array  can
    also  be  either.  To refer to an array element that is part of
    an array element, concatenate the subscript in  brackets.   For
    example, to refer to the foobar element of an associative array
    that is defined as the third element of the indexed array,  use
    ${vname[3][foobar]}


$ namespace foo { bar=(alpha=one beta=two gamma=three); }
$ echo ${.foo.bar.alpha}
one
$

$ namespace first { namespace second { item=42; } }
$ echo ${.second.item}
42
$ echo ${.first.second.item}

$ typeset -p
[ ... skipping much before/after/between these ... ]
namespace first
{
	:
}
namespace foo
{
	typeset -C bar=()
}
namespace second
{
	item=42
}

$ namespace a { b=( c=(one two three) d=([ichi]=1 [ni]=2 [san]=3) ); }
$ echo ${.a.b.c[@]}
one two three
$ echo ${!.a.b.d[@]}
ichi ni san
$ echo ${.a.b.d[@]}
1 2 3
$ echo ${.a.b.d[ni]}
2
$

-Phil




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