Hi,

How do you create a type derived from a builtin type such as the array types? 
I understand that you can inherit from user-defined types, but the 
documentation is conflicting. The "TYPES" file from the ksh source gives an 
example involving the special variable ".", which isn't mentioned in the 
manpage. The manual only discusses "_" with regards to custom types, but in 
addition you're able to set the -a and -A flags when creating instances. I 
can't really figure out what this does or why you would do this at the time an 
instance is created. Shouldn't there be a base class along the lines of 
".sh.type.array" to inherit from in the type definition?

Say for example I wanted to create an object that expands to two words when 
referenced. How would you do it? I'm having a difficulty even coming up with 
an example that does anything like what I expect.

typeset -T Tuple_t=(
    typeset -h 'Declare this as an array type of two members' -a .[2]
    integer count # keep track of the current count

    function get {
        ((.sh.value = _.count++))
    }
)

Tuple x

for ((i = 0; i++ < 5;)); do
    printf '<%s> ' "${x[@]}"
    print
done

Expected result:
<0> <1>
<2> <3>
<4> <5>
<6> <7>
<8> <9>

As I understand, the getter should get called once for each element and set 
.sh.subscript when requesting multiple values. I've tried hundreds of 
permutations on this from creating my own array types to accessing other class 
attributes indirectly. Everything produces a surprising result, or just 
segfaults.

Also, is there a "call" method for invoking an instance as a function? Is the 
only way to interact with objects to assign and dereference values?
-- 
Dan Douglas
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to