π Glossary
| Word | What it means |
|---|---|
fun | Declares a new function (a little machine) |
3.14 | A float literal β a number with a decimal point |
let | Creates a named value (an immutable labelled box) |
var | Creates a changeable value (a box with a lid) |
=> | The magic arrow β shortcut for simple functions |
test "name" | Declares a test block β checks that your code works |
assert(cond) | Test tool β fails if condition is false |
assert_eq(a, b) | Test tool β fails if a and b are different |
match | A sorting machine that picks a path based on a value |
_ | The wildcard β matches anything |
x if cond | A match guard β adds a condition to a pattern |
a | b | Or-pattern β match this or that in a match arm |
0..=59 | Range pattern β match any integer in a range (inclusive) |
[x, ..rest] | Slice pattern β grab the first item, keep the rest |
if / else | A fork in the road β pick one path |
else if | Chain multiple conditions without nesting |
repeat(n) | Do something n times |
for i in a..b | Counted loop β run with i going from a to b (inclusive) |
while cond | Loop while a condition is true |
loop | Infinite loop β runs until break |
break | Emergency exit β jump out of any loop |
continue | Skip the rest of this round and go to the next one |
Some(x) | A maybe that has a value inside |
None | A maybe with nothing inside |
Ok(x) | A result that succeeded |
Err(x) | A result that failed, with a reason |
.. | Range operator β used in for loops: 1..10 |
+ on strings | Glue two strings together (concatenation) |
"{expr}" | String interpolation β embed a value inside a string |
s[i] | String indexing β get the character at position i |
s[i:j] | String slicing β get a substring from i to j |
|> | The pipe β passes a value into a function: a |> f means f(a) |
(a, b) | A tuple β bundles two (or more) values together |
.0, .1 | Tuple access β get the first or second item from a tuple |
let (x, y) | Tuple destructuring β unpack a tuple into separate variables |
struct | Declares a new type with named fields β like designing a custom box |
Name { f: v } | Create a struct value β fill in the labelled compartments |
.field | Struct field access β read a named compartment |
type | Declares an enum type β a value that can be one of several variants |
Red, Circle(r) | Enum variants β the possible shapes a value can take |
input(prompt) | Ask the user for text input β prints prompt, waits for answer |
random(min, max) | Pick a random number from min to max (both included) |
show_fixed(v, n) | Format a float with exactly n decimal places β show_fixed(3.14159, 2) gives "3.14" |
parse_int(s) | Try to turn a string into an integer β returns Some(n) or None |
parse_float(s) | Try to turn a string into a float β returns Some(n) or None |
is_valid_date(s) | Check if a string is a real date like "2024-05-15" β needs import "std/datetime" |
is_valid_time(s) | Check if a string is a real time like "07:32:00" β needs import "std/datetime" |
datetime_kind(s) | Tell you what kind of datetime a string is β needs import "std/datetime" |
date_parts(s) | Break a date into year, month, day β needs import "std/datetime" |
time_parts(s) | Break a time into hour, minute, second β needs import "std/datetime" |
is_before(d1, d2) | True if the first date/time comes before the second β needs import "std/datetime" |
day_of_week(s) | What day of the week is this date? Returns "monday" etc. β needs import "std/datetime" |
offset_to_minutes(s) | Convert a timezone offset to minutes β "+02:00" gives 120 β needs import "std/datetime" |
is_digit(c) | True if c is a digit (0β9) |
is_alpha(c) | True if c is a letter (aβz or AβZ) |
is_upper(c) | True if c is an uppercase letter |
is_lower(c) | True if c is a lowercase letter |
is_alnum(c) | True if c is a letter or digit |
all_digits(s) | True if every character in s is a digit |
all_upper(s) | True if every character in s is uppercase |
all_lower(s) | True if every character in s is lowercase |
glob_match(p, s) | Match a string against a glob pattern (* and ?) |
glob_match_path(p, s) | Match a path against a glob pattern (supports **) |
-x | Negate a number (flip positive/negative) |
!x | Negate a boolean (flip true/false) |
&& | AND β both sides must be true |
== | Equals β asks βare these the same?β |
println() | Print a value to the screen |
show() | Turn a value into a string β show(42) gives "42" |
str_length() | Count the characters in a string |
trim() | Remove spaces from the edges of a string |
contains() | Check if a string contains another string |
to_upper() | Convert a string to UPPERCASE |
to_lower() | Convert a string to lowercase |
split() | Break a string into a list β split("a,b", ",") gives ["a", "b"] |
join() | Glue a list into a string β join(["a", "b"], "-") gives "a-b" |
center() | Center a string inside padding β center("hi", 10, "-") gives "----hi----" |
replace() | Swap parts of a string |
length() | Count how many items are in a list |
reverse() | Flip a list backwards |
head() | First element of a list β returns Some(x) or None |
tail() | Everything after the first element |
last() | Last element of a list β returns Some(x) or None |
sum() | Add up all numbers in a list |
sort_by() | Sort a list using a comparison function |
unique() | Remove duplicates from a list |
for x in list | Walk through each item in a list |
foreach() | Function form of for-each β foreach(list, fn) |
pow(base, exp) | Exponentiation β pow(2, 10) gives 1024 |
sqrt(x) | Square root β sqrt(25.0) gives 5.0 |
floor(x) | Round a float down β floor(3.7) gives 3 |
ceil(x) | Round a float up β ceil(3.2) gives 4 |
round(x) | Round to nearest integer |
to_float(n) | Turn an integer into a float |
chars(s) | Break a string into a list of characters |
from_chars(cs) | Turn a list of characters back into a string |
| closure | A function that remembers values from where it was created |
| higher-order function | A function that takes or returns other functions |
import | Bring functions from another file into yours |
pub | Mark a function as public β other files can use it |
from ... import | Pick specific functions from another file |
pub import | Import and re-share β pass functions along to your importers |
: int | A type annotation β labels a variable or parameter with its type |
block { } | A group of steps; the last line is the answer |
.hc | The file extension for Hica source code |
| Koka | The language Hica is built in and translates to |
| Perceus | The smart memory cleaner β no garbage collector needed |
Happy coding!