Re: Closures versus objects
Mike Newhall <[email protected]>
| Newsgroups | gmane.comp.lang.lightweight |
|---|---|
| Message-ID | <[email protected]> |
At 02:49 AM 2/17/2007 -0800, Steve Dekorte wrote:
>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
They might be separate issues. For example, in the presence of generic functions, which are dispatched dynamically on type and do not introduce any new syntax at the call site, one can have the best of both worlds and do things like:
move_first_to_last = function(seq) { atInsert(seq, 0, popLast(seq)) }
'seq' just needs to be a type for which the two generics used are implemented, the same requirement as in using methods.