examples: lang: Update examples
This commit is contained in:
@@ -7,9 +7,11 @@ class foo {
|
||||
}
|
||||
}
|
||||
|
||||
$wow = "this is wow" # gets captured
|
||||
|
||||
class bar($a, $b) { # a parameterized class
|
||||
print "bar-"+ $a {
|
||||
msg => fmt.printf("inside bar: %s", $b),
|
||||
msg => fmt.printf("inside bar: %s", $b + "; " + $wow),
|
||||
|
||||
Meta:autogroup => false,
|
||||
}
|
||||
|
||||
19
examples/lang/polymorphic-lambda.mcl
Normal file
19
examples/lang/polymorphic-lambda.mcl
Normal file
@@ -0,0 +1,19 @@
|
||||
import "fmt"
|
||||
|
||||
$add = func($x) {
|
||||
$x + $x
|
||||
}
|
||||
|
||||
$num = 2
|
||||
$out1 = $add($num) # 4
|
||||
|
||||
print fmt.printf("%d + %d is %d", $num, $num, $out1) { # simple math
|
||||
Meta:autogroup => false,
|
||||
}
|
||||
|
||||
$val = "hello"
|
||||
$out2 = $add($val) # hellohello
|
||||
|
||||
print fmt.printf("%s + %s is %s", $val, $val, $out2) { # simple concat
|
||||
Meta:autogroup => false,
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import "fmt"
|
||||
import "os"
|
||||
import "strings"
|
||||
import "golang/strings"
|
||||
import "example"
|
||||
|
||||
$input = example.str2int(strings.trim_space(os.readfile("/tmp/cpu-count")))
|
||||
|
||||
Reference in New Issue
Block a user