lua-users home
lua-l archive

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


Dirk Laurie <dpl@sun.ac.za> writes:

> On Wed, Dec 15, 2010 at 06:56:12AM +0200, David Manura wrote:
>> you'd probably prefer it in the
>> form of slices instead: `t[3:6] = ...` (i.e. replace elements 3
>> through 6 with the elements in the vararg list).
>
> Two extensions to Lua needed:
>     3:6             --> {3,4,5,6}
>     a[{3,4,5,6}]    --> {a[3],a[4],a[5],a[6]}
> Will this break many programs?  I doubt it: table-valued keys
> are close to useless.

Huh?  Why would they be useless?  You can store additional info for
tables in them without touching the table itself, with different
scoping.  After all, identity for tables is not based on their contents,
but their existence.

Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> a={}
> b={}
> print(a==b)
false
> zup={}
> zup[a]="this is a"
> a[1]=4
> a.x="f"
> print(zup[a])
this is a
> 

>> a[{1,2}]='s'
>> print(a[{1,2}])
> nil
> At present a table-valued key hashes the address of the table.
> You can't use it, as I tried above, to simulate double indexing.

But you can use it to index information pertaining to table identity.

-- 
David Kastrup