I guess I should outline my whole proposal for $ in Prothon. I'll try to be
brief.
Statement of problem:
# in python
class klass:
def __init__(self):
self.me = 1
def func(self):
print "func1,self"+str(self.me),
class klass2(klass):
def __init__(self):
self.me = 2
def func(self):
klass.func(self)
print "func2,self"+str(self.me),
inst = klass2()
inst.func() # prints func1,self2 func2,self2
#in Prothon
Klass = Object()
with Klass:
.me = 0
def .__init__():
.me = 1
def .func():
print "func1,self"+.me,
Klass2 = Klass()
with Klass2:
def .__init__():
.me = 2
def .func():
Klass.func() # does not do what python does
print "func2,self"+.me,
inst = Klass2()
inst.func() # prints func1,self0 func2,self2
As you can see, the call Klass.func() got the function func from the object
Klass and then called it on Klass using Klass as the target "self" instead
of the instance "inst". In Python the call klass.func was different because
Python knows that klass is a class and therefore obviously cannot be the
target of call (an instance), so it made the programmer pass the instance to
use as a parameter (something Prothon never does).
To fix this, we have to make things more explicit in Prothon. This is a
GOOD thing, making things more explicit. It makes things simpler. We have
four different proposals over on the Prothon mailing lists right now. I'll
show mine here right now briefly by just showing a bunch of sample code
lines:
$.var # $ replaces Python's self (think $elf)
$var # same thing (. is optional after $ self symbol)
obj.func() # get func from obj and bind to obj during call
obj$func() # get func from obj and bind to self during call
x = obj.func # get func from obj (simple attr retrieval)
bm = obj..func # get func from obj and make bound method from obj and func
bm = obj$$func # get func from obj and make bound method from self and func
with bobj: cobj$func() # get func from cobj and bind to bobj during call
with bobj: bm = cobj$$func # get func from cobj and make bound method from
bobj
Now we can fix the problem stated above using the example in the fourth line
above ( obj$func() ):
Klass = Object()
with Klass:
.me = 0
def .__init__():
.me = 1
def .func():
print "func1,self"+.me,
Klass2 = Klass()
with Klass2:
def .__init__():
.me = 2
def .func():
Klass$func() # ambiguity fixed
print "func2,self"+.me,
inst = Klass2()
inst.func() # prints func1,self2 func2,self2