Re: vote on prop keyword

"Mark Hahn" <[email protected]>
Newsgroups gmane.comp.lang.prothon.user
Message-ID <[email protected]>
Paul Prescod wrote:
>> object Widget:
>>      price = 3.72
>>      object tax(Property):
>>           def get_():
>>                return self.price * 0.03
>>
>
> Doesn't work for me in build 710. (see below)

The prop keyword works as advertised.  In 710 the prototype is "Prop", not
"Property" which is what caused your problem.  I didn't expect anyone to
actually try to run it.   I can change it to Property or however we want to
spell it.

>> Vote FOR the keeping the keyword or AGAINST the keyword and just
>> typing out the object statement.
>
> Can I vote AGAINST the object syntax? ;)

I'm not sure what you mean.  Vote against the whole scheme altogether or for
the keyword?

> To my Python-trained brain I can't see how it would work.
>
> object Widget:
>       price = 3.72
>       object tax(Property):
>            def set_(abc):
>                 ...
>
> Widget().tax = 15
>
> Doesn't this _rebind_ .tax rather than calling it? How is the
> "Property" object implemented so that it can prevent its own
> rebinding?

The interpreter is hard-wired to respect get_, set_ and del_ as special.

>Can I use this elsewhere? At the top level:
>
> object foo(Property):
>      def set_(abc):
> ...
>
> foo = 5 # calls set_ instead of rebinding???

At the top level it is a wild-card responding to ALL attribute accesses.
Read the tutorial.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.