[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lists with nil play nice for Lua 5.2
- From: PA <petite.abeille@...>
- Date: Wed, 1 Aug 2007 18:08:40 +0200
On Aug 01, 2007, at 13:30, Roberto Ierusalimschy wrote:
a = new.tuple(2, nil, "foo")
#a -- not available; perhaps a"#" ???
a:insert("baz") -- not available (tuples are immutable)
a(3) -- yields "foo"
a() -- yields 2, nil, "foo"
for i, v in a do ... -- or something like this...
Another wacky implementation with support for 'unpack' of sort:
local Tuple = require( 'Tuple' )
local aTuple = Tuple( 2, nil, 'foo', nil )
print( #aTuple ) -- count
print( aTuple( 3 ) ) -- one value
print( aTuple( '*' ) ) -- all values
for anIndex, aValue in aTuple do -- enumerate
print( anIndex, aValue )
end
> 4
> foo
> 2 nil foo nil
> 1 2
> 2 nil
> 3 foo
Attachment:
Tuple.lua
Description: Binary data