## How to teach Functional Programming... in Flash???

A question from the: "You can do my homework!" department.

Since I am an avid lambda reader, and given the recent thread on why people don't use functional programming, I thought I might ask for assistance from the lambda-crowd with a particular problem I have.

These days I am coteaching a Flash course. The language used in Flash is actionscript, which is a javascript derivative, which is a Lisp derivative.

Therefor, Flash might be an excellent aid in teaching functional programming.

However... At the moment my imagination kind of falls short in what kind of interesting examples one could use in a course. I thought about some calculator to showcase closures, or some functional spreadsheet implementation in Flash. They seem boring to me.

So, how would one teach functional programming in Flash, and more to the point: What kind of examples would one use?

Cheers,
Marco

## Comment viewing options

### not sure if the topic is ok for ltu

but some time ago we had a long discussion about functional programming in actionscript at the german flashforum. The thread contains some code examples which might be useful for you. Personally i'd prefer the spreadsheet example though. Unless you speak german, simply skim the thread and copy the yellow code parts.

Cheers
Ralf

### Great

Well, first, thanks for the heads up. I am not a native German speaker but have no problems expressing myself in the language, so thanks for the link.

I am thinking now about doing some graphical reductions, where functional concepts are explicitly shown in the animation. For example, a tree containing some pictures where a fold is applied to the structure resulting in another graph where the evaluation is animated. Or some trivial physics engine, or something.

Hmm, great,
Marco

### Graphics

Given Flash's good support for graphics, why not do something like the classic SICP picture language?

### Check out the 'prototype' library for Javascript

It adds a lot of Ruby/Smalltalk-style functional programming conveniences to the prototypes of core Javascript objects, eg things like:

 Array.prototype.each = function(f) { for (var i = 0; i f(this[i]); } }

 

[1,2,3].each(function(item) { alert('Woo '+item) }); 

### The Little Javascripter

The Little Javascripter might be of interest.

### Hints from Pancito

Perhaps Andrew Cooke's Pancito may provide some inspiration. It is a Haskell module that treats images as functions, allowing for neat transformations.