You may want to check out the extension library we (Sjoerd Visscher and I) have created. You can find it over at http://w3future.com/weblog/
This library, called Beyond JS, provides functional programming features for JavaScript language. Since JavaScript is based on Self, you get the benefit of both these "obscure" languages
We have yet to document this library, or QAed it sufficiently, but we are giving the source for free. You can get both the lib and some sample code from here.
An example of what can be done with beyond.js. First an example of some Haskell code, which is a used to explain some of the benefits of Haskell:
qsort [] = []
qsort (x:xs) = qsort elts_lt_x ++ [x] ++ qsort elts_greq_x
where
elts_lt_x = [y | y <- xs, y < x]
elts_greq_x = [y | y <- xs, y >= x]
With beyond.js, this type of code can be done in javascript too. This is the code to add a qsort method to arrays:
_AP.qsort = Array.recurse(function(head, tail) {
var elts_greq = [];
var elts_lt = tail.filter(function(v) { return v
return elts_lt.qsort().concat(head, elts_greq.qsort());
});
// this is how to use qsort:
alert([ 5, 3, 4, 2, 1 ].qsort());
Here is another sample:
function fac(n) {
return n.to(1).fold("*");
}
alert(fac(6));
Although both these samples use a version of the lib that is slightly newer than the one currently online, they do demonstrate its design and features.
We invite everyone to try it out. At the very least it should give new perspectives on what can be done with JavaScript.
You may want to check out the extension library we (Sjoerd Visscher and I) have created. You can find it over at http://w3future.com/weblog/
This library, called Beyond JS, provides functional programming features for JavaScript language. Since JavaScript is based on Self, you get the benefit of both these "obscure" languages
We have yet to document this library, or QAed it sufficiently, but we are giving the source for free. You can get both the lib and some sample code from here.
An example of what can be done with beyond.js. First an example of some Haskell code, which is a used to explain some of the benefits of Haskell:
qsort [] = []qsort (x:xs) = qsort elts_lt_x ++ [x] ++ qsort elts_greq_x
where
elts_lt_x = [y | y <- xs, y < x]
elts_greq_x = [y | y <- xs, y >= x]
With beyond.js, this type of code can be done in javascript too. This is the code to add a qsort method to arrays:
_AP.qsort = Array.recurse(function(head, tail) {var elts_greq = [];
var elts_lt = tail.filter(function(v) { return v return elts_lt.qsort().concat(head, elts_greq.qsort());
});
alert([ 5, 3, 4, 2, 1 ].qsort());
Here is another sample:
function fac(n) {return n.to(1).fold("*");
}
alert(fac(6));
Although both these samples use a version of the lib that is slightly newer than the one currently online, they do demonstrate its design and features.
We invite everyone to try it out. At the very least it should give new perspectives on what can be done with JavaScript.