cc:  [email protected]
Subject: Re: Re: [ast-users] Can't pass parameters to an instance constructor
--------

> On Monday, July 15, 2013 10:31:57 AM David Korn wrote:
> > cc: [email protected] Subject: Re: [ast-users] Can't pass parameters to an
> > instance constructor
> > --------
> > 
> > > 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 currently doesn't have a create discipline and you example doesn't
> > invoke x.create so why should val be incremented?
> 
> It's described within the "TYPES" document:
> 
> "If the discipline function named create is defined it will be invoked when
> creating each instance for that type. A function named create cannot be 
> defined
> by any instance."
> 
> "create" indeed appears to be called when the instance is created.
> 
> It would make sense to treat this the same way as type constructors in most
> languages. It just needs a way to accept positional parameters and/or an
> initializer list for initial setup of the object. Otherwise you'd have to do
> something like Cedric suggested with wrapper functions for everything.
> 
> -- 
> Dan Douglas
> 

You are correct that just as the "TYPES" document describes, ksh93
does support a create function.  I completely forgot about this and it
is also in the man page.

However, it is invoked when instance is created before the
fields have been modifed by assignment as if it were created as
        Type foo
        (foo.x=q foo.y=z)

My concern with changing it is that this could mean that
you can't save and restore a shell environment using
typeset -T and typeset -p and putting it in a file and
then dotting the file to restore it since the
initialization function will get called twice.

David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to