On Wednesday, July 24, 2013 12:40:01 PM David Korn wrote:
> cc:  [email protected]  [email protected]
> Subject: Re: Re: [ast-users] _ doesn't refer to the correct object.
> --------
> 
> > What happens if "x" itself is a typed variable? What does python do?
> 
> 
> I don't know what python does.  What I did for ksh was to have _ reference
> x when x is a type variable.

Ksh has "type variables"? As in generics?

If you really mean "objects", in Python, everything is an object and has a
type. There are no "untyped variables". Why wouldn't Ksh's _ work the same for
user-defined types as for built-in types?

        #!/usr/bin/env python3

        class A(object):
                def __init__(self):
                        self.y = "I'm from A"

                @property
                def x(self):
                        return self.y

        class B(A):
                def __init__(self, **kwargs):
                        self.y="I'm from B"
                        print(self.x)               # "I'm from B"
                        super().__init__(**kwargs)  # call base class 
constructor.

        obj = B()
        print(obj.x) # "I'm from A"


I take it that __ is going to work like super(), hopefully. This basic program
fails in several ways:

        #!/usr/bin/env ksh

        typeset -T Person_t=(
                integer -S population
                typeset name
                
                function create {
                        ((_.population++))
                }

                # This destructor fails altogether for some reason.
                function unset {
                        ((_.population--))
                }
                
                # Static method
                typeset -fS totalpop
                function totalpop {
                        printf 'Total population is currently %d.\n' 
"${_.population}"
                }
        )

        typeset -T Maintainer_t=(
                Person_t _

                function create {
                        # We need some equivalent to Python super().
                        # Theres no base class access or virtual / override 
methods.
                        .sh.type.Person_t.create
                        .sh.type.Person_t.totalpop
                }
                
                # I don't know whether this is needed. It fails either way.
                function unset {
                        .sh.type.Person_t.unset
                        .sh.type.Person_t.totalpop
                }
        )

        typeset -T Shell_t=(
                Maintainer_t -a maintainers
                typeset list

                function create {
                        print -r 'Another UNIX shell?!'
                }
        )

        function main {
                compound shells=(
                        Shell_t ksh=(maintainers=((name=DGK) (name=Glenn)); 
list=ast-users)
                        Shell_t bash=(maintainers=((name=Chet)); list=bug-bash)
                        Shell_t mksh=(maintainers=((name=TG)))
                )

                typeset -p shells
                unset -v shells
        }

        main "$@"

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

Reply via email to