diff --git a/examples/lang/env1.mcl b/examples/lang/env1.mcl index e1beafcd..fe2a6aa1 100644 --- a/examples/lang/env1.mcl +++ b/examples/lang/env1.mcl @@ -2,7 +2,7 @@ import "fmt" import "sys" $env = sys.env() -$m = map_lookup_optional($env, "GOPATH", "") +$m = $env["GOPATH"] || "" print "print0" { msg => if sys.hasenv("GOPATH") { diff --git a/examples/lang/maplookup1.mcl b/examples/lang/maplookup1.mcl index 7843673e..083a592e 100644 --- a/examples/lang/maplookup1.mcl +++ b/examples/lang/maplookup1.mcl @@ -2,13 +2,13 @@ import "fmt" $m = {"k1" => 42, "k2" => 13,} -$found = map_lookup_optional($m, "k1", 99) +$found = $m["k1"] || 99 print "print1" { msg => fmt.printf("found value of: %d", $found), } -$notfound = map_lookup_optional($m, "k3", 99) +$notfound = $m["k3"] || 99 print "print2" { msg => fmt.printf("notfound value of: %d", $notfound), diff --git a/examples/lang/sendrecv1.mcl b/examples/lang/sendrecv1.mcl index 4bb29f82..dea59fc8 100644 --- a/examples/lang/sendrecv1.mcl +++ b/examples/lang/sendrecv1.mcl @@ -3,7 +3,7 @@ import "world" $ns = "estate" $exchanged = world.kvlookup($ns) -$state = map_lookup_optional($exchanged, $hostname, "default") +$state = $exchanged[$hostname] || "default" exec "exec0" { cmd => "echo hello world && echo goodbye world 1>&2", # to stdout && stderr diff --git a/examples/lang/states0.mcl b/examples/lang/states0.mcl index f7c3dc65..0b5a0ac3 100644 --- a/examples/lang/states0.mcl +++ b/examples/lang/states0.mcl @@ -2,7 +2,7 @@ import "world" $ns = "estate" $exchanged = world.kvlookup($ns) -$state = map_lookup_optional($exchanged, $hostname, "default") +$state = $exchanged[$hostname] || "default" if $state == "one" or $state == "default" { diff --git a/lang/interpret_test/TestAstFunc1/slow_unification0.txtar b/lang/interpret_test/TestAstFunc1/slow_unification0.txtar index 0afe342b..43d1a1f4 100644 --- a/lang/interpret_test/TestAstFunc1/slow_unification0.txtar +++ b/lang/interpret_test/TestAstFunc1/slow_unification0.txtar @@ -4,7 +4,7 @@ import "world" $ns = "estate" $exchanged = world.kvlookup($ns) -$state = map_lookup_optional($exchanged, $hostname, "default") +$state = $exchanged[$hostname] || "default" if $state == "one" or $state == "default" { diff --git a/lang/interpret_test/TestAstFunc2/complex-example.txtar b/lang/interpret_test/TestAstFunc2/complex-example.txtar index f073a967..aa150f15 100644 --- a/lang/interpret_test/TestAstFunc2/complex-example.txtar +++ b/lang/interpret_test/TestAstFunc2/complex-example.txtar @@ -16,10 +16,8 @@ $generate = func($idn) { $foo = iter.map([$id1, $id2,], $generate) -#test $foo[0] {} -#test $foo[1] {} -test list_lookup_optional($foo, 0, "fail") {} # TODO: add syntactic sugar for list_lookup_optional -test list_lookup_optional($foo, 1, "fail") {} # TODO: add syntactic sugar for list_lookup_optional +test $foo[0] || "fail" {} +test $foo[1] || "fail" {} -- OUTPUT -- Vertex: test[foo] Vertex: test[foofoo] diff --git a/lang/interpret_test/TestAstFunc2/listlookup.txtar b/lang/interpret_test/TestAstFunc2/listlookup.txtar index ab6a92db..82368452 100644 --- a/lang/interpret_test/TestAstFunc2/listlookup.txtar +++ b/lang/interpret_test/TestAstFunc2/listlookup.txtar @@ -3,12 +3,10 @@ $l1 = ["a", "b", "c",] $l2 = [$l1, ["hello", "world",],] -#test $l1[0] {} -#test $l1[1] {} -test list_lookup_optional($l1, 0, "fail") {} # TODO: add syntactic sugar for list_lookup_optional -test list_lookup_optional($l1, 2, "fail") {} # TODO: add syntactic sugar for list_lookup_optional -test list_lookup_optional($l1, 3, "pass") {} # TODO: add syntactic sugar for list_lookup_optional -test list_lookup_optional($l2, 1, ["fail",]) {} # TODO: add syntactic sugar for list_lookup_optional +test $l1[0] || "fail" {} +test $l1[2] || "fail" {} +test $l1[3] || "pass" {} +test $l2[1] || ["fail",] {} -- OUTPUT -- Vertex: test[a] Vertex: test[c] diff --git a/lang/interpret_test/TestAstFunc2/maplookup0.txtar b/lang/interpret_test/TestAstFunc2/maplookup0.txtar index cfda5f69..3dc5aa47 100644 --- a/lang/interpret_test/TestAstFunc2/maplookup0.txtar +++ b/lang/interpret_test/TestAstFunc2/maplookup0.txtar @@ -1,15 +1,15 @@ -- main.mcl -- $map1 map{int: str} = {42 => "hello1",} -test map_lookup_optional($map1, 42, "not found") {} +test $map1[42] || "not found" {} $map2 map{int: str} = {42 => "hello2",} -test map_lookup_optional($map2, 13, "world2") {} +test $map2[13] || "world2" {} $map3 = {42 => "hello3",} -test map_lookup_optional($map3, 42, "not found") {} +test $map3[42] || "not found" {} $map4 = {42 => "hello4",} -test map_lookup_optional($map4, 13, "world4") {} +test $map4[13] || "world4" {} -- OUTPUT -- Vertex: test[hello1] Vertex: test[hello3] diff --git a/lang/interpret_test/TestAstFunc2/very-complex-example.txtar b/lang/interpret_test/TestAstFunc2/very-complex-example.txtar index 1e60037c..12505467 100644 --- a/lang/interpret_test/TestAstFunc2/very-complex-example.txtar +++ b/lang/interpret_test/TestAstFunc2/very-complex-example.txtar @@ -72,7 +72,6 @@ $generate = func($idn) { # this code should be rejected during type unification $foo = iter.map([$id1, $id2,], $generate) -#test $foo[0] {} -test list_lookup_optional($foo, 0, "fail") {} # TODO: add syntactic sugar for list_lookup_optional +test $foo[0] || "fail" {} -- OUTPUT -- # err: errUnify: can't unify, invariant illogicality with equals: base kind does not match (Str != Int) diff --git a/test/shell/env0.mcl b/test/shell/env0.mcl index a3730087..e259c0ab 100644 --- a/test/shell/env0.mcl +++ b/test/shell/env0.mcl @@ -15,7 +15,7 @@ $t = sys.hasenv("TEST") $f = sys.hasenv("DOESNOTEXIST") $env = sys.env() -$m = map_lookup_optional($env, "TEST", "321") +$m = $env["TEST"] || "321" file "${tmpdir}/environ" { state => $const.res.file.state.exists,