aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorc2023-12-05 13:14:50 -0500
committerc2023-12-05 13:14:50 -0500
commit4d41b1186f3dc721102cd1d9e47dde233f7b1e40 (patch)
treee7a715570d3c13ba041cb08f722ed65d009ede5f /examples
parenta75b474bf153388e39c31b072a4bf0d49190cc5b (diff)
Updated examples.
Diffstat (limited to 'examples')
-rw-r--r--examples/hello.halk14
-rw-r--r--examples/preprocessor.halk38
2 files changed, 27 insertions, 25 deletions
diff --git a/examples/hello.halk b/examples/hello.halk
index d046d19..0fb2fd6 100644
--- a/examples/hello.halk
+++ b/examples/hello.halk
@@ -1,18 +1,16 @@
-` comments in backticks `
+` Comments in backticks. `
-#inc# #somefile.halk# ` include a file `
-#inc# #stdio# ` include the 'stdio' header (file path stored in the macro #stdio#) `
+:str:hello = "Hello"; ` Define a variable "hello" with the type "str". `
-:str:hello = "Hello"; ` define a variable 'hello' with the type 'str' `
-
-:str:greet.:str:target = strcat.hello, ", ", target; ` define a function 'greet' that returns a 'str' and accepts an
- argument 'target', also of type 'str' `
+:str:greet.:str:target = strcat.hello, ", ", target; ` Define a function "greet" that returns a "str" and accepts an
+ argument "target", also of type "str". `
` some more functions `
:void:add1.:int:n+=. n, 1;
:int:fac.:int:n=?.(=.n,0),1,*.n,fac.-.n,1;
-:int:fib. :int:n = ?. (<=. n, 1), ` multiple lines can be used for clarity `
+:int:fib. :int:n = ?. (<=. n, 1), ` Multiple lines and whitespace can be used for clarity. `
n,
+. fib.(-. n, 1), fib. -. n, 2);
+io!print.greet."world!"; ` Use previously defined function to print "Hello, world!". `
diff --git a/examples/preprocessor.halk b/examples/preprocessor.halk
index 9e3f6b5..e755ca2 100644
--- a/examples/preprocessor.halk
+++ b/examples/preprocessor.halk
@@ -1,29 +1,33 @@
`
- #def# #ID# [#VALUE#] set a macro
- #fed# #ID# unset a macro
+ Preprocessor directive types:
+
+ #FOO# Call a macro or function.
+ #=BAR# A string that can be stored by a macro.
- #cde# #VALUE# leave code as is
+ #def# #ID# [#=VALUE#] Set a macro.
+ #fed# #ID# Unset a macro.
- #ddo# #ID?# #DIR# if defined, do #DIR# (Defined DO)
- #udo# #ID?# #DIR# if undefined, do #DIR# (UnDefined Do)
+ #dex# #ID?# ... #xed# If macro ID is defined, expand to ... (Defined EXpand).
+ #uex# #ID?# ... #xeu# If macro ID is undefined, expand to ... (Undefined EXpand).
- #inc# #FPATH# include a file
+ #inc# #FILE# Include a file; first searches cwd, then some kind of $HALKPATH.
- #ID# call a macro
+ #ID# Call a macro.
`
-` example usage: `
+` Example usage: `
-#def# #VERSION# #"31.4.1"#
+` Simple header guard. `
+#uex# #TEST#
+#def# #TEST#
-#ddo# #BSD# #inc# #bsd_support.halk#
+#inc# #io#
+#inc# #packet.hlk#
-#udo# #OS# #
- some_error_func."os not specified";
-#
+#def# #VERSION# #= 3.14.1 #
+#def# #ERR# #= {io!print."Error D:"; die;} #
-#def# #OSTYPE# #
- os/shell."sysctl kernel.ostype"
-#
+:packet_t:p = packet!get;
+?.(~=.p!version,#VERSION#),#ERR#; ` Throw error if versions do not match. `
-stdio/pln.#OSTYPE#
+#xeu#