Driving iTunes with Scheme, with a fold tutorial and a Haskell book

In this pretty detailed tutorial, Jim Ursetto puts his Cocoa/Chicken bridge to work. Jim noticed that some of his music files were forgotten by iTunes, and wanted to reimport them without losing any metadata. His article

documents my attempt to do just that by building an application in Chicken Scheme, using the bindings to Objective-C and Cocoa provided by the objc egg. It’s targeted at the intermediate Scheme programmer, who may have some experience with Cocoa. It may also be useful to a beginner looking for examples of an interactive development process, and to a non-Scheme user for the same reason.

Jim has taken the time to document also the program’s design and coding processes, so you’ll not only learn about Cocoa or how to use the Scheme bridge, but also about property lists parsing, symlink creation or exception handling. In addtion, you will have the chance of looking over a fellow programmer shoulder having fun for a while.

Programming in HaskellIt’s a long read, but a very good one. And just in case you don’t get to the end, don’t miss Jim’s last recommended reading: a tutorial on the expressiveness and universality of fold, by Graham Hutton. Graham, by the way, happens to be a Haskell and functional programming erudite and professor, so you may be interested in his publications, including the forthcoming book Programming in Haskell, whose first five chapters are available in PDF here.

Tags: , , , , ,

Counting by lambdas

One of the nice things about functional languages is that you’re closer to the mathematical underpinnings of computer programming. Now, maybe you don’t like maths, but then you’ll have to learn to live with a necessary evil, for trying to be serious about programming without taking the plunge into abstract thinking is like wanting to be an astronomer without writing down a single equation. In my experience, both in the industry and as a CS teacher, the ability of abstraction is the most useful and, unfortunately, hardest to find quality when it comes to programming.

Structure and interpretation of computer programs I entered the functional programming world some years ago through a golden gate: SICP. It was an amazing journey full of magical moments: recursion, higher-order functions, generics, lazy evaluation, metacircular interpreters, compilers… a journey i have reedited many times afterwards… i still watch a SICP lecture now and then instead of taking my TV to the repair shop.

Among those moments, one that i specially recall is my first encounter with Church Numerals. I remember staring blankly for quite a while to the code in exercise 2.6:

(define zero (lambda (f) (lambda (x) x)))

(define (add-1 n)
(lambda (f) (lambda (x) (f ((n f) x)))))

And then something clicked in, and i’ve been amazed ever since. Of course, Church numerals are just the tip of the iceberg: from there i went to learn Lambda Calculus, and realized that there were powerful and deep principles at play underneath that fun hacking hobby of mine.

Things can get pretty hairy from here. If you think that the above lambda tricks are old hat and not worth such a fuss, take a look at the impressive fireworks of Oleg’s with Lambda Calculus, Scheme and Haskell, including negative numbers, substraction and division: i’m sure you will find them much more fun.

But if you’d rather follow a gentler path through this magic, the better introduction i’ve read is Chris Hankin’s An Introduction to Lambda Calculi for Computer Scientists. Or, if you prefer online stuff, this javascript-enabled lambda tutorial. From there, you can go to… well, to many places. For instance, McCarthy’s original paper on Lisp, or any of the Lambda Papers by Steele and Sussman. And of course, if you want to get to the very marrow of it, Barendregt’s Shorter introduction to the lambda calculus (free PDF), and the definitive The Lambda Calculus, its syntax and semantics will keep you busy for quite a while. Enjoy!

Tags: , , , , , , ,

Faster and smaller Haskell, with a pointer to Qi

Haskell is one of those languanges i keep an eye on, accumulating links and books in my maybe/someday task list (the other forerunner in there being Smalltak). To be fair, i’ve actually read a couple of tutorials and books, but, for some reason or the other, it never sticks in (a minor nit that, in the long run, ends up being a hurdle is that, unlike Smalltalk’s, i find Haskell’s syntax ugly).

Haskell has a long list of features that make it an excellent, and sometimes unique, language. Some of them i miss in Lisp, like (built-in) pattern matching a la ML or currying, which fits like a glove in a functional programming style (if you’re in maths or physics or for some other reason play a lot with tensors, you’ll be currying all the time). As an aside, some months ago i noticed that i am not the only one to miss these features in Lisp: Lambda Associates‘s Qi extends Lisp precisely in those directions (and then more).

Another fun feature of Haskell is laziness (but we have that in Scheme too). On the one hand, it provides the means for extremely elegant constructions, like e.g. circular, infinite data structures. On the other hand, it poses lots of challenges when it comes to evaluate and/or guarantee time and space requirements for your programs. I just found and article entitled Making Haskell programs faster and smaller which makes an in-depth analysis of these (potential) problems, with solutions, that may help you in your Haskell adventures. My unqualified opinion is that i prefer the Scheme way: call by value by default, with call by need, well, when needed.

Tags: ,

Follow

Get every new post delivered to your Inbox.

Join 42 other followers