Re: proposal for call_ and str_
"Mark Hahn" <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <[email protected]> |
Mark Hahn wrote:
> ---- sample code ----
>
> object Proto:
> def str_():
> print 'extension'
> def call_():
> "special call for instances"
> blah blah blah
>
> object attrProxy_:
> def str_():
> print 'proto'
> call_ = defaultCall_
>
> p = Proto()
> print Proto # --> proto
> print p # --> extension
>
> We might want some syntax sugar for "object attrProxy_:".
>
> Note that "p = Proto()" needs attrProxy_.call_() set to
> "defaultCall_" in order to free up the Proto namespace for the
> special Proto.call_. It would be nice to somehow make "call =
> defaultCall_" automatic. Maybe that could be part of the syntax
> sugar for "object attrProxy_:".
I think I know what syntax sugar I'd like to use. It is a new keyword
called "factory". It is a lot like object but is specifically generates the
"attrProxy_" object and automatically generates a default call_() and str_()
method that can be overriden. I've used the word "factory" instead of the
word "class" that I used in class proposal 2 because "factory" works both in
prototypes and in classes. Factory is general to the 2-tier concept. You
can think of the factory as defining methods that are used when the object
is "used as a factory" instead of as an instance.
object Proto:
def str_():
print 'extension'
def call_():
"special call for instances"
blah blah blah
factory:
def str_():
print 'proto'
I really like this now. If I don't hear comments back I'm going to assume
eveyone else loves it also, so speak up. :-) I'll probably be implementing
it soon since it is not part of any class controversy.