Thursday, May 25, 2006

rur-ple bug fix for Mac and Linux users

Brad Miller uncovered a bug (hard coded windows specific path separators) in version 0.9.8.2 of rur-ple. Version 0.9.8.3 has been uploaded with required changes. Apologies to Linux and Mac users.

Summer of Code 2006

For a second year in a row, Google is paying hundreds of students to spend their summer contributing to open source projects. This is known as Summer of Code 2006. The Python Software Foundation is a mentoring organisation that is the beneficiary of 25 Summer of Code projects. Continuing on my streak of luck with Python, I am mentoring Johannes Woolard, a promising student whose project was accepted in this Summer of Code competition. Johannes has a blog, and has already started working on his project. Within the span of a day or two, he has already removed the CherryPy dependency of Crunchy Frog, which was one of my longer-term objective - but something I didn't know how to do. Kudos to Johannes!

Tuesday, May 23, 2006

Rur-ple 0.9.8.2 released

I implemented in rur-ple the "auto-indent" feature that was added to Lightning Compiler. This should be more user-friendly for beginners. I also fixed a bug that was introduced when I improved the highlighting method - it was no longer possible to run programs where robots were introduced by an instruction [e.g. Reeborg = UsedRobot()] in an otherwise empty world.

Lightning 2.1

Thanks to Milan Melena, who left a code sample on this blog, Lightning 2.1 has been released, with added auto-indent and quick fold/unfold. Next, I'll have to consider added auto-indent to rur-ple.

Monday, May 22, 2006

Rur-ple: getting closer to 1.0

Rur-ple is getting ever closer to version 1.0. I have to finish about 10 new lessons to get to version 0.9.9 after which I will do a final cleanup of the code for the 1.0 release candidate. The current version (released today) is 0.9.8.1.

Since the last release, I made two changes that should be helpful for students. The first one has been to use a scintilla feature to indicate white spaces with tiny dots as indicated in the picture below.



This should help locate problems related to blank lines with a number of spaces that does not match the indentation level; this had apparently been a problem for some students.

The second change is more significant. When I started working on rur-ple, I wanted to be able to step through the code and highlight the line of code being executed. I managed to do this only partially through a kludge.

The first step was to take the user code and add some line number information using the Python module tokenize and some complicated processing. For example, the code shown above might be re-written as follows:
def follow_right_wall():
....linenumber = 20
....if right_is_clear():
........linenumber = 21
........turn_right()
........linenumber = 22
........move()
........linenumber = 23
....elif front_is_clear():
........linenumber = 24
........move()
........linenumber = 25
....else:
........linenumber = 26
........turn_left()
........linenumber = 27

I would then call exec to execute the processed code, leaving the unprocessed one displayed in the editor window. Each time a basic instruction (like move, turn_left, pick_beeper, put_beeper) was executed, the graphical display would be updated and the corresponding line of code in the editor was highlighted. When I came up with this solution, I had only been programming with Python for a few months and thought it was rather clever.

Unfortunately it was not possible, using this method, to highlight every line being executed: only those with one of the four basic robot instructions.


The new version makes use of the Python method sys.trace to follow the execution. It is much simpler than the old version (5 lines of code instead of 33) and works much better, as can be seen on the picture on the left. It has not yet been field tested but Andy Judkis's students should do just that in the coming week.

Monday, May 15, 2006

New version of RUR-PLE (0.9.8)

After receiving some suggestions from Andy Judkis, a high school teacher who uses Rur-ple in his classes, I made the following changes to rur-ple.
  • I added an "output pane" in the robot world window. Users can now put "print" statements in their programs, and the result will appear in the output pane. This should be useful in "tracing" the program flow.
  • I added two new instructions that can be used in robot programs: input_int("optional text") and input_string("optional text: e.g. Enter your name.") This is an undocumented feature for now.
  • I fixed an obscure "bug" discovered by Andy. When the "World file" is visible, the display was not updated when giving some beepers to the robot. This did not affect in any way the program execution; furthermore, most of the time, the world file viewer was probably hidden. Still, it should now be fixed.
  • Finally, I had removed the requirement to save a program before running it. However, I had made it such that a dialog would pop up if a user was trying to quit without saving a program. Apparently, it would sometimes cause the program to hang. I could not reproduce the bug ...

Optional typechecking: fun with "with"

A while ago, prompted by various entries [1, 2, 3, 4] on Guido's blog about Adding Optional Static Typing to Python, I mused about different ways of doing this [5, 6, 7], keeping the syntax as Pythonic as possible, but at the cost of introducing a new keyword ("where"). Today's entry is written in the same spirit (i.e. just for fun), but with a different syntax, and makes use of the new "with" keyword. By itself, this blog entry is probably too brief to make much sense.

Let me start by introducing some static typing information that could be extracted from an IDE, or used by pychecker or pylint.

01 def gcd(a, b):
02 '''Returns the Greatest Common Divisor,
03 implementing Euclid's algorithm.
04 with __typecheck__:
05 assert isinstance(a, int), 'First argument must be an integer.'
06 assert isinstance(b, int), 'Second argument must be an integer.'
07 #Some doctests for good measure
08 >>> print gcd(6, 3)
09 3
07 '''
08 while a:
09 a, b = b%a, a
10 return b
The above is totally valid Python. Just like doctests can be extracted by the doctest module, the "typecheck" assertions could be extracted and used by other programs. However, as they stand, they are "totally optional".

Now, if we wanted to use the typechecking information in some module where gcd() is actually used, we would have to instruct the interpreter to do so ... here's a way we might want to write this:
1    with __typecheck__:
2 gcd()
3 some_other_useful_function()
4 # the rest of the code follows...


Granted, this is not currently valid in Python ... but its intent should be understandable!

Wednesday, May 10, 2006

Crunchy Frog 0.3

Version 0.3 of "Crunchy Frog" has been released. It can be found at
https://sourceforge.net/project/showfiles.php?group_id=125834

Crunchy Frog transforms a "traditional" Python tutorial into an interactive session within your favourite web browser. Four modes of interaction are currently possible:
1. One-liner, similar to the typical instruction at the Python interpreter.
2. Embedded Python shell, within an html page.
3. Multi-line Python code, as entered in a traditional editor, and executed by Python.
4. Solutions to doctests, as described by Jeff Elkner in a post on edu-sig.

Even though it is an early release, Crunchy Frog could probably already be useful in a classroom situation. To use it, you will also need to have installed Elementtree and CherryPy.

Suggestion: read the 6 page long "tutorial" included, using your favourite browser. Then, start Crunchy Frog, and go through the tutorial again. The whole thing should be doable in approximately 15 minutes ... if you don't spend too much time playing with the interpreter. :-)

Thursday, May 04, 2006

My first CherryPy app.

Using CherryPy, I've just created version 0.1 of "Crunchy Frog". It can be found at
https://sourceforge.net/project/showfiles.php?group_id=125834

Crunchy Frog is just a temporary name for this app. (Read the tutorial for more details.) What it does is to transform a "traditional" Python tutorial into an interactive session within your favourite web browser. Three modes of interaction are currently possible:
1. one-liner, similar to the typical instruction at the Python interpreter.
2. multi-line Python code, as entered in a traditional editor, and executed by Python.
3. Solutions to doctests, as described by Jeff Elkner in a post on edu-sig.

Crunchy Frog is more of a proof-of-concept than a serious application at this point. The code is rather messy, showing my total lack of experience with this type of program (web app). I will very likely rewrite it from scratch for the next release. To use it you will also need to have installed Elementtree (included with Python 2.5?) and CherryPy.

To try it: read the 5 (short) pages long "tutorial" included, using your favourite browser. Then, start Crunchy Frog, and go through the tutorial again. The whole thing should be doable in less than 10 minutes.