Re: Closures versus objects
Steve Dekorte <[email protected]>
| Newsgroups | gmane.comp.lang.lightweight |
|---|---|
| Message-ID | <[email protected]> |
On 16 Feb 2007, at 04:35 pm, [email protected] wrote: >> non-pure dynamic object code has type >> dependencies, which are at odds with code reuse and flexibility. > Regardless I am puzzled by your last sentence. What dependencies are > you talking about? Consider the function: list_move_first_to_last = function(list) { list_at_insert(list, 0, list_pop_last(list)) } Notice how each of those functions is dependent on the list type. Now consider a collection method like: Sequence moveLastToFirst := method(atInsert(0, popLast)) in a dynamic OO language, where the method calls are dynamically bound, that method could work on *any* object that implements atInsert and popLast - be it a Vector, a String, a SortedMap, a List, etc. This reusability is the result of dynamic binding. Now we can do dynamic binding with functions: Object_add_method(Collection, Collection_move_first_to_last, function (collection) { Object_send(collection, Collection_at_insert, 0, Object_send (collection, Collection_pop_last)) } Now we get the benefits of dynamic binding, but at the cost of (at least) mixed semantics. - Steve