Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -7,13 +7,13 @@
[
// 1. Create
#var aMap := Dictionary new.
aMap @ "key" << "foox".
aMap @ "key" << "foo".
aMap @ "key2" << "foo2".
aMap @ "key3" << "foo3".
aMap @ "key4" << "foo4".
aMap set &key:"key" &value:"foox".
aMap set &key:"key" &value:"foo".
aMap set &key:"key2" &value:"foo2".
aMap set &key:"key3" &value:"foo3".
aMap set &key:"key4" &value:"foo4".
// Enumerate
control foreach:aMap &do: &&:aKeyValue
[ console write:(aKeyValue Key) write:" : " writeLine:(aKeyValue Value) ].
control foreach:aMap &do: aKeyValue
[ console write:(aKeyValue key) write:" : " writeLine:(aKeyValue value) ].
].

View file

@ -0,0 +1,19 @@
mydict = [ "hello"=>13, "world"=>31, "!"=>71 ]
# applying a function to key-value pairs:
map(println, mydict);
# iterating over key-value pairs:
for (key,value) in mydict
println("key = $key, value = $value")
end
# iterating over keys:
for key in keys(mydict)
println("key = $key")
end
# iterating over values:
for value in values(mydict)
println("value = $value")
end

View file

@ -0,0 +1,23 @@
import tables
var t: TTable[int,string] = initTable[int,string]()
t[1] = "one"
t[2] = "two"
t[3] = "three"
t.add(4,"four")
echo "t has " & $t.len & " elements"
echo "has t key 4? " & $t.hasKey(4)
echo "has t key 5? " & $t.hasKey(5)
#iterate keys
echo "key iteration:"
for k in t.keys:
echo "at[" & $k & "]=" & t[k]
#itetate pairs
echo "pair iteration:"
for k,v in t.pairs:
echo "at[" & $k & "]=" & v