Noob: What is a slot? Me trying to understand another's code
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Tue Sep 4 14:46:37 EDT 2007
En Tue, 04 Sep 2007 15:03:16 -0300, Carnell, James E
<jecarnell at saintfrancis.com> escribi�:
> MY QUESTION:
> What is a slot? In class Object below the __init__ has a slot. Note:
> The slot makes use of a data object called 'percept' that is used in the
> TableDrivenAgent(Agent) at the bottom of this post. I am guessing this
> is a type of Finite State Machine (I haven't bought the book yet so I am
> guessing).
The authors appear to be using the term in a very general sense - meaning
"something that has to be filled in".
That is, you (the programmer) is supposed to "fill" the slot with
meaningful code or data.
> [...] You subclass Object to get the objects you want. Each object can
> have a .__name__ slot (used for output only).
> [...] An Agent is a subclass of Object with one required slot,
> .program, which should hold a function that takes one argument, the
> percept, and returns an action. Note that 'program' is a slot, not a
> method.
Here they're trying to bind a simple function (not a method) to a name. I
don't see the point in forcing things that way, maybe the authors have
good reasons. But I'd use a staticmethod instead, perhaps.
Note: The C Python source code does use "slots", fields in a structure
holding function pointers. For example, filling the nb_add slot in a type
object, one can evaluate a+b for instances of that type.
--
Gabriel Genellina
More information about the Python-list
mailing list