aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/hello.halk60
-rw-r--r--examples/preprocessor.halk4
-rw-r--r--examples/simple.halk4
3 files changed, 30 insertions, 38 deletions
diff --git a/examples/hello.halk b/examples/hello.halk
index 62b8360..6e5f7bf 100644
--- a/examples/hello.halk
+++ b/examples/hello.halk
@@ -1,42 +1,36 @@
-:str:hello = 'hello, ';
-:void:greeting. :str:to = { ` functions declared the same way as variables, but with a . after
- the name, followed by arguments `
+` comments in backticks `
- :str:message = strcat.hello, to; ` function application is right-associative `
+#inc# #somefile.halk# ` include a file `
+#inc# #stdio# ` include the 'stdio' header (file path stored in the macro #stdio#) `
- io/stdo.message; ` navigate namespaces with a '/' `
-}
+:str:hello = "Hello"; ` define a variable 'hello' with the type 'str' `
-:int:sum_all. :int[]:_ = { ` variadic functions are possible with the reserved '_' argument,
- which is treated as an array `
- return.foldl.sum, 0, _;
-}
+:str:greet.:str:target = strcat.hello, ", ", target; ` define a function 'greet' that returns a 'str' and accepts an
+ argument 'target', also of type 'str' `
-:namespace:new_namespace = { ` create a new namespace `
- :int:value = 1;
+` some more functions `
+:void:add1. :int:n = n = +. n, 1;
+:int:fac.:int:n=if.(==.n,0),1,*.n,fac.-.n,1;
- :int:sum_all. :int[]:_ = {
- return.foldl.sum,0,_;
- }
-}
+:int:fib. :int:n = if. (<=. n, 1), ` multiple lines can be used for clarity `
+ n,
+ +. fib.(-. n, 1), fib. -. n, 2);
-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;
- }, {
- return.sum.
- (fibonacci.(sub.n, 1)),
- (fibonacci.(sub.n, 2));
- }
-}
-:int:main. :str[]:args = { ` where code will begin executing `
- greeting.'world.'; ` prints 'hello, world.' `
+:void:print_greet.:str:target = stdio/pln.greet.target; ` namespaces `
+
+:namespace:people = { ` create namespace `
+ struct.person, :int:age, :str:name; ` create a struct -- syntax not finalized `
+
+ :str:person_report. :struct:person = {
+ :str:age = int->str.person.age;
+ :str:name = person.name;
- return.0;
+ strcat. "NAME:\t", name, "\nAGE:\t", age;
+ }
+
+ :void:person_birthday. :struct:person = {
+ stdio/pln. "Happy birthday, ", person.name;
+ person.age = +.person.age, 1;
+ }
}
diff --git a/examples/preprocessor.halk b/examples/preprocessor.halk
index d68748e..9e3f6b5 100644
--- a/examples/preprocessor.halk
+++ b/examples/preprocessor.halk
@@ -19,11 +19,11 @@
#ddo# #BSD# #inc# #bsd_support.halk#
#udo# #OS# #
- some-error-func."os not specified";
+ some_error_func."os not specified";
#
#def# #OSTYPE# #
os/shell."sysctl kernel.ostype"
#
-io/print.#OSTYPE#
+stdio/pln.#OSTYPE#
diff --git a/examples/simple.halk b/examples/simple.halk
index 80d70de..6f44d73 100644
--- a/examples/simple.halk
+++ b/examples/simple.halk
@@ -1,3 +1 @@
-:str:var = "Hello";
-
-fprint.stdio, strcat.var, "\n";
+:str:var = "Hello, World!";