diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2019-01-01 15:05:58 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2019-01-01 15:07:10 -0800 |
| commit | b6d3cbd61cd08e39d20a569b7c5ece6bb25897dd (patch) | |
| tree | ccf3930b7a2834ffad1a10a9d91f0042542dec34 /containers.moon | |
| parent | 0760d4fb6495c4aa4f74038457acede5063f514a (diff) | |
Misc changes, including text indented interpolations are now indented
relative to the text, not the opening '("', code objects can now remove
all free vars, the REPL uses global vars. Error API is changing a bit.
Diffstat (limited to 'containers.moon')
| -rw-r--r-- | containers.moon | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/containers.moon b/containers.moon index 26c1032..be0925b 100644 --- a/containers.moon +++ b/containers.moon @@ -106,13 +106,6 @@ List = (t)-> return l else error("Unsupported List type: "..type(t)) -walk_items = (i)=> - i = i + 1 - k, v = next(@table, @key) - if k != nil - @key = k - return i, Dict{key:k, value:v} - _dict_mt = __type: "Dict" __eq: (other)=> @@ -133,32 +126,31 @@ _dict_mt = "{"..concat(["#{as_nomsu(k)}: #{as_nomsu(v)}" for k,v in pairs @], ", ").."}" as_lua: => "Dict{"..concat(["[ #{as_lua(k)}]= #{as_lua(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} __bor: (other)=> - ret = {k,v for k,v in pairs(@)} + ret = Dict{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 ret __bxor: (other)=> - ret = {k,v for k,v in pairs(@)} + ret = Dict{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 ret __add: (other)=> - ret = {k,v for k,v in pairs(@)} + ret = Dict{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 ret __sub: (other)=> - ret = {k,v for k,v in pairs(@)} + ret = Dict{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 ret Dict = (t)-> if type(t) == 'table' return setmetatable(t, _dict_mt) @@ -171,8 +163,6 @@ Dict = (t)-> return d else error("Unsupported Dict type: "..type(t)) -for i,entry in ipairs(Dict({x:99})) - assert(i == 1 and entry.key == "x" and entry.value == 99, "ipairs compatibility issue") do {:reverse, :upper, :lower, :find, :byte, :match, :gmatch, :gsub, :sub, :format, :rep} = string @@ -204,7 +194,7 @@ do line_position_at: (i)=> select(3, line_at(@, i)) matches: (patt)=> match(@, patt) and true or false matching: (patt)=> (match(@, patt)) - matching_groups: (patt)=> {match(@, patt)} + matching_groups: (patt)=> List{match(@, patt)} [as_lua_id "* 1"]: (n)=> rep(@, n) all_matches_of: (patt)=> result = {} |
