test, examples: lang: Add new syntax for map lookup

Sugar at last!
This commit is contained in:
James Shubin
2023-10-17 15:32:13 -04:00
parent ea0af4dc43
commit 96093984e4
10 changed files with 18 additions and 23 deletions

View File

@@ -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") {

View File

@@ -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),

View File

@@ -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

View File

@@ -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" {