aboutsummaryrefslogtreecommitdiff
path: root/containers.moon
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-09-06 12:46:39 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-09-06 12:48:16 -0700
commita35d010dfe2b2769cf13ae508952c279aecb3aac (patch)
tree69ce1fcd0123832599d2766d361a8a8b43fcfb4b /containers.moon
parente1bc075bb5319b3903f66e141810dcb9ef53042e (diff)
Removed the mandatory "_" prefix for Nomsu variables, renamed "list" and
"dict" to "List" and "Dict", or in Nomsu's environment, "_List" and "_Dict", removed uuid.lua and replaced it with core/id.nom for handling IDs.
Diffstat (limited to 'containers.moon')
-rw-r--r--containers.moon25
1 files changed, 13 insertions, 12 deletions
diff --git a/containers.moon b/containers.moon
index 2441ccf..68c618b 100644
--- a/containers.moon
+++ b/containers.moon
@@ -1,8 +1,9 @@
-- This file contains container classes, i.e. Lists, Dicts, and Sets
+
{:insert,:remove,:concat} = table
{:repr, :stringify, :equivalent, :nth_to_last, :size} = require 'utils'
-local list, dict
+local List, Dict
-- List and Dict classes to provide basic equality/tostring functionality for the tables
-- used in Nomsu. This way, they retain a notion of whether they were originally lists or dicts.
@@ -28,7 +29,7 @@ _list_mt =
elseif @[i] > other[i] then return false
return true
__add: (other)=>
- ret = list[x for x in *@]
+ ret = List[x for x in *@]
for x in *other
insert(ret, x)
return ret
@@ -55,14 +56,14 @@ _list_mt =
assert type(k) == 'number', "List indices must be numbers"
rawset(@, k, v)
-list = (t)-> setmetatable(t, _list_mt)
+List = (t)-> setmetatable(t, _list_mt)
walk_items = (i)=>
i = i + 1
k, v = next(@table, @key)
if k != nil
@key = k
- return i, dict{key:k, value:v}
+ return i, Dict{key:k, value:v}
_dict_mt =
__eq:equivalent
@@ -71,33 +72,33 @@ _dict_mt =
"{"..concat(["#{repr(k)}: #{repr(v)}" for k,v in pairs @], ", ").."}"
__ipairs: => walk_items, {table:@, key:nil}, 0
__band: (other)=>
- dict{k,v for k,v in pairs(@) when other[k] != nil}
+ Dict{k,v for k,v in pairs(@) when other[k] != nil}
__bor: (other)=>
ret = {k,v for k,v in pairs(@)}
for k,v in pairs(other)
if ret[k] == nil then ret[k] = v
- return dict(ret)
+ return Dict(ret)
__bxor: (other)=>
ret = {k,v for k,v in pairs(@)}
for k,v in pairs(other)
if ret[k] == nil then ret[k] = v
else ret[k] = nil
- return dict(ret)
+ return Dict(ret)
__add: (other)=>
ret = {k,v for k,v in pairs(@)}
for k,v in pairs(other)
if ret[k] == nil then ret[k] = v
else ret[k] += v
- return dict(ret)
+ return Dict(ret)
__sub: (other)=>
ret = {k,v for k,v in pairs(@)}
for k,v in pairs(other)
if ret[k] == nil then ret[k] = -v
else ret[k] -= v
- return dict(ret)
-dict = (t)-> setmetatable(t, _dict_mt)
+ return Dict(ret)
+Dict = (t)-> setmetatable(t, _dict_mt)
-for i,entry in ipairs(dict({x:99}))
+for i,entry in ipairs(Dict({x:99}))
assert(i == 1 and entry.key == "x" and entry.value == 99, "ipairs compatibility issue")
-return {:list, :dict}
+return {:List, :Dict}