"Davy" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Hi all, | | When reading Python source code of Peter Norvig's AI book, I found it | hard for me to understand the idea of slot (function nested in | function). Please see "program()" nested in "make_agent_program()", | why not use program() directly?
To expand on BD's comment: make_agent_program() returns a new function object for each instance. If each is a copy of the same func, that makes little sense in itself. PN could just as well have put defined programs() outside of the class and passed it to the constructor or grabbed it as a global. But perhaps PN intends that in a real program, the .program attribute would not always be the same. The more subtle point is that a function that is an attribute of a class normally get an instance as the first parameter while a function that is an attribute of a instance does not. As BD said, use of @staticmethod() would have the same effect, today, if indeed .program was really meant to be the same function for all instances. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list