lang: core: Move template to golang namespace

I don't think this template function should be in any way authoritative,
so let's namespace it.
This commit is contained in:
James Shubin
2024-09-13 15:51:24 -04:00
parent 5bbc06d8bc
commit 29eebd0d07
33 changed files with 110 additions and 43 deletions

View File

@@ -1,4 +1,5 @@
-- main.mcl --
import "golang"
import "iter"
$fn = func($x) { # notable because concrete type is fn(t1) t2, where t1 != t2
@@ -9,7 +10,7 @@ $ins = ["a", "bb", "ccc", "dddd", "eeeee",]
$out = iter.map($ins, $fn)
$t = template("out: {{ . }}", $out)
$t = golang.template("out: {{ . }}", $out)
test "${t}" {}
-- OUTPUT --

View File

@@ -1,4 +1,5 @@
-- main.mcl --
import "golang"
import "iter"
func itermap($a, $b) {
@@ -29,14 +30,14 @@ $out6 = iter.map($in4, func($x) { $x + $x })
$out7 = itermap($in3, func($x) { $x + $x })
$out8 = itermap($in4, func($x) { $x + $x })
$t1 = template("out1: {{ . }}", $out1)
$t2 = template("out2: {{ . }}", $out2)
$t3 = template("out3: {{ . }}", $out3)
$t4 = template("out4: {{ . }}", $out4)
$t5 = template("out5: {{ . }}", $out5)
$t6 = template("out6: {{ . }}", $out6)
$t7 = template("out7: {{ . }}", $out7)
$t8 = template("out8: {{ . }}", $out8)
$t1 = golang.template("out1: {{ . }}", $out1)
$t2 = golang.template("out2: {{ . }}", $out2)
$t3 = golang.template("out3: {{ . }}", $out3)
$t4 = golang.template("out4: {{ . }}", $out4)
$t5 = golang.template("out5: {{ . }}", $out5)
$t6 = golang.template("out6: {{ . }}", $out6)
$t7 = golang.template("out7: {{ . }}", $out7)
$t8 = golang.template("out8: {{ . }}", $out8)
test "${t1}" {}
test "${t2}" {}

View File

@@ -1,4 +1,5 @@
-- main.mcl --
import "golang"
import "iter"
$fn = func($x) { # ignore arg
@@ -9,7 +10,7 @@ $ins = [5, 4, 3, 2, 1,]
$out = iter.map($ins, $fn)
$t = template("out: {{ . }}", $out)
$t = golang.template("out: {{ . }}", $out)
test "${t}" {}
-- OUTPUT --

View File

@@ -1,4 +1,5 @@
-- main.mcl --
import "golang"
import "iter"
$fn = func($x) { # type changes from str to int
@@ -9,7 +10,7 @@ $ins = ["a", "bb", "ccc", "dddd", "eeeee",]
$out = iter.map($ins, $fn)
$t = template("out: {{ . }}", $out)
$t = golang.template("out: {{ . }}", $out)
test "${t}" {}
-- OUTPUT --

View File

@@ -1,4 +1,5 @@
-- main.mcl --
import "golang"
import "iter"
$ins = ["a", "bb", "ccc", "dddd", "eeeee",]
@@ -9,7 +10,7 @@ $out = iter.map($ins, func($x) {
})
$t = template("out: {{ . }}", $out)
$t = golang.template("out: {{ . }}", $out)
test "${t}" {}
-- OUTPUT --

View File

@@ -1,5 +1,6 @@
-- main.mcl --
import "datetime"
import "golang"
$secplus42 = 42 + $ayear
@@ -9,7 +10,7 @@ $ayear = 60 * 60 * 24 * 365 # is a year in seconds (31536000)
$tmplvalues = struct{time => $secplus42, hello => "world",}
print "template-0" {
msg => template("Hello: {{ .hello }}, 42 sec + 1 year is: {{ .time }} seconds, aka: {{ datetime_print .time }}", $tmplvalues),
msg => golang.template("Hello: {{ .hello }}, 42 sec + 1 year is: {{ .time }} seconds, aka: {{ datetime_print .time }}", $tmplvalues),
}
-- OUTPUT --
Vertex: print[template-0]

View File

@@ -1,6 +1,8 @@
-- main.mcl --
import "golang"
$v = 42
$x = template("hello", $v) # redirect var for harder unification
$x = golang.template("hello", $v) # redirect var for harder unification
test "${x}" {
#anotherstr => $x,
}

View File

@@ -1,4 +1,5 @@
-- main.mcl --
import "golang"
import "sys"
$tmplvalues = struct{num => 42, load => $theload,}
@@ -7,7 +8,7 @@ $theload bool = sys.load()->x1 # wrong type, make sure the compiler catches it!
file "/tmp/datetime" {
state => $const.res.file.state.exists,
content => template("num: {{ .num }} seconds\nload average: {{ .load }}\n", $tmplvalues),
content => golang.template("num: {{ .num }} seconds\nload average: {{ .load }}\n", $tmplvalues),
}
-- OUTPUT --
# err: errUnify: error setting type: func() { <built-in:_struct_lookup> }, error: field x1 type error: base kind does not match (bool != float)