RE: Prothon bug: strange interaction between self and add_
"Mark Hahn" <[email protected]> Wed, 19 May 2004 12:55:04 -0700
| Newsgroups | gmane.comp.lang.prothon.devel |
|---|---|
| Message-ID | <001b01c43ddb$2dedfc40$0b01a8c0@mark> |
I will work on this in about an hour. You caught me at a bad time. I should know better than to quote a fixed time for bug fixes :-) By the way, I do already have symbol objects internally that are what you need for attrname. They are like strings but can only hold legal Prothon symbols. They are used as keys for attribute "dictionaries". We can discuss supporting them at the Prothon level. > -----Original Message----- > From: Lenard Lindstrom [mailto:[email protected]] > Sent: Wednesday, May 19, 2004 11:17 AM > To: [email protected]; [email protected] > Subject: Prothon bug: strange interaction between self and add_ > > > Here is something that has me completely confused. Each time > I run this program I get a different result. The only guess I > can make is that "self" is getting clobbered in "add_" somehow. > > -------------------------------------------------------------- > def refer(start, attrname): > mro = self.protoList() > n = mro.len() > i = 0 > while i < n: > if mro[i] is start: > break > i += 1 > if i == n: > raise AttributeError > while True: > i += 1 > if i == n: > break > o = mro[i] > attrs = o.attrs() > if attrname in attrs: > a = attrs[attrname] > if a.hasProto?(Func): > return a > return a > raise AttributeError > > print "# 1) Integers that support modular addition:" > object ModInt(Int): > modulo = 10 > def call_(i=0): > call = refer(ModInt, 'call_') > return call{self}(i % self.modulo) > def add_(other): > if self.modulo != other.modulo: > raise TypeError > proto = self.protoList()[1] > add = refer(ModInt, 'add_') > x = proto(add{self}(other)) > print "new", x > return x > > object Mod8Int(ModInt): > modulo = 8 > > m = Mod8Int(1) > n = Mod8Int(1) > print "%i, %s" % (m, m.protoList().str_()) > for i in 10: > m = m + n > print "%i, %s" % (m, m.protoList().str_()) > --------------------------------------------------------- > > Some different results: > > ----------------- > # 1) Integers that support modular addition: > 1, [1, <Int:Uninitialized>, <Int:Uninitialized>, > <Object:89d260:Int: integer obj ect prototype>, > <Object:89d020:Object: prototype base for all objects>] > > Uncaught exception: > --- File: \user\projects\prothon\example1_v1.pr, line: 47, char: 46 > --- File: \user\projects\prothon\example1_v1.pr, line: 46, > char: 14 Function not found Error, Function add_ not found. > ------------------ > # 1) Integers that support modular addition: > 1, [1, <Int:Uninitialized>, <Int:Uninitialized>, > <Object:89d260:Int: integer obj ect prototype>, > <Object:89d020:Object: prototype base for all objects>] new 2 > 2, [2, <Int:Uninitialized>, <Int:Uninitialized>, > <Object:89d260:Int: integer obj ect prototype>, > <Object:89d020:Object: prototype base for all objects>] > > Uncaught exception: > --- File: \user\projects\prothon\example1_v1.pr, line: 47, char: 46 > --- File: \user\projects\prothon\example1_v1.pr, line: 46, > char: 14 Function not found Error, Function add_ not found. > ------------------- > # 1) Integers that support modular addition: > 1, [1, <Int:Uninitialized>, <Int:Uninitialized>, > <Object:89d260:Int: integer obj ect prototype>, > <Object:89d020:Object: prototype base for all objects>] new 2 > 2, [2, <Int:Uninitialized>, <Int:Uninitialized>, > <Object:89d260:Int: integer obj ect prototype>, > <Object:89d020:Object: prototype base for all objects>] 3, > [3, <Object:89d260:Int: integer object prototype>, > <Object:89d020:Object: pro totype base for all objects>] 4, > [4, <Object:89d260:Int: integer object prototype>, > <Object:89d020:Object: pro totype base for all objects>] 5, > [5, <Object:89d260:Int: integer object prototype>, > <Object:89d020:Object: pro totype base for all objects>] 6, > [6, <Object:89d260:Int: integer object prototype>, > <Object:89d020:Object: pro totype base for all objects>] 7, > [7, <Object:89d260:Int: integer object prototype>, > <Object:89d020:Object: pro totype base for all objects>] 8, > [8, <Object:89d260:Int: integer object prototype>, > <Object:89d020:Object: pro totype base for all objects>] 9, > [9, <Object:89d260:Int: integer object prototype>, > <Object:89d020:Object: pro totype base for all objects>] 10, > [10, <Object:89d260:Int: integer object prototype>, > <Object:89d020:Object: p rototype base for all objects>] 11, > [11, <Object:89d260:Int: integer object prototype>, > <Object:89d020:Object: p rototype base for all objects>] > -------------------- > > Or even a page fault in one case. > > Does the prothon interpreter remember anything between > command line runs? A particular output will appear several > times in a row before changing to something else. > > Lenard Lindstrom > <[email protected]> > > > > > >