forked from shramee/starklings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfo.toml
More file actions
262 lines (225 loc) · 8.25 KB
/
info.toml
File metadata and controls
262 lines (225 loc) · 8.25 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# INTRO
[[exercises]]
name = "intro1"
path = "exercises/intro/intro1.cairo"
mode = "run"
hint = """
No hints this time ;)
"""
[[exercises]]
name = "intro2"
path = "exercises/intro/intro2.cairo"
mode = "run"
hint = """
No hints this time ;)
"""
# VARIABLES
[[exercises]]
name = "variables1"
path = "exercises/variables/variables1.cairo"
mode = "run"
hint = """
The declaration on line 8 is missing a keyword that is needed in Cairo
to create a new variable binding."""
[[exercises]]
name = "variables2"
path = "exercises/variables/variables2.cairo"
mode = "run"
hint = """
What happens if you annotate line 7 with a type annotation?
What if you give x a value?
What if you do both?
What type should x be, anyway? (remember what the basic type in Cairo is?)
What if x is the same type as 10? What if it's a different type? (e.g. a u8)"""
[[exercises]]
name = "variables3"
path = "exercises/variables/variables3.cairo"
mode = "run"
hint = """
Oops! In this exercise, we have a variable binding that we've created on
line 7, and we're trying to use it on line 8, but we haven't given it a
value. We can't print out something that isn't there; try giving x a value!
This is an error that can cause bugs that's very easy to make in any
programming language -- thankfully the Cairo compiler has caught this for us!"""
[[exercises]]
name = "variables4"
path = "exercises/variables/variables4.cairo"
mode = "run"
hint = """
In Cairo, variable bindings are immutable by default. But here we're trying
to reassign a different value to x! There's a keyword we can use to make
a variable binding mutable instead."""
[[exercises]]
name = "variables5"
path = "exercises/variables/variables5.cairo"
mode = "run"
hint = """
In variables4 we already learned how to make an immutable variable mutable
using a special keyword. Unfortunately this doesn't help us much in this exercise
because we want to assign a different typed value to an existing variable. Sometimes
you may also like to reuse existing variable names because you are just converting
values to different types like in this exercise.
Fortunately Cairo has a powerful solution to this problem: 'Shadowing'!
You can see an example of variables and 'shadowing' here: https://book.cairo-lang.org/ch02-01-variables-and-mutability.html?highlight=shadow#shadowing
You can read about the different integer types here: https://book.cairo-lang.org/ch02-02-data-types.html#integer-types
Try to solve this exercise afterwards using this technique."""
[[exercises]]
name = "variables6"
path = "exercises/variables/variables6.cairo"
mode = "run"
hint = """
We know about variables and mutability, but there is another important type of
variable available: constants.
Constants are always immutable and they are declared with keyword 'const' rather
than keyword 'let'.
Constants types must also always be annotated.
You can read about the constants here: https://book.cairo-lang.org/ch02-01-variables-and-mutability.html?highlight=const#constants
"""
# PRIMITIVE TYPES
[[exercises]]
name = "primitive_types1"
path = "exercises/primitive_types/primitive_types1.cairo"
mode = "run"
hint = "No hints this time ;)"
[[exercises]]
name = "primitive_types2"
path = "exercises/primitive_types/primitive_types2.cairo"
mode = "run"
hint = "No hints this time ;)"
[[exercises]]
name = "primitive_types3"
path = "exercises/primitive_types/primitive_types3.cairo"
mode = "run"
hint = """
You'll need to make a pattern to bind `name` and `age` to the appropriate parts
of the tuple.
If you're familiar with Rust, you should know that Cairo has a similar syntax to
destructure tuples into multiple variables.
https://book.cairo-lang.org/ch02-02-data-types.html?highlight=destructu#the-tuple-type
You can do it!!
"""
# OPERATIONS
[[exercises]]
name = "operations1"
path = "exercises/operations/operations1.cairo"
mode = "test"
hint = """You can check the list of available operators here:
https://book.cairo-lang.org/appendix-02-operators-and-symbols.html
"""
[[exercises]]
name = "operations2"
path = "exercises/operations/operations2.cairo"
mode = "test"
hint = """Use % for modulus, / for division, and * for multiplication."""
# IF
[[exercises]]
name = "if1"
path = "exercises/if/if1.cairo"
mode = "test"
hint = """
Remember in Cairo that:
- the `if` condition does not need to be surrounded by parentheses
- `if`/`else` conditionals are expressions
- Each condition is followed by a `{}` block."""
[[exercises]]
name = "if2"
path = "exercises/if/if2.cairo"
mode = "test"
hint = """
For that first compiler error, it's important in Cairo that each conditional
block returns the same type! To get the tests passing, you will need a couple
conditions checking different input values."""
# FUNCTIONS
[[exercises]]
name = "functions1"
path = "exercises/functions/functions1.cairo"
mode = "run"
hint = """
This main function is calling a function that it expects to exist, but the
function doesn't exist. It expects this function to have the name `call_me`.
It expects this function to not take any arguments and not return a value.
Sounds a lot like `main`, doesn't it?"""
[[exercises]]
name = "functions2"
path = "exercises/functions/functions2.cairo"
mode = "run"
hint = """
Cairo requires that all parts of a function's signature have type annotations,
but `call_me` is missing the type annotation of `num`. What is the basic type in Cairo?"""
[[exercises]]
name = "functions3"
path = "exercises/functions/functions3.cairo"
mode = "run"
hint = """
This time, the function *declaration* is okay, but there's something wrong
with the place where we're calling the function.
As a reminder, you can freely play around with different solutions in Starklings!
Watch mode will only jump to the next exercise if you remove the I AM NOT DONE comment."""
[[exercises]]
name = "functions4"
path = "exercises/functions/functions4.cairo"
mode = "run"
hint = """
The error message points to line 18 and says it expects a type after the
`->`. This is where the function's return type should be -- take a look at
the `is_even` function for an example!
"""
# Arrays
[[exercises]]
name = "arrays1"
path = "exercises/arrays/arrays1.cairo"
mode = "test"
hint = """
You can declare an array in Cairo using the following syntax:
`let your_array = ArrayTrait::new();`
You can append elements to an array using the following syntax:
`your_array.append(element);`
The `pop_front` method removes the first element from the array and returns an Option::Some(value) if the array is not empty, or Option::None() if the array is empty.
"""
[[exercises]]
name = "arrays2"
path = "exercises/arrays/arrays2.cairo"
mode = "test"
hint = """
How can you remove the first element from the array?
Take a look at the previous exercise for a hint. Don't forget to call `.unwrap()` on the returned value.
This will prevent the `Variable not dropped` error.
"""
[[exercises]]
name = "arrays3"
path = "exercises/arrays/arrays3.cairo"
mode = "test"
hint = """
The test fails because you are trying to access an element that is out of bounds!
By using array.pop_front(), we remove the first element from the array, so the index of the last element is no longer 2.
Without changing the index accessed, how can we make the test pass? Is there a method that returns an option that could help us?
"""
# MOVE SEMANTICS
[[exercises]]
name = "move_semantics1"
path = "exercises/move_semantics/move_semantics1.cairo"
mode = "run"
hint = """
So you've got the "ref argument must be a mutable variable." error on line 17,
right? The fix for this is going to be adding one keyword, and the addition is NOT on line 17
where the error is.
Also: Try accessing `arr0` after having called `fill_arr()`. See what happens!
Read more about move semantics and ownership here: https://book.cairo-lang.org/ch04-01-what-is-ownership.html
"""
[[exercises]]
name = "move_semantics2"
path = "exercises/move_semantics/move_semantics2.cairo"
mode = "run"
hint = """
The difference between this one and the previous ones is that the first line
of `fn fill_arr` that had `let mut arr = arr;` is no longer there. You can,
instead of adding that line back, add `mut` in one place that will change
an existing binding to be a mutable binding instead of an immutable one :)"""
# MODULES
[[exercises]]
name = "modules1"
path = "exercises/modules/modules1.cairo"
mode = "test"
hint = """
You can bring a parent's modules items in the current module with super::item_name
"""