[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Functional objects
- From: Mark Hamburg <mhamburg@...>
- Date: Thu, 23 Sep 2004 08:18:59 -0700
One loses direct read/write access to attributes, but closure-based (which
is probably a better term than functional now that I think about it) can
certainly have data as closure values. In fact, this data is more private
and accessed more efficiently since it doesn't involve a table lookup.
Lacking a switch statement, however, method dispatch itself is slower.
local attribute = 1
return function( msg, param )
if msg == "attribute" then
elseif msg == "setAttribute" then
attribute = param
elseif msg == "method" then
-- method code goes here
error( "Unknown message: " .. tostring( msg ) )
In Lua as it presently exists, one needs to write:
obj( "attribute" )
obj( "setAttribute", 2 )
obj( "method" )
With the proposed change one could write:
obj:setAttribute( 2 )
Now, it is true that this also enables one to write
but it doesn't create pressure to do so.
on 9/22/04 12:43 PM, Bilyk, Alex at ABilyk@maxis.com wrote:
> And still this would only apply to those 'objects' that don't have any
> given a table 'object'
> table_object =
> method = function () end,
> attribute = 1
> table_object.attribute = 2
> table_object : method()
> How can one convert this into a functional one? So, the proposed feature would
> only apply to objects that effectively are bags of functions with no data.
> Right? I think, practically, most objects people are dealing with have both
> methods and attributes. Given an function based object, can one use attributes
> with them?
> function_object:method() --> function_object("method")
> function_object.attribute --> ???