Patrick Thomson draws a parallel between Haskell monads and jQuery method chaining. The result is the easiest introduction to the concept of monads I've ever read.
A very interesting introduction to Haskell for programmers used to imperative languages: Haskell for C Programmers.
Researching a bit for my previous post about closures in Python and Ruby I found out that they are coming in PHP 5.3. Here is the RFC. Unfortunately it requires declaring the closed variables with the use keyword and provides a justification for it:
PHP's notion of scope is quite different than the notion of scope other languages define. Combine this with variable variables ($$var) and it becomes clear that automatically detecting which variables from the outer scope are referenced inside are closure is impossible.
One of the main attractions (a least for me) of dynamic languages are their functional capabilities. Python has crippled lambdas but makes it up with very powerful stateful generators and generator expressions, even if its scoping rules are a bit fishy.
In comparison Ruby goes in the opposite direction. Being relatively poor on comprehension syntax it makes it up by offering 7 different ways to define a block of code and pass it around, with varying degrees of scoping. Unfortunately most of them appear to be nearly identical and are being kept around just to not break old code. Investigating this matter I found this enlightening sample script from Paul Cantrell:
This is quite a dizzing array of syntactic options, with subtle semantics differences that are not at all obvious, and riddled with minor special cases. It's like a big bear trap from programmers who expect the language to just work.
Paul explains how most of this mess grew out of lacking a formal specification for Ruby as a language, and how most of the ways to define a code block are equivalent and different at the same time. The final conclusion would be to use lambda if you want a true, lexically scoped first order function, and code blocks for everything else. The script finishes with a very cool lazy evaluation example and a pointer to the Lazy gem.
John Resig, the author of the amazing jQuery library, has published his interactive presentation on advanced Javascript topics like first class functions, closures and prototype based OOP. The talk also covers his Javascript port of the Processing language and offers a new demo that compares it with direct Javascript + Canvas programming. More in his blog.
Scripting languages for J2ME
One of the many limitations of J2ME is the lack of dynamic code addition on runtime. It is impossible to add new classes, be it by class files or by reflection. The required APIs are just not included in CLDC. Given this limitation I find it surprising there are not many J2ME hosted script interpreters, specially now that medium and high end handsets have megabytes of available heap memory and fast JIT compilers. Here are the ones I can find.
Imperative languages
FScript, a very simple scripting language, has a J2ME port called FScriptME.
Hecl is a full blown scripting environment for J2ME. It has specific support for J2ME APIs and includes easy to use wrappers for many of them.
The Simple Forth Interpreter has a J2ME port. Forth is a very good fit for the limited resources you find in J2ME handsets but its reverse polish notation and stack-based, hum, everything, are usually very off-putting to programmers.
Lisp dialects
An extremely simple J2ME Lisp interpreter as an OKI software programming exercise. I'm not kidding, run it and see it for yourself. It lacks proper lambda expressions so it's not useful for anything other than as a demonstration, but it could be used as the base of a more complete interpreter (which is what part of the exercise appears to be).
JScheme is small enough to be ported to J2ME, specifically the old 1.x versions which have less bootstrapping implemented in pure Scheme (which allows for a smaller JAR file.) In fact somebody as already ported it to J2ME.
Clang now has support for blocks, which are basically a way to bind stack variables to hidden structs and a pointer to a code block on runtime (link via John Gruber). It's very interesting to compare this approach to C++0x lambda functions. C++ takes the language way, by adding a new syntax to the language and making the feature depend heavily on templates and metaprogramming. Clang is primarily a C and Objective-C compiler and blocks are implemented with small syntax additions and a small runtime library that uses concepts such as reference counting. Very much like Objective-C.
