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
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users

Reply via email to