On Thu, Jul 25, 2013 at 12:29 AM, David Korn <[email protected]> wrote:
> cc: [email protected] [email protected]
> Subject: Re: Re: [ast-developers] [RFE] var.__ to access the parent variable 
> of a  type or compound variable
> --------
>
>
>> I like the idea of var.__ because it has a lot of potential. IMO, in
>> terms of usefulness, its 2nd to namerefs.
>>
>> Irek
>>
>
> Are you proposing that for compound variables
>         print ${var.__}
> be equivalent to
>
>         nameref name=${var%.*}
>         print ${name}
>
> Is this correct?

Yes, I think so. It eludes me at the moment why ${var%.*} only removes
the last element in a compound tree name, but...

>
> What is ${var.__} for simple variables,

simple variables => throw an error, except if they are member of a
compound variable. Then the name of the parent variable should be
printed.

> type variables

Example 1:
typeset -T my_t=(
    integer a=1;
)

my_t v;

v.a.__ will refer to v itself (circular, I know, just for demonstration)


Example 2:
typeset -T my_t=(
    compound a=(
        integer b=1;
    )
)

my_t v;

v.a.b.__ will refer to v.a, v.a.b.__.__ will refer to v


Example 3:
typeset -T my_t=(
    compound a=(
        integer b=1;
    )
)

compound c
my_t c.v;
nameref v=c.v

v.__ will refer to c


Example 4 - the IMO important one:
typeset -T my_t=(
    compound a=(
        integer b=1;
    )
)

function add_i
{
    nameref parent_of_v=$1.__
    integer parent_of_v.i=9
}

compound c
my_t c.v;
add_i c.v
print ${c.i}

should print '9'

> and for array variables?

This is the tough little question I don't have an answer for.

Irek
_______________________________________________
ast-developers mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-developers

Reply via email to