Skip to content

Commit

Permalink
refactor:exercises order (foundry-rs#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat authored Mar 3, 2023
1 parent 46f5551 commit 7e64ca0
Showing 1 changed file with 131 additions and 129 deletions.
260 changes: 131 additions & 129 deletions info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,87 +95,6 @@ Constants types must also always be annotated.
You can read about the different integer types here: https://link.medium.com/c8TqX7R3qxb#6d64
"""



# FUNCTIONS

[[exercises]]
name = "functions1"
path = "exercises/functions/functions1.cairo"
mode = "compile"
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 = "compile"
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 = "compile"
hint = """
This time, the function *declaration* is okay, but there's something wrong
with the place where we're calling the function.
Remember how we can use a suffix to specify the type of a literal? https://link.medium.com/c8TqX7R3qxb#6d64
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 = "functions5"
path = "exercises/functions/functions4.cairo"
mode = "compile"
hint = """
This is a really common error that can be fixed by removing one character.
It happens because Cairo distinguishes between expressions and statements: expressions return a value based on their operand(s), and statements simply return a () type which behaves just like `void` in C/C++ language.
We want to return a value of `felt` type from the `square` function, but it is returning a `()` type...
They are not the same. There are two solutions:
1. Add a `return` ahead of `num * num;`
2. remove `;`, make it to be `num * num`"""

# 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?
"""

# PRIMITIVE TYPES

[[exercises]]
Expand Down Expand Up @@ -228,12 +147,6 @@ path = "exercises/operations/operations2.cairo"
mode = "test"
hint = """Use % for modulus, / for division, and * for multiplication."""

[[exercises]]
name = "quizs1"
path = "exercises/quizs/quizs1.cairo"
mode = "test"
hint = """No hints this time ;)"""

# IF

[[exercises]]
Expand All @@ -255,58 +168,57 @@ 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."""

# STRUCTS
# FUNCTIONS

[[exercises]]
name = "structs1"
path = "exercises/structs/structs1.cairo"
mode = "test"
name = "functions1"
path = "exercises/functions/functions1.cairo"
mode = "compile"
hint = """
Cairo has a single type of struct that are named collections of related data stored in fields.
In this exercise you need to complete and implement a struct.
Here is how we describe a person struct that stores a name and an age,
#[derive(Copy, Drop)]
struct Person {
name: felt,
age: felt,
}
You'd use the struct like so,
let john = Person { name: 'John', age: 29 };
Read more about structs in the Structs section of this article: https://link.medium.com/c8TqX7R3qxb#ff54 """
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 = "compile"
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 = "structs2"
path = "exercises/structs/structs2.cairo"
mode = "test"
name = "functions3"
path = "exercises/functions/functions3.cairo"
mode = "compile"
hint = """
Cairo requires you to initialize all fields when creating a struct and there is no update syntax available at the moment.
You can have multiple data types in a struct, and even other structs.
This time, the function *declaration* is okay, but there's something wrong
with the place where we're calling the function.
Remember how we can use a suffix to specify the type of a literal? https://link.medium.com/c8TqX7R3qxb#6d64
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."""

There are some shortcuts that can be taken when destructuring structs,
```
let Foo {x, y} = foo; // Creates variables x and y with values foo.x and foo.y
let Foo {x: a, y: b} = foo; // Creates variables a and b with values foo.x and foo.y
```
Read more about structs in the Structs section of this article: https://link.medium.com/c8TqX7R3qxb#ff54 """

[[exercises]]
name = "structs3"
path = "exercises/structs/structs3.cairo"
mode = "test"
name = "functions4"
path = "exercises/functions/functions4.cairo"
mode = "compile"
hint = """
For is_international: What makes a package international? Seems related to the places it goes through right?
This is a really common error that can be fixed by removing one character.
It happens because Cairo distinguishes between expressions and statements: expressions return a value based on their operand(s), and statements simply return a () type which behaves just like `void` in C/C++ language.
We want to return a value of `felt` type from the `square` function, but it is returning a `()` type...
They are not the same. There are two solutions:
1. Add a `return` ahead of `num * num;`
2. remove `;`, make it to be `num * num`"""

For get_fees: This method takes an additional argument, is there a field in the Package struct that this relates to?
# QUIZ 1

Looking at the test functions will also help you understand more about the syntax.
This section will help you understanding more about impls and traits: https://link.medium.com/c8TqX7R3qxb#83b5.
"""
[[exercises]]
name = "quizs1"
path = "exercises/quizs/quizs1.cairo"
mode = "test"
hint = """No hints this time ;)"""

# ENUMS

Expand All @@ -330,8 +242,8 @@ path = "exercises/enums/enums3.cairo"
mode = "test"
hint = """
As a first step, you can define enums to compile this code without errors.
and then create a match expression in `process()`.
Note that you need to deconstruct some message variants
and then create a match expression in `process()`.
Note that you need to deconstruct some message variants
in the match expression to get value in the variant.
"""

Expand All @@ -351,7 +263,7 @@ name = "options2"
path = "exercises/options/options2.cairo"
mode = "test"
hint = """
check out: https://github.com/starkware-libs/cairo/blob/main/corelib/src/option.cairo
check out: https://github.com/starkware-libs/cairo/blob/main/corelib/src/option.cairo
to see the implementation of the Option type and its methods.
"""

Expand All @@ -364,6 +276,96 @@ Reminder: You can use a match statement with an Option to handle both the Some a
This syntax is more flexible than using unwrap, which only handles the Some case, and contributes to more robust code.
"""

# 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?
"""


# STRUCTS

[[exercises]]
name = "structs1"
path = "exercises/structs/structs1.cairo"
mode = "test"
hint = """
Cairo has a single type of struct that are named collections of related data stored in fields.
In this exercise you need to complete and implement a struct.
Here is how we describe a person struct that stores a name and an age,
#[derive(Copy, Drop)]
struct Person {
name: felt,
age: felt,
}
You'd use the struct like so,
let john = Person { name: 'John', age: 29 };
Read more about structs in the Structs section of this article: https://link.medium.com/c8TqX7R3qxb#ff54 """


[[exercises]]
name = "structs2"
path = "exercises/structs/structs2.cairo"
mode = "test"
hint = """
Cairo requires you to initialize all fields when creating a struct and there is no update syntax available at the moment.
You can have multiple data types in a struct, and even other structs.
There are some shortcuts that can be taken when destructuring structs,
```
let Foo {x, y} = foo; // Creates variables x and y with values foo.x and foo.y
let Foo {x: a, y: b} = foo; // Creates variables a and b with values foo.x and foo.y
```
Read more about structs in the Structs section of this article: https://link.medium.com/c8TqX7R3qxb#ff54 """

[[exercises]]
name = "structs3"
path = "exercises/structs/structs3.cairo"
mode = "test"
hint = """
For is_international: What makes a package international? Seems related to the places it goes through right?
For get_fees: This method takes an additional argument, is there a field in the Package struct that this relates to?
Looking at the test functions will also help you understand more about the syntax.
This section will help you understanding more about impls and traits: https://link.medium.com/c8TqX7R3qxb#83b5.
"""


# MOVE SEMANTICS

[[exercises]]
Expand Down

0 comments on commit 7e64ca0

Please sign in to comment.