Monday, January 13, 2014

Teaching Functional Programming With A Chicken That Crosses the Road

I'm currently teaching a third year course on programming paradigms.  For functional programming we look at Scheme, and for logic programming, Prolog.  I took this course when I was an undergrad, and it looks like not much has changed since then.  I decided to take a look at the visual image and animation contexts now available to help students get a good feel for Scheme right up front.  I hope to continue using these sorts of examples to help make new abstract concepts about Scheme easier to understand (though how well I do with that remains to be seen).


I started my search for teaching materials at How to Design Programs, Second Edition.  This free online book teaches programming from the ground up, and assumes no prior experience.  In some ways this is good, even for third year CS majors who are learning functional programming for the first time.  It can't be our main text, but there are many good sections to reference.

Even better, the book features DrRacket's image and universe teachpacks.  That means that there are some fun, visual examples among the usual traditional applications of programming.  That's where I started to learn about these tools, since I had never seen them before myself.

Another resource I found helpful was How to Design Worlds, a supplementary online book that covers how to use an older version of universe and the related worlds.  From there, I found the chicken-crossing-the-road example you see in the screenshot above.  The code for the chicken project is available online - the only problem is that it's based on the old teachpacks, and doesn't run out of the box in the newest DrRacket IDE.

Not to worry - I updated the code (which was not much work in the end), and added a few useful comments.  If you'd like to make use of it, download the zip.  If you are just learning Scheme, try using this as a fun example to get you started.  Good luck!

1 comments:

Doug Blank said...

Thank you for pointers to these resources! I didn't know that the second edition was also on-line. By the way, we also have Scheme (well, much of the language anyway) that can do very nice graphics, including a version of the Processing system. Our Graphics library has built-in Physics, and we have a robot simulator. At our site, http://calicoproject.org, many examples are in Python, but almost all also work in Scheme (and other languages) too.

Post a Comment

Comments are moderated - please be patient while I approve yours.