Linguistic challenge: name this program

2004-12-05 Thread Andr? Roberge
In 1981, Richard Pattis wrote a delightful little book titled "Karel
the Robot, a Gentle Introduction to the Art of Programming." Pattis's
"Karel the Robot" was named after the author Karel Capek, who
popularized the word "robot" in his play "Rossum's Universal Robots".
Pattis's approach was to introduce a robot who could follow 5 basic
instructions and be taught to accomplish tasks of increasing
complexity.

A few years ago, a first implementation of "Karel the Robot" in Python
was created and called PyKarel. A second, newer implementation is
called Guido van Robot (GvR for short), and is available at
gvr.sourceforge.net. Work is currently underway by the developpers of
GvR to produce a new-and-improved version.

I have been working on my own (better ;-) version (sometimes
collaborating with the GvR folks) in order to learn Python. It is now
90% finished. It is meant to be a complete environment to learn about
programming concepts, from simple sequences of instruction to OOP.

Given the origin of Pattis's name (Rossum's Universal Robot) and the
name of Python's BDFL, I find it difficult to think of a better name
than Guido van Robot to name a programming environment in which one
uses Python to teach a robot new tricks! (Hat's off to Steve Howell
for this one). Yet, I want a "clever" name for my version.

Any suggestions?

Andre Roberge
-- 
http://mail.python.org/mailman/listinfo/python-list


exec and global puzzle

2004-12-05 Thread Andr? Roberge
I have the following two files:

#--testexec.py--
def exec_code(co):
try:
exec co
except:
print "error"

#-- test.py--
import thread
import testexec
import time

code = "def a():\n print 'a'\n\n" +\
   "def c():\n a()\n\nc()"

code2 = "def a():\n print 'a'\n\n" +\
   "def c():\n global a\n a()\n\nc()"

print " exec code - no global"
exec code
print " exec from thread - no global"
thread.start_new(testexec.exec_code, (code,))
time.sleep(1)
print "\n exec code2 - with global"
exec code2
print " exec from thread - with global"
thread.start_new(testexec.exec_code, (code2,))
#---

Here's the output when I execute test.py:

 exec code - no global
a
 exec from thread - no global
error

 exec code2 - with global
a
 exec from thread - with global
a
#-
Without the global statement, I get an error when trying to execute
the code.
I don't understand why I need to use the global statement within the
definition of c() in order for it to know what a() is.  If I define
exec_code() within test.py and use it there, I do not get any error,
with or without the use of a global statement.

Andre
-- 
http://mail.python.org/mailman/listinfo/python-list