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.

3 comments:

  1. Anonymous3:26 PM

    just wanted to know , im 27 and just interested in learning programming will this tutorial be a good starting point ,
    im going to start anyways and keep you updated

    ReplyDelete
  2. It should be a good starting point. The only thing is that you will need to install both Python (www.python.org) and wxPython (www.wxpython.org). You should get Python version 2.4 (2.4.3 is the latest, I believe) and wxPython, preferably the unicode version for Python 2.4.

    If you are using Windows, get the "binaries".

    Once they are installed, you can just double-click on rur_start.py and you'll be ready to go.

    ReplyDelete
  3. Anonymous3:23 AM

    Thanx , downloaded and on my way.

    ReplyDelete

Spammers: none shall pass.

Note: Only a member of this blog may post a comment.