Thursday, January 25, 2007

A subtle difference

Consider the the following
(define (power-n x)
(define power-x
(lambda (n)
(if (= n 0)
(list 1)
(cons (power x n) (power-x (- n 1))))))
power-x)
The above definition basically defines a generator function. A slightly different definition using a named let is

(define (power-n x)
(lambda (n)
(let power-x ((n n))
(if (= n 0)
(list 1)
(cons (power x n) (power-x (- n 1)))))))
In the first case, we define power-x and then explicitly return it. In the second version, we create an anonymous function and return that automatically.

In both cases, we can create generators such as power-two as
(define (power-two n)
((power-n 2) n))
Thanks to a thread on comp.lang.scheme for fixing things!

Myopic view of

Saturday, January 20, 2007

Scheme48 + Cygwin + Xemacs

I had installed MIT Scheme to use as my base for learning Scheme. I created a nice little phone book language that would operate on a database of phone book entries. However, there was no way to use the little language other than by first starting MIT Scheme and then loading the file. This was cumbersome, but it was still a toy project.

I recently installed XEmacs. I'm basically a VIM guy but I wanted to try out the *other* editor philosophy :-). All said and done, it was still configured to use VIPER! I knew that emacs and friends use a lisp dialect and so it would be fun to see what its like to have an integrated enviroment.

After a quick search, I found a package for XEmacs that allows it to run an inferior scheme process i.e as a child. However running MIT Scheme screwed things up. On Windows, the parent-child I/O model is quite different from what XEmacs wanted and as a result it was not going to work.

So, I installed Scheme48. Installed is not quite the right term, because there is a native windows application available. Instead, I downloaded the source and built it on top of cygwin. That's when all the problems that are associated with a 'minimalist' language like scheme hit. MIT scheme has its own library of useful utilities and its own functions for things like File I/O. I spent an hour or so cleaning up and moving to Scheme48.

The end result? Much happier. XEmacs run scheme48 as an inferior process quite nicely. Plus, I getting a hang of some of the XEmacs commands that run on the inferior process or for that matter even a shell. So, I now have my phone book application and I don't have to leave XEmacs. Perhaps, there is something to this *different* philosophy after all :-)

Myopic view of , ,