lang: funcs: Add lookup default func for list or map

This version requires you specify the default value.
This commit is contained in:
James Shubin
2023-10-11 19:33:29 -04:00
parent d1c15bd0b7
commit d6a58f33f3
2 changed files with 582 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
-- main.mcl --
$l1 = ["a", "b", "c",]
$l2 = [$l1, ["hello", "world",],]
test $l1[0] || "fail" {}
test $l1[2] || "fail" {}
test $l1[3] || "pass" {}
test $l2[1] || ["fail",] {}
$map1 map{int: str} = {42 => "hello1",}
test $map1[42] || "not found" {}
$map2 map{int: str} = {42 => "hello2",}
test $map2[13] || "world2" {}
$map3 = {42 => "hello3",}
test $map3[42] || "not found" {}
$map4 = {42 => "hello4",}
test $map4[13] || "world4" {}
$map5 = {"wow" => "pass1",}
test $map5["wow"] || "fail" {}
$map6 = {"wow" => "fail",}
test $map6["mom"] || "pass2" {}
-- OUTPUT --
Vertex: test[a]
Vertex: test[c]
Vertex: test[hello1]
Vertex: test[hello3]
Vertex: test[hello]
Vertex: test[pass1]
Vertex: test[pass2]
Vertex: test[pass]
Vertex: test[world2]
Vertex: test[world4]
Vertex: test[world]