Master the art of pirate programming 🏴☠️
# While loops with comparisons
while counter be less_than 3 bark counter
# Plunder (forEach) loops
plunder each coin from treasure_chest:
bark coin
end plunder
# Simple repeat loops
repeat 3 times bark "BOOM!"
brace for impact:
bark "Attempting dangerous waters"
if capsized, bark "Error, Capsized!"
# Map with inline operations
coins be list of 1, 2, 3 where each times 2
# Filter lists
big_coins be coins where it greater_than 5
# Reduce operation
total be reduce coins with result plus it
# Custom dialects
dialect Caribbean:
"shout" be "bark"
"expedition" be "voyage"
end dialect
# String operations
greeting be "hello world" upper
words be greeting split " "
sentence be words join ", "
choose x:
case 1: bark "one"
case 2: bark "two"
default: bark "unknown"
end choose
roll_dice sails with 20
random_float sails with 10,20
crew be list of 1,2,3,4,5
random_pick sails with crew
random_sample sails with crew, 3
normal_random,
factorial sails with 5
sin sails with 1
cos sails with 2
tan sails with 3
exp sails with 1
log sails with 2
mean sails with list of 1, 2, 3
median sails with list of 1, 2, 3, 1, 2
sum sails with list of 1, 2, 3, 6
flip_coin sails with
roll_multiple sails with 3, 6
# Your first Maroon program
treasure be "Ahoy, World!"
bark treasure
# Basic arithmetic
gold be 5
silver be 3
total be gold plus silver
bark total # Outputs: 8
voyage calculate_treasure(gold, silver):
total be gold plus silver
bark "Total treasure:" total
end voyage
calculate_treasure sails with 100, 50
treasure be 100
if treasure be greater_than 50, then
bark "Rich pirate!"
else
bark "Keep searching!"
# Comparison operators:
# equals, greater_than, less_than
# greater_or_equal, less_or_equal
# Create a list
loot be list of "gold", "silver", "gems"
# Add to list
add "diamond" to loot
# Access elements
first_item be loot[0]
# List operations
size be count_booty sails with loot
best be plunder sails with loot
worst be abandon sails with loot
# View current variable state
debug_chest
# Type checking
type_val be type_of sails with treasure
bark type_val # Outputs: number