kabel/examples/everything.kab

49 lines
1.1 KiB
Plaintext
Raw Normal View History

2024-01-18 04:17:13 +00:00
# File showing examples of Kabel syntax
2024-01-20 00:47:56 +00:00
# This should lex and parse OK, but it will not run.
2024-01-18 04:17:13 +00:00
# Function/procedure definition
2024-01-20 00:47:56 +00:00
# General structure:
# to <identifier> [with <argument list, comma separated>]:
# An argument list may accept 'and' after
2024-01-18 04:17:13 +00:00
2024-01-20 00:47:56 +00:00
to doSomething using r, x, and p:
if r == 6: # Contemplate simply using =
return 7;
else:
2024-01-18 04:17:13 +00:00
2024-01-19 03:51:57 +00:00
# Hoisting and declaration is implicit
_7 = 6;
2024-01-20 00:47:56 +00:00
n = 5;
2024-01-19 03:51:57 +00:00
_kt_hr = "string literal!";
2024-01-20 00:47:56 +00:00
tab = {n: 7, mod: p};
# Here's every type.
my_str = "string lit"; # Str
my_num = 128; # Num
my_list = [1, 2, 3, 4, "I", "Declare", "a Thumb", "War"]; # List
my_table = {
x = 4,
q = 6,
t = "mystr",
n_ar = [5, 6, 7, 8, "Try to", "Keep your", "Thumb", "Straight"],
k_pr = tab, # references abstracted away. just bodge it behind the scenes
# Trailing comma optional
}
2024-01-18 04:17:13 +00:00
2024-01-19 03:51:57 +00:00
# OOP-ish-ly:
# g = 7 + t.x.find(n, k, g+5, p) + 6;
g = (t's x: find using n, k, g + 5, p) + 6;
2024-01-20 00:47:56 +00:00
# OOP-ish-ly: for module in p:
foreach module in p:
# This should be valid.
n=n+(_7+1);
while k's angle > 50:
# 'decrease x by y' and 'increase x by y' are simply aliases for
# 'x = x - y' and 'x = x + y'
decrease k's angle by 5;