Xah Lee wrote:
On Dec 10, 2:47 pm, John W Kennedy <[EMAIL PROTECTED]> wrote:
Xah Lee wrote:
In lisp, python, perl, etc, you'll have 10 or so lines. In C or Java,
you'll have 50 or hundreds lines.
[...]

Thanks to various replies.

I've now gather code solutions in ruby, python, C, Java, here:

• A Example of Mathematica's Expressiveness
  http://xahlee.org/UnixResource_dir/writ/Mathematica_expressiveness.html

now lacking is perl, elisp, which i can do well in a condensed way.
It'd be interesting also to have javascript...

mmm, stone soup...

javascript:

var map = function(fn, a) {
    var b = new Array(a.length);
    for (i = 0; i < a.length; i++) {
        b[i] = fn(a[i]);
    }
    return b
};

var reduce = function(fn, a, init) {
    var s = init;
    for (i = 0; i < a.length; i++) {
        s = fn(s, a[i]);
    }
    return s
};

var sum = function(a) {
    return reduce(function(x, y) { return x + y }, a, 0.0)
};

var norm = function(a) {
    var pow = Math.pow;
    return Math.sqrt(sum(map(function(x) { return pow(x, 2) }, a)))
};

var Unit = function(a) {
    var N = norm(a);
    return map(function(x) { return x/N }, a)
};


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to