From 9f479d2d093f5656f887c246201ed2fa4a2f1f4b Mon Sep 17 00:00:00 2001 From: c+1 Date: Mon, 22 May 2023 22:38:39 -0400 Subject: man.txt --- examples/hello.halk | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'examples') 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; } -- cgit v1.2.3