Files
mgmt/lang/interpret_test/TestAstFunc2/map-iterator1.txtar
James Shubin 9d208e8795 lang: Test more iter funcs without polymorphic id function
This tests the lambdas in more ways so that we are sure non-polymorphic
$id functions work the way we want.
2023-12-27 16:33:38 -05:00

58 lines
1.3 KiB
Plaintext

-- main.mcl --
import "iter"
func itermap($a, $b) {
iter.map($a, $b)
}
func id($x) {
$x + $x
}
$fn_str = func($x) {
id($x)
}
$fn_int = func($x) {
id($x)
}
$in1 = [5, 4, 3, 2, 1,]
$in2 = ["a", "b", "c", "d", "e",]
$in3 = [1, 2, 3, 4, 5,]
$in4 = ["e", "d", "c", "b", "a",]
$out1 = iter.map($in1, $fn_int)
$out2 = iter.map($in2, $fn_str)
$out3 = itermap($in1, $fn_int)
$out4 = itermap($in2, $fn_str)
$out5 = iter.map($in3, func($x) { $x + $x })
$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)
test $t1 {}
test $t2 {}
test $t3 {}
test $t4 {}
test $t5 {}
test $t6 {}
test $t7 {}
test $t8 {}
-- OUTPUT --
Vertex: test[out1: [10 8 6 4 2]]
Vertex: test[out2: [aa bb cc dd ee]]
Vertex: test[out3: [10 8 6 4 2]]
Vertex: test[out4: [aa bb cc dd ee]]
Vertex: test[out5: [2 4 6 8 10]]
Vertex: test[out6: [ee dd cc bb aa]]
Vertex: test[out7: [2 4 6 8 10]]
Vertex: test[out8: [ee dd cc bb aa]]