L# - LISP for .NET

Miklos_HollenderMiklos_Hollender Member Posts: 1,598
edited 2006-09-12 in General Chat
A couple of months ago I wrote about how functional programming is entering into the .NET world: http://www.mibuso.com/forum/viewtopic.php?t=12246 and now I think we are a step forward.

LISP is one of the oldest programming languages still being in production use. The reason it is so, that most current programming languages are based on the theory of the Universal Turing Machine. LISP is not, it's based on another computatunal theory called lambda calculus. Lambda calculus is a computation model where functions are treated as first-class data, therefore, functions can be passed as a parameter or returned as a return value. It is generally considered a more elegant and powerful model than the UTM. LISP is known to be an artifical intelligence research language, simply because that's the hardest discipline in computer science therefore it needed the most powerful language available.

LISP, in a sense, it's a pretty way of writing XML. As the source code is a hierarchical tree, without having any real syntax, the source code itself is a data structure that can be changed algorythmically just like any other tree data structure. Therefore, it's very easy to create domain-specific languages in LISP, so one can change the language itself to suit the problem domain. Viaweb, which was sold to Yahoo! for $40M and became Yahoo! Stores, is one company that demonstrated this approach can be highly successful.

LISP's lack of syntax means you can express everything in a
(function param1 param2 param3 ...)
way.

Therefore,
(+ 5 10)
returns 15,
(= x 10)
sets the variable x to the value of 10, and
(= square (fn (x) 
               (* x x)))

defines a function called square that takes a parameter and returns it's squared. (To put it more clearly, it defines the function and then assignes the function object to the variable called square.)

As it is a tree structure, it can be processed algorithmically by using syntactic macros. For example, there is a defun macro commonly used for a prettier way of defining functions and
(defun square (x) 
          (* x x))

expands into the form written above. This is one simple example how the language itself can be easily changed.

A number of LISP implementations were written for the .NET CLR, but I'd like to recommend L#. You can read a blog about it at http://listeningtoreason.blogspot.com/2 ... -of-l.html, try it out at http://www.lsharp.org/ and download an IDE for it at http://sourceforge.net/projects/xacc

Currently, you cannot define classes and methods in L#, only functions and macros. There are three reasons. First, currently it's aimed at scripting, although class/method features will added later on. Second, although LISP was one of the first languages with powerful OO facilities, it was rarely used, as functional programming - passing and returning functions as data - is at least as powerful as OO. Third, you can write an object system for yourself with but a set of syntactic macros. I mean an object can be simulated by writing a function - the constructor - and defining variables and functions right within this function. Inheritance etc. is but a couple of syntactic macros then. LISP's macro system is so powerful that you can write a LISP interpreter in LISP in but a couple of lines: http://lib.store.yahoo.net/lib/paulgraham/jmc.ps (it's a PostScript document).

I think it worth's a try.

Comments

Sign In or Register to comment.