aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/hello.halk25
1 files changed, 19 insertions, 6 deletions
diff --git a/examples/hello.halk b/examples/hello.halk
index 719ba93..7ec14b8 100644
--- a/examples/hello.halk
+++ b/examples/hello.halk
@@ -1,14 +1,14 @@
` comments in backticks `
` preprocessor directives `
-#INCLUDE##math#
-#INCLUDE##io#
+#MACRO##PI##3.14159#
+#IFNDEF##HELLO#
+ #DEF##HELLO#
+#ENDIF#
` source code begins here `
str:hello = 'hello, '; ` variables must be given a value at declaration `
-int:PI = math/PI; ` namespaces are accessed with a '/'' `
-
void:greeting. str:to = { ` functions declared the same way as variables, but with a . after
the name, followed by arguments `
@@ -18,11 +18,24 @@ void:greeting. str:to = { ` functions declared th
do not prefix it with a namespace/ `
}
-int:sum_all. any[]:_ = { ` variadic functions are possible with the reserved '_' argument,
+int:sum_all. int[]:_ = { ` variadic functions are possible with the reserved '_' argument,
which is treated as an array `
return.foldl.sum, 0, _;
}
+namespace:new_namespace = { ` create a new namespace `
+ int:value = 1;
+
+ int:sum_all. int[]:_ = {
+ return.foldl.sum,0,_;
+ }
+}
+
+check_expect.(sum_all. 1, 2, 3, 4), 10; ` tests `
+check_expect.
+ (sum_all. 1, 2, 3, 4),
+ (new_namespace/sum_all. 1, 2, 3, 4);
+
int:fibonacci. int:n = {
if.(eq.n, 0), {
return.1;
@@ -34,7 +47,7 @@ int:fibonacci. int:n = {
}
int:main. str[]:args = { ` where code will begin executing `
- greeting.` comments can be placed *anywhere* `'world.';
+ greeting.'world.'; ` returns 'hello, world.' `
return.0;
}