diff options
author | c+1 | 2023-05-10 09:44:13 -0400 |
---|---|---|
committer | c+1 | 2023-05-10 09:44:13 -0400 |
commit | 18d845732524d0b2982374135e0d24abfe8c0a5e (patch) | |
tree | 7e864f33ae1ca02e27b04db566c8c47b97a4a917 /examples | |
parent | 5b303a0c3262a207b35d255ff52ce524f6e03d4c (diff) |
hello, halk
Diffstat (limited to 'examples')
-rw-r--r-- | examples/hello.halk | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/examples/hello.halk b/examples/hello.halk index 6f87160..ae388eb 100644 --- a/examples/hello.halk +++ b/examples/hello.halk @@ -1,30 +1,35 @@ [comments in square brackets] [preprocessor directives] -#INCLUDE 'math.halk'; [looks for a 'math' file in cwd, then ~/halk/include] -#INCLUDE 'io' AS ''; [bring everything in 'io' into global scope] +#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] -let.hello -> 'hello, '; [variables must be given a value at declaration] +let.hello -> 'hello, '; [variables must be given a value at declaration] -let.PI => math/PI; [header namespaces are accessed with a '/'] - [constants are denoted with a '=>'] +let.PI => math/PI; [namespaces are accessed with a '/'] + [constants are denoted with a '=>'] -fn.greeting.to -> { ['fn' only expects 1 argument, so no grouping of arguments is necessary] - let.message -> str.cat.(hello,to); [parens can be used to make calls to multi-argument - functions more clear] +fn.greeting.to -> { [functions defined with: `fn.<name>,<argument>,..., -> {<body>};`] + let.message -> str.cat.hello,to; [functions are right-associative] - stdo.message; [since 'io' was brought into global scope, we - don't need to (and, in fact, cannot) prefix it - with a namespace] + stdo.message; [since 'io' was brought into global scope, we + do not prefix it with a namespace/] }; -fn.sum_all._ -> { [variadic functions are possible with the reserved '_' argument, - which is treated as an array] +fn.sum_all._ -> { [variadic functions are possible with the reserved '_' argument, + which is treated as an array] return.foldl.+,0,_; }; +fn.fibonacci.n -> { + if.or.(num=?.n, 0), (num=?.n, 1) -> { [functions ending in '?' should be predicates] + return.1; + }; + return.+.(fibonacci. -.n, 1), (fibonacci. -.n, 2); [parens can be used to group function application] +}; + fn.main -> { [where our code will begin executing] greeting.[comments can be placed *anywhere*]"world."; - exit.0; [exit with code 0] + exit.0; [exit with code 0 for success] }; |