lang/interpret_test/TestAstFunc2/polymorphic-stmt-func.txtar
raw| 1 | -- main.mcl -- |
| 2 | import "fmt" |
| 3 | |
| 4 | # this should be a regular polymorphic function |
| 5 | func add($x) { |
| 6 | $x + $x |
| 7 | } |
| 8 | |
| 9 | $num = 2 |
| 10 | $out1 = add($num) # 4 |
| 11 | |
| 12 | test [fmt.printf("%d + %d is %d", $num, $num, $out1),] {} # simple math |
| 13 | |
| 14 | $val = "hello" |
| 15 | $out2 = add($val) # hellohello |
| 16 | |
| 17 | test [fmt.printf("%s + %s is %s", $val, $val, $out2),] {} # simple concat |
| 18 | -- OUTPUT -- |
| 19 | Vertex: test[2 + 2 is 4] |
| 20 | Vertex: test[hello + hello is hellohello] |