-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.maroon
154 lines (123 loc) · 3.41 KB
/
sample.maroon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Test basic variable assignment
x be 5
y be 10
bark "Testing variables:"
bark x, y
# Test arithmetic
result be x plus y
bark "Testing arithmetic:"
bark "x plus y =", result
new_result be result minus 3
bark "After subtraction:", new_result
new_result be new_result times 2
bark "After multiplication:", new_result
final_result be new_result divided_by 4
bark "After division:", final_result
# Test strings
message be "Ahoy, Pirates!"
bark "Testing strings:"
bark message
# Test lists
numbers be list of 1, 2, 3, 4, 5
bark "Testing lists:"
bark numbers
add 6 to numbers
bark "After adding 6:", numbers
# Test built-in functions
max_nums be list of 5, 10, 3
maxval be plunder sails with max_nums
min_nums be list of 5, 10, 3
minval be abandon sails with min_nums
bark "Testing built-ins:"
bark "Maximum value:", maxval
bark "Minimum value:", minval
# Test conditionals
if x be less_than 10, then bark "x is less than 10" else bark "x is greater or equal to 10"
# Test function
voyage double(n):
result be n times 2
bark "Double of", n, "is", result
return result
end voyage
bark "Testing function:"
doubled be double sails with 5
bark "Function returned:", doubled
# Show final state
bark "Final state:"
debug_chest
# UPDATED FEATURES START FROM HERE:
# Set up some initial variables
weather be "stormy"
treasure_chest be list of 1, 2, 3, 4, 5
crew_list be list of "Jack", "Anne", "Mary", "Henry"
counter be 0
# While loop with proper comparison
while counter be less_than 3 bark counter
# Plunder loop examples
plunder each coin from treasure_chest bark coin
plunder each sailor from crew_list bark "Welcome aboard" sailor
# Repeat loop example
repeat 3 times bark "BOOM!"
# Using a variable for repeat count
cannon_count be 2
repeat cannon_count times bark "FIRE!"
# Example usage:
x be 2
choose x:
case 1: bark "one"
case 2: bark "two"
case 3: bark "three"
default: bark "unknown number"
end choose
brace for impact:
bark "Attempting dangerous waters"
if capsized, bark "Error, Capsized in execution!"
# List with nested ops
coins be list of 1, 2, 3 where each times 2 plus 3
# Filter
big_coins be coins where it greater_than 5
# Reduce
total be reduce coins with result plus it
# String ops
greeting be "hello world" upper
words be greeting split " "
sentence be words join ", "
# Define a Caribbean dialect
dialect Caribbean:
"shout" be "bark"
"expedition" be "voyage"
"treasure" be "variable"
"sail_with" be "sails with"
end dialect
# Define the function
expedition greet(txt):
shout txt
end expedition
shout 1
greet sail_with "Hi"
bark roll_dice sails with 20
bark random_float sails with
bark random_float sails with 10, 20
crew be list of 1, 2, 3, 4, 5
bark random_pick sails with crew
bark random_sample sails with crew, 3
bark normal_random sails with
# Math operations
x be 5
bark factorial sails with x
angle be 3.14159
bark sin sails with angle
bark cos sails with angle
bark tan sails with angle
bark exp sails with 2
bark log sails with 10
bark log sails with 8, 2
# Statistical operations
numbers be list of 2, 4, 6, 8, 10
bark mean sails with numbers
bark median sails with numbers
bark sum sails with numbers
# Gaming functions
bark flip_coin sails with
bark roll_multiple sails with 3, 6
bark roll_multiple sails with 2, 20