aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorc+12023-05-18 18:13:41 -0400
committerc+12023-05-18 18:13:41 -0400
commit5ab53b80334b6a9e849c46bd2998b163b0b7f72c (patch)
tree1e641d7fd42a7258ace525dc75da9d087978b0f4 /examples
parentf6ae20caf8191f78eea90edfb17f316db8f8c6b5 (diff)
update hello.halk with new syntax
Diffstat (limited to 'examples')
-rw-r--r--examples/hello.halk59
1 files changed, 31 insertions, 28 deletions
diff --git a/examples/hello.halk b/examples/hello.halk
index 06a3d95..8b6b038 100644
--- a/examples/hello.halk
+++ b/examples/hello.halk
@@ -1,37 +1,40 @@
-[comments in square brackets]
+` comments in backticks `
-[preprocessor directives]
-#INCLUDE 'math.halk'; [looks for a 'math.halk' file in the cwd, then ~/halk/include]
-#INCLUDE 'io' AS ''; [bring everything in 'io' into global scope]
+` preprocessor directives `
+#INCLUDE.'math', 'm'; ` bring the math library into scope, under the namespace 'm' `
+#INCLUDE.'io', ''; ` bring the io library into global scope (with no namespace) `
-let.hello -> 'hello, '; [variables must be given a value at declaration]
+str:hello = 'hello, '; ` variables must be given a value at declaration `
-let.PI => math:PI; [namespaces are accessed with a ':'']
- [constants are denoted with a '=>']
+int:PI = math/PI; ` namespaces are accessed with a '/'' `
-fn.greeting,to -> { [functions defined with: `fn.<name>,<argument>,..., -> {<body>};`]
- let.message -> strcat.hello,to; [functions are right-associative]
+void:greeting. str:to = { ` functions declared the same way as variables, but with a . after
+ the name, followed by arguments `
- stdo.message; [since 'io' was brought into global scope, we
- do not prefix it with a namespace/]
-};
+ str:message = strcat.hello, to; ` function application is right-associative `
-fn.sum_all,_ -> { [variadic functions are possible with the reserved '_' argument,
- which is treated as an array]
- return.foldl.sum,0,_;
-};
+ stdo.message; ` since 'io' was brought into global scope, we
+ do not prefix it with a namespace/ `
+}
-fn.fibonacci,n -> {
- if.or.(eq.n, 0), (eq.n, 1) -> { [functions ending in '?' should be predicates]
+int:sum_all. any[]:_ = { ` variadic functions are possible with the reserved '_' argument,
+ which is treated as an array `
+ return.foldl.sum, 0, _;
+}
+
+int:fibonacci. int:n = {
+ if.(eq.n, 0), {
return.1;
- };
- return.sum.
- (fibonacci. sub.n, 1),
- (fibonacci. sub.n, 2);
-};
-
-fn.main -> { [where our code will begin executing]
- greeting.[comments can be placed *anywhere*]'world.';
- exit.0; [exit with code 0 for success]
-};
+ }, {
+ return.sum.
+ (fibonacci.(sub.n, 1)),
+ (fibonacci.(sub.n, 2));
+ }
+}
+
+int:main. str[]:args = { ` where code will begin executing `
+ greeting.` comments can be placed *anywhere* `'world.';
+
+ return.0;
+}