473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 1904
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.