RE: Insight: Prothon is an Acquisition-oriented language

"Mark Hahn" <[email protected]> Thu, 29 Jul 2004 20:17:30 -0700
Newsgroups gmane.comp.lang.prothon.user
Message-ID <000301c475e3$c03bd870$0d01a8c0@MarkVaio>
Paul Prescod wrote:

> Here is a Python implementation of the style inheritance thing:
> 
> inherited_properties = ["a", "b", "c"]
> 
> class Node:
> 	vals = None
> 
> 	def __init__(self, parent = None):
> 		# have to get around setattr below
> 		self.__dict__["vals"] = {}
> 		self.__dict__["parent"] = parent
> 
> 	def __getattr__(self, name):
> 		if name in inherited_properties:
> 			if name in self.vals:
> 				return self.vals[name]
> 			else:
> 				return getattr(self.parent,name)
> 		else:
> 			return self.vals[name]
> 
> 
> 	def __setattr__(self, name, val):
> 		self.vals[name] = val

Does this look significantly simpler to you?  It just switches between using
the built-in inheritance and a local store. To use this you just mix-in this
prototype with the data prototypes.

object Node:
	def init_():	
		local_vals = {}
	def get_(attr):
		if attr in inherited_properties:
			return getAttrNoProp(attr)
		else
			return local_vals[attr]
	def set_(attr, value):
		if attr in inherited_properties:
			setAttrNoProp(attr, value)
		else
			local_vals[attr] = value