rev 498 - in trunk: docs/tutorial pr/test src
SVN User <[email protected]> Mon, 17 May 2004 23:42:10 -0400
| Newsgroups | gmane.comp.lang.prothon.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: mark
Date: 2004-05-17 23:42:07 -0400 (Mon, 17 May 2004)
New Revision: 498
Modified:
trunk/docs/tutorial/tutorial8.htm
trunk/pr/test/test.pr
trunk/src/object.c
Log:
fixed bug that caused symbols to be garbage collected
Modified: trunk/docs/tutorial/tutorial8.htm
===================================================================
--- trunk/docs/tutorial/tutorial8.htm 2004-05-18 01:51:43 UTC (rev 497)
+++ trunk/docs/tutorial/tutorial8.htm 2004-05-18 03:42:07 UTC (rev 498)
@@ -167,8 +167,29 @@
"Prototype". Now you can see what our original statement "Rectangle
= Object()" was doing. It created an empty object with only a prototype
link to Object.</p>
+ <pre>>>> rect2 = Rectangle()
+>>> print rect2.attrs() # attrs() returns attrs as dictionary
+{}
+>>> print rect2.width, rect2.height, rect2.area()
+10 10 100
+>>></pre>
+ <p>We created a new object called rect2 with no attributes as before,
+ but this time we gave it a prototype link to Rectangle instead of copying
+ it from Rectangle. We showed that it had no attributes of it's own by
+ printing them out using the .attrs() function. Yet when we accessed
+ width, height, and area we got the same results as before. This is because
+ each of the attribute lookups, both for data and functions, failed on
+ rect2 so the lookup went to Rectangle where the lookup succeeded. </p>
+ <p>In the case of rect2.area() resolving to Rectangle.area(), this kind
+ of method lookup reminds us a lot of the method inheritance in object-oriented
+ programming. So we sometimes say in Prothon that rect2 "inherited"
+ the method area from Rectangle. In Prothon, we also "inherit"
+ data since we lookup all attributes in the prototype parents. This is
+ not done in object-oriented languages and it is a powerful advantage
+ of prototype-based languages. Let's continue the example:</p>
<p> </p>
- </td>
+ <p> </p>
+ </td>
</tr>
</table>
<table width="630" border="0" cellpadding="0" cellspacing="0">
Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr 2004-05-18 01:51:43 UTC (rev 497)
+++ trunk/pr/test/test.pr 2004-05-18 03:42:07 UTC (rev 498)
@@ -6,5 +6,5 @@
height = 10
def area():
return self.width * self.height
-rect2 = Rectangle()
+
Modified: trunk/src/object.c
===================================================================
--- trunk/src/object.c 2004-05-18 01:51:43 UTC (rev 497)
+++ trunk/src/object.c 2004-05-18 03:42:07 UTC (rev 498)
@@ -1106,10 +1106,8 @@
if (!sym_obj) {
raise_exception(ist, OBJ(INTERNAL_EXC), "key_to_symstr sym lookup error");
res = "";
- } else {
+ } else
res = symch(ist, sym_obj);
- del_unlock(sym_obj);
- }
del_unlock(key_obj);
return res;
}