lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thu, 28 Oct 2010 16:05:10 -0200
Renato Maia <maia@inf.puc-rio.br> wrote:

> I followed a different approach for this problem [1] borrowing some  
> ideas from the way Lua handle strings. My idea was that each tuple  
> value should be a single value in the Lua state instead of creating  
> different tables to represent the same tuple and using '__eq' to  
> change the way they are compared for equality. In other words:
> 
>    assert(rawequal(tuple.create(1,false,table),  
> tuple.create(1,false,table)))
> 
> The main advantage of this approach is that tuples can be used as  
> table keys just like any other value. Therefore, there is no need to  
> implement special tables or complex data structures that work with the  
> tuples:
> 
>    t = { [tuple.create(1,false,table)] = "number, boolean and table" }
>    print(t[tuple.create(1,false,table)]) --> number, boolean and table
> 
> A simple way to compare my approach to yours is to think that there is  
> only a single instance of your "index table" inside my 'tuple' module.  
> This internal "index table" is used to store all tuples created so  
> they can be easily recovered when a tuple with the same values is  
> "created" again.

I like very much the Lua way of making every value unique, with the obvious advantage in comparison, esp. when those values are used as keys. But wondered how this can be made efficient. Also why other dynamic language do not use the same strategy...
What method does, in your case, tuple.create use to check wether a given tuple _value_ already exists? Are they sorted -- how? For comparison, is there any other way than blindly comparing tuple-table content (when cardinals match)?


Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com