On 15 July 2013 13:09, Dan Douglas <[email protected]> wrote:
> Hi, here x.val is assigned after the constructor has already run. It should be
> assigned before so it's accessiable to the "create":
>
> typeset -T X=(
>     integer val
>
>     function create {
>         ((_.val++))
>     }
> )
>
> X x=(val=5)
> print -v x.val # should print 6

ksh93 doesn't have a create/creat function for types yet, but you can
use factory functions to manufacture objects on an assembly line.

An example:
###################################
typeset -T X=(
    integer val

    function factory_create {
        ((_.val++))
    }
)

# this function manufactures objects of type "X"
function factory_X
{
        nameref n=$1

        X x=(val=5)
        x.factory_create

        typeset -m n=x  
}

# use this to pretty print objects
compound prettyprint

# create an object via our trusty factory
factory_X prettyprint.obj

# print it
print -v prettyprint
###################################

Hint: typeset -m is like /usr/bin/mv, typeset -c is like /usr/bin/cp.
Both are pretty useful to implement object factories or other OOP
methods.

Ced

-- 
Cedric Blancher <[email protected]>
Institute Pasteur
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to