Keyboard shortcuts

Press ← or β†’ to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

πŸ“– Glossary

WordWhat it means
funDeclares a new function (a little machine)
3.14A float literal β€” a number with a decimal point
letCreates a named value (an immutable labelled box)
varCreates 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
matchA sorting machine that picks a path based on a value
_The wildcard β€” matches anything
x if condA match guard β€” adds a condition to a pattern
a | bOr-pattern β€” match this or that in a match arm
0..=59Range pattern β€” match any integer in a range (inclusive)
[x, ..rest]Slice pattern β€” grab the first item, keep the rest
if / elseA fork in the road β€” pick one path
else ifChain multiple conditions without nesting
repeat(n)Do something n times
for i in a..bCounted loop β€” run with i going from a to b (inclusive)
while condLoop while a condition is true
loopInfinite loop β€” runs until break
breakEmergency exit β€” jump out of any loop
continueSkip the rest of this round and go to the next one
Some(x)A maybe that has a value inside
NoneA 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 stringsGlue 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, .1Tuple access β€” get the first or second item from a tuple
let (x, y)Tuple destructuring β€” unpack a tuple into separate variables
structDeclares a new type with named fields β€” like designing a custom box
Name { f: v }Create a struct value β€” fill in the labelled compartments
.fieldStruct field access β€” read a named compartment
typeDeclares 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 **)
-xNegate a number (flip positive/negative)
!xNegate 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 listWalk 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
closureA function that remembers values from where it was created
higher-order functionA function that takes or returns other functions
importBring functions from another file into yours
pubMark a function as public β€” other files can use it
from ... importPick specific functions from another file
pub importImport and re-share β€” pass functions along to your importers
: intA type annotation β€” labels a variable or parameter with its type
block { }A group of steps; the last line is the answer
.hcThe file extension for Hica source code
KokaThe language Hica is built in and translates to
PerceusThe smart memory cleaner β€” no garbage collector needed

Happy coding!