TOPIC: A Trick Borrowed from JavaScript
A Trick Borrowed from JavaScript 1 Year, 7 Months ago
I just finished reading JavaScript: The Good Parts (recommended)

One of its examples of functional programming seemed like a good thing to add to Suneido.

The goal is to write something like:

list = [[name: 'Fred', age: 23], [name: 'Andy', age: 45]]

To enable this, you define By as:

function (field)
    return {|x, y| x[field] < y[field] }

Unlike JavaScript, Suneido functions are not lexically scoped, so they would not work for this. But blocks are lexically scoped so they work fine.

Note: In Suneido you could also write this as:


list.Sort({|x, y| < })
Last Edit: 2009/01/07 16:39 By andrew.