diff options
author | c+1 | 2023-05-22 22:38:39 -0400 |
---|---|---|
committer | c+1 | 2023-05-22 22:38:39 -0400 |
commit | 9f479d2d093f5656f887c246201ed2fa4a2f1f4b (patch) | |
tree | ffd569b1e7886bf06f40ec8e0a5d46b5e300f92f /examples | |
parent | d83d37ecd5682252f85af099c3353525f1cb1394 (diff) |
man.txt
Diffstat (limited to 'examples')
-rw-r--r-- | examples/hello.halk | 25 |
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; } |