472,992 Members | 3,494 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,992 software developers and data experts.

Noob: What is a slot? Me trying to understand another's code



I am thinking about purchasing a book, but wanted to make sure I could
get through the code that implements what the book is about (Artificial
Intelligence a Modern Approach). Anyway, I'm not a very good programmer
and OOP is still sinking in, so please don't answer my questions like I
really know anything.

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).

MY GUESS AT THE ANSWER:
I've played around with it, and my guess is that is just some data
container local to the instance of Object (after it has been extended or
inherited or whatever). In other words, if I would have made some global
dictionary that each instance of Object and or Agent(Object) could
access it would be possible to allow instances of other classes to
access the global dictionary.

Why not make a class instance have something like a dictionary for
keeping it's own records like self.myListOfActions then you could append
to it etc. I guess it wouldn't be private, but I don't think anything
really is private in python.

Anyway, why a slot (whatever that is)?
class Object:
"""This represents any physical object that can appear in an
Environment.
You subclass Object to get the objects you want. Each object can
have a
.__name__ slot (used for output only)."""
def __repr__(self):
return '<%s>' % getattr(self, '__name__',
self.__class__.__name__)

def is_alive(self):
"""Objects that are 'alive' should return true."""
return hasattr(self, 'alive') and self.alive

class Agent(Object):
"""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. (What counts as a percept or action
will depend on the specific environment in which the agent exists.)
Note that 'program' is a slot, not a method. If it were a method,
then the program could 'cheat' and look at aspects of the agent.
It's not supposed to do that: the program can only look at the
percepts. An agent program that needs a model of the world (and of
the agent itself) will have to build and maintain its own model.
There is an optional slots, .performance, which is a number giving
the performance measure of the agent in its environment."""
##################### HERE IS THE SLOT #######################

def __init__(self):
def program(percept):
return raw_input('Percept=%s; action? ' % percept)
self.program = program
self.alive = True

################THIS APPEARS LATER IN THE PROGRAM##############
< so you can see where the 'percept' is coming from and how it is being
used.

class TableDrivenAgent(Agent):
"""This agent selects an action based on the percept sequence.
It is practical only for tiny domains.
To customize it you provide a table to the constructor. [Fig.
2.7]"""

def __init__(self, table):
"Supply as table a dictionary of all {percept_sequence:action}
pairs."
## The agent program could in principle be a function, but
because
## it needs to store state, we make it a callable instance of a
class.
Agent.__init__(self)
################################### percept ##########
percepts = []
def program(percept):
percepts.append(percept)
action = table.get(tuple(percepts))
return action
self.program = program
Thanks for your time (and patience),

James Carnell
Sep 4 '07 #1
2 1867
Carnell, James E wrote:
>
I am thinking about purchasing a book, but wanted to make sure I could
get through the code that implements what the book is about (Artificial
Intelligence a Modern Approach). Anyway, I'm not a very good programmer
and OOP is still sinking in, so please don't answer my questions like I
really know anything.

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).
I really have a hard time grasping what it is you don't understand (the
annoying thing about not understanding stuff is that you usually lack
the proper terms to explain what you don't understand, precisely
_because_ you don't understand it ;)).

At first I thought you were talking about __slots__, as explained in the
docs <URL:http://docs.python.org/ref/slots.html>.
[but some snipped code later you say:]

##################### HERE IS THE SLOT #######################

def __init__(self):
def program(percept):
return raw_input('Percept=%s; action? ' % percept)
self.program = program
self.alive = True
That is "simply" a special method (namely the one that is called after
instance creation so you can set up the instance variables).
<nagging>You should really know that.<\nagging>
Lookie here: <URL:http://docs.python.org/ref/customization.html>

Did that do it? Sorry, I have big trouble looking at long listings and
figuring out their meaning. If that didn't help, try reformulating your
question (please).

/W
Sep 4 '07 #2
On Tue, 04 Sep 2007 13:03:16 -0500, Carnell, James E wrote:
I am thinking about purchasing a book, but wanted to make sure I could
get through the code that implements what the book is about (Artificial
Intelligence a Modern Approach). Anyway, I'm not a very good programmer
and OOP is still sinking in, so please don't answer my questions like I
really know anything.

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).

[…]

Anyway, why a slot (whatever that is)?

[Example code snipped.]
If you want to learn Python don't do it with that book because the authors
seem to write another programming language using Python syntax. I guess
there's an older issue of that book that used the SmallTalk programming
language and they switched to Python syntactically but not mentally and not
the vocabulary. A "slot" in SmallTalk is called "attribute" in Python.

Ciao,
Marc 'BlackJack' Rintsch
Sep 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Rich Grise | last post by:
I think I've finally found a tutorial that can get me started: http://www.zib.de/Visual/people/mueller/Course/Tutorial/tutorial.html and I've been lurking for awhile as well. What happened is,...
42
by: Holger | last post by:
Hi guys Tried searching for a solution to this, but the error message is so generic, that I could not get any meaningfull results. Anyways - errormessage:...
9
by: davetelling | last post by:
I am not a programmer, I'm an engineer trying to make an interface to a product I'm designing. I have used C# to make a form that interrogates the unit via the serial port and receives the data. I...
0
by: AndyW | last post by:
Hey folks. I am trying to get a soap wsdl service working and have a bit of a noob php programming question for it. I'm using PHP 5.x btw. I have written a soap server that contains a...
2
by: tavspamnofwd | last post by:
I'm a total noob, and I'm trying to understand this code: var newsi = { name:"newsi", dom:false }; newsi.Client=function(){ //stuff }
4
by: Computer Guy | last post by:
Hi I have recently started working with PHP and am making a neighborhood website. I am connecting to my Mysql database and am having difficulty understanding what is happening in the example on...
6
by: Lang Murphy | last post by:
I'm baaaaack... some of you answered a question I had last week. Only problem is: I'm a dope who doesn't understand most of what y'all posted. Raw noob when it comes to .Net and C#. So I'm going...
2
by: Davy | last post by:
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...
2
by: pinman | last post by:
hi. i'm pretty much a noob to c# and visual studio and am trying to create a simple login method. i have created a users table in the database and can add users by inputing there md5 encrypted...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.