Functional late binding for arrays
Posted by jonnymind on 2008-08-23
Functional late binding and automatic symbol generation in functional sequences (planned for 0.8.12) has been added, with some extra features that wasn't originally thought.
The '&' operator creates a "late binding" falcon item type. Late binding are "exploded" at function calls into the content of a late binding dictionary, which is specific for each array, and can be set and/or inspected via the '.' accessor before, during and after the functional evaluation.

In example, it is now possible to create a functional loop like this:

a = .[ times 100000 &count .[
.[printl &count]
]
]
a() // or eval(a)

> "Final value: ", a.count


But it is also possible to compose functions like this:

b = []
b.greeting = "Hello world"
b += printl
b += &greeting
b()


As late bindings are falcon items it is possible to store them in arbitrary variables. In example, the functional loop may be rewritten as:

x= &count
a = .[ times 100000 x .[ .[printl x] ]]


As bindings are internally stored as special strings, we will provide also functions that will generate bindings on the fly from dynamic content.

Also, we'll extend the dynamic property access support to the arrays, so that it is possible to access/store properties by name.

We have now two new abilities which can be merged or used separately; the ability to add flexible oop-like properties and methods to arrays, which can serve as classless and dynamic oop constructs, and the ability to automatically create references to symbols by name. When used together, like in the example I shown here, they are quite powerful.


Close this window