diff --git a/content/mods/Z-starting-programming/0-introduction-to-programming-concepts.md b/content/mods/Z-starting-programming/0-introduction-to-programming-concepts.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/1-types.md b/content/mods/Z-starting-programming/1-types.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/2-divide-and-conquer.md b/content/mods/Z-starting-programming/2-divide-and-conquer.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/3-scopes-and-globals.md b/content/mods/Z-starting-programming/3-scopes-and-globals.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/4-memory.md b/content/mods/Z-starting-programming/4-memory.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/5-inputs-and-outputs.md b/content/mods/Z-starting-programming/5-inputs-and-outputs.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/6-command-line-and-cargo.md b/content/mods/Z-starting-programming/6-command-line-and-cargo.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/7-modules-and-multi-file.md b/content/mods/Z-starting-programming/7-modules-and-multi-file.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/8-intermediate-programming-concepts.md b/content/mods/Z-starting-programming/8-intermediate-programming-concepts.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/exercises/arrays.rs b/content/mods/Z-starting-programming/exercises/arrays.rs new file mode 100644 index 0000000..9946e8a --- /dev/null +++ b/content/mods/Z-starting-programming/exercises/arrays.rs @@ -0,0 +1,21 @@ +fn main() { + let list = [1, 1337, 42]; + + let mut sum = 0; + for number in list { + sum = sum + number; + } + + // TODO: print the following: + // 1. print the numbers one by one + // 2. an addition line + // 3. the sum + // + // For example, for the list [5, 9, 2] your output would be: + // + // 5 + // 9 + // 2 + // -------+ + // 16 +} \ No newline at end of file diff --git a/content/mods/Z-starting-programming/exercises/conditionals.rs b/content/mods/Z-starting-programming/exercises/conditionals.rs new file mode 100644 index 0000000..3a0458f --- /dev/null +++ b/content/mods/Z-starting-programming/exercises/conditionals.rs @@ -0,0 +1,12 @@ +fn main() { + let age = 17; + + if age > 17 { + println!("You are an adult 👩"); + } else { + println!("You are a child 🧒"); + } + + // TODO: Add a clause for 13 - 17 year olds to be `teenagers` + // TIP: you can use the 🏫 emoji +} \ No newline at end of file diff --git a/content/mods/Z-starting-programming/exercises/first-program.rs b/content/mods/Z-starting-programming/exercises/first-program.rs new file mode 100644 index 0000000..d1ad206 --- /dev/null +++ b/content/mods/Z-starting-programming/exercises/first-program.rs @@ -0,0 +1,5 @@ +fn main() { + println!("Hello World"); + + // TODO: add another print, where it prints your name +} \ No newline at end of file diff --git a/content/mods/Z-starting-programming/exercises/functions.rs b/content/mods/Z-starting-programming/exercises/functions.rs new file mode 100644 index 0000000..74a7703 --- /dev/null +++ b/content/mods/Z-starting-programming/exercises/functions.rs @@ -0,0 +1,19 @@ +fn x_squared_plus_one(number: i32) -> i32 { + // TODO: Implement the expression for this +} + +fn double(number: i32) -> i32 { + 2 * number +} + +fn main() { + let double_6 = double(6); + println!("2 * 6: {double_6}"); + + let six_squared_plus_one = x_squared_plus_one(6); + println!("6*6 + 1: {six_squared_plus_one}"); + + // TODO: Create the function named `x_cubed_plus_x_squared` + let six_cubed_plus_six_squared = x_cubed_plus_x_squared(6); + println!("6*6*6 + 6*6: {six_cubed_plus_six_squared}"); +} \ No newline at end of file diff --git a/content/mods/Z-starting-programming/exercises/variables.rs b/content/mods/Z-starting-programming/exercises/variables.rs new file mode 100644 index 0000000..4fef704 --- /dev/null +++ b/content/mods/Z-starting-programming/exercises/variables.rs @@ -0,0 +1,12 @@ +fn main() { + let x = 10; + let double_x = 2 * x; + let x_plus_twenty = x + 22; + + // `{x}` is replaced with the value of `x` + println!("x: {x}"); + + // TODO: create variables and print the following expressions: + // * y = (61 + 130) * 7 + // * z = (x + y) * 5 + 2 +} \ No newline at end of file diff --git a/content/mods/Z-starting-programming/images/A0-abstract-program.svg b/content/mods/Z-starting-programming/images/A0-abstract-program.svg new file mode 100644 index 0000000..537c291 --- /dev/null +++ b/content/mods/Z-starting-programming/images/A0-abstract-program.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/content/mods/Z-starting-programming/images/A0-mutation-sum-warning.png b/content/mods/Z-starting-programming/images/A0-mutation-sum-warning.png new file mode 100644 index 0000000..96869bd Binary files /dev/null and b/content/mods/Z-starting-programming/images/A0-mutation-sum-warning.png differ diff --git a/content/mods/Z-starting-programming/mod.toml b/content/mods/Z-starting-programming/mod.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/associated-functions-and-methods/slides.md b/content/mods/Z-starting-programming/topics/associated-functions-and-methods/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/associated-functions-and-methods/topic.toml b/content/mods/Z-starting-programming/topics/associated-functions-and-methods/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/basics-of-the-command-line/slides.md b/content/mods/Z-starting-programming/topics/basics-of-the-command-line/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/basics-of-the-command-line/topic.toml b/content/mods/Z-starting-programming/topics/basics-of-the-command-line/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/bits-and-bit-operations/slides.md b/content/mods/Z-starting-programming/topics/bits-and-bit-operations/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/bits-and-bit-operations/topic.toml b/content/mods/Z-starting-programming/topics/bits-and-bit-operations/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/booleans/slides.md b/content/mods/Z-starting-programming/topics/booleans/slides.md new file mode 100644 index 0000000..ecb4aad --- /dev/null +++ b/content/mods/Z-starting-programming/topics/booleans/slides.md @@ -0,0 +1,57 @@ +--- +layout: section +--- + +# Types --- Booleans + +--- + +# Types --- Booleans (1) + +* Boolean answer a *yes/no question* (`true` or `false`) +* Examples: + * Is $x$ even? $\to$ $x$ is even + * Is $x$ larger than 42? $\to$ $x$ is larger than 42 + * Does text start with "Wow"? $\to$ text starts with "Wow" + * Is the left mouse button pressed? $\to$ Left mouse button is pressed + +```rust +let is_x_larger_than_42 = x > 42; + +let does_text_start_with_wow = text.starts_with("Wow"); +``` + +--- + +# Types --- Booleans (2) + +* Booleans are also the conditions for `if` + +```rust +let age = 19; +let is_adult = age > 17; + +if is_adult { + println!("You are an adult 👩"); +} else { + println!("You are a child 🧒"); +} +``` + +--- + +# Types --- Booleans (3) + +* Booleans can be combined + * This or that? + * This and that? + +```rust +if number > 10 && number < 20 { + println!("{number} is somewhere between 11 and 19"); +} + +if number < 10 || number > 20 { + println!("{number} is lower than 10 or higher than 20"); +} +``` diff --git a/content/mods/Z-starting-programming/topics/booleans/topic.toml b/content/mods/Z-starting-programming/topics/booleans/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/cargo-basics/slides.md b/content/mods/Z-starting-programming/topics/cargo-basics/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/cargo-basics/topic.toml b/content/mods/Z-starting-programming/topics/cargo-basics/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/comments/slides.md b/content/mods/Z-starting-programming/topics/comments/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/comments/topic.toml b/content/mods/Z-starting-programming/topics/comments/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/composition-structures/slides.md b/content/mods/Z-starting-programming/topics/composition-structures/slides.md new file mode 100644 index 0000000..d95a0cb --- /dev/null +++ b/content/mods/Z-starting-programming/topics/composition-structures/slides.md @@ -0,0 +1,25 @@ +--- +layout: section +--- + +# Types --- Composite Structures + +--- + +# Types --- Composite Structures + +* Create our own type by combining types + +```rust +struct Point { + x: i32, + y: i32, +} + +// Define a new point +let p = Point { x: 10, y: 20 }; + +// Print the properties +println!("Point's x: {}", point.x); +println!("Point's y: {}", point.y); +``` diff --git a/content/mods/Z-starting-programming/topics/composition-structures/topic.toml b/content/mods/Z-starting-programming/topics/composition-structures/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/conditionals/slides.md b/content/mods/Z-starting-programming/topics/conditionals/slides.md new file mode 100644 index 0000000..b98e23a --- /dev/null +++ b/content/mods/Z-starting-programming/topics/conditionals/slides.md @@ -0,0 +1,95 @@ +--- +layout: section +--- + +# Conditionals --- `if` + +--- + +# Conditionals + +* Output changes based on a condition +* *Branches* the execution flow +* Commonly done with `if` and optional `else` + +```rust +if ( + // A condition +) { + // If the condition is true do this. +} else { + // Else do this +} +``` + +--- + +# Conditionals --- Example (1) + +```rust {all|1|3|4} +let age = 19; + +if age > 17 { + println!("You are an adult 👩"); +} else { + println!("You are a child 🧒"); +} +``` + +#### Output: + +``` +You are an adult 👩 +``` + +--- + +# Conditionals --- Example (2) + +#### Code: + +```rust {all|1|3|4} +let age = 12; + +if age > 17 { + println!("You are an adult 👩"); +} else { + println!("You are a child 🧒"); +} +``` + +#### Output: + +``` +You are a child 🧒 +``` + +--- + +# Conditionals --- Example (3) + +```rust {1|3|4} +let role = "Student"; + +// `==` asks whether they are equal +if role == "Administrator" { + println!("All systems operational! 🔓"); +} else { + println!("You don't have the authority!"); +} +``` + +#### Output: + +``` +You are an adult 👩 +``` + +--- + +# Conditionals --- Operations + +- Equality: `==` +- Inequality: `!=` +- Comparison: `<`, `>`, `<=`, `>=` +- Invert: `!` diff --git a/content/mods/Z-starting-programming/topics/conditionals/topic.toml b/content/mods/Z-starting-programming/topics/conditionals/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/constants/slides.md b/content/mods/Z-starting-programming/topics/constants/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/constants/topic.toml b/content/mods/Z-starting-programming/topics/constants/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/copy-by-value-and-reference/slides.md b/content/mods/Z-starting-programming/topics/copy-by-value-and-reference/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/copy-by-value-and-reference/topic.toml b/content/mods/Z-starting-programming/topics/copy-by-value-and-reference/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/enums/slides.md b/content/mods/Z-starting-programming/topics/enums/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/enums/topic.toml b/content/mods/Z-starting-programming/topics/enums/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/functions/slides.md b/content/mods/Z-starting-programming/topics/functions/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/functions/topic.toml b/content/mods/Z-starting-programming/topics/functions/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/heap/slides.md b/content/mods/Z-starting-programming/topics/heap/slides.md new file mode 100644 index 0000000..bb5c17a --- /dev/null +++ b/content/mods/Z-starting-programming/topics/heap/slides.md @@ -0,0 +1,29 @@ +--- +layout: section +--- + +# Heap + +--- + +# Heap + +- *Heap*: Variables that belong to the entire program. You only get the receipt. +- Receipt is gone $\implies$ variable data is gone +- Useful for: + - Unknown time of use + - Unknown size + +```rust +{ + // `numbers` is only a receipt to the data + let mut numbers = vec![]; + + // numbers = [] + + list_of_numbers.push(1); // numbers = [1] + list_of_numbers.push(3); // numbers = [1, 3] + list_of_numbers.push(3); // numbers = [1, 3, 3] + list_of_numbers.push(7); // numbers = [1, 3, 3, 7] +} // `numbers` gets removed from the stack, so data is also gone +``` diff --git a/content/mods/Z-starting-programming/topics/heap/topic.toml b/content/mods/Z-starting-programming/topics/heap/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/hello-world-analysis/slides.md b/content/mods/Z-starting-programming/topics/hello-world-analysis/slides.md new file mode 100644 index 0000000..5bec9a7 --- /dev/null +++ b/content/mods/Z-starting-programming/topics/hello-world-analysis/slides.md @@ -0,0 +1,26 @@ +--- +layout: section +--- + +# Our First Program + +--- + +# Hello World! + +```rust +fn main() { + println!("Hello World!"); +} +``` + +--- + + + +# Our First Program --- Explained + +* Computer needs to know where to start $\to$ `fn main()` +* Everything in the `{` and `}`, and will get run line by line +* A line is terminated with a `;` +* Here we display `Hello World!` to the screen diff --git a/content/mods/Z-starting-programming/topics/hello-world-analysis/topic.toml b/content/mods/Z-starting-programming/topics/hello-world-analysis/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/lists-and-loops/slides.md b/content/mods/Z-starting-programming/topics/lists-and-loops/slides.md new file mode 100644 index 0000000..e17c9c2 --- /dev/null +++ b/content/mods/Z-starting-programming/topics/lists-and-loops/slides.md @@ -0,0 +1,123 @@ +--- +layout: section +--- + +# Lists and Loops + +--- + +# Lists and Loops + +* List = **Array** +* List of multiple elements + * Usernames and Passwords + * Pixels on the Screen + +```rust +let list = [1, 1337, 42]; +``` + +--- + +# Lists and Loops --- Moving over Elements + +```rust +let list = [1, 1337, 42]; + +for number in list { + println!("{number}"); +} +``` + +#### Output: + +``` +1 +1337 +42 +``` + +--- + +# Lists and Loops --- Sum of Elements + +```rust +let list = [1, 1337, 42]; + +let mut sum = 0; +for number in list { + sum = sum + number; +} + +println!("Sum of List: {sum}"); +``` + +#### Output: + +``` +Sum of List: 1390 +``` + +--- + +# Lists and Loops --- Loops without Lists + +```rust +// NOTE: Does not include `1340` +for number in 1337..1340 { + println!("{number}"); +} +``` + +#### Output: + +``` +1337 +1338 +1339 +``` + +--- + +# Lists and Loops --- Unconditional Loops + +```rust +loop { + println!("Please help! I cannot stop!"); +} +``` + +#### Output: + +``` +Please help! I cannot stop! +Please help! I cannot stop! +Please help! I cannot stop! +Please help! I cannot stop! +... +``` + +--- + +# List and Loops --- Breaking Early + +```rust +let mut number = 1337; +loop { + // If the number is greater than 3, break out of the loop + if number > 1339 { + break; + } + + println!("{number}"); + number = number + 1; +} +``` + +#### Output: + +``` +1337 +1338 +1339 +``` diff --git a/content/mods/Z-starting-programming/topics/lists-and-loops/topic.toml b/content/mods/Z-starting-programming/topics/lists-and-loops/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/modules/slides.md b/content/mods/Z-starting-programming/topics/modules/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/modules/topic.toml b/content/mods/Z-starting-programming/topics/modules/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/multi-file-projects/slides.md b/content/mods/Z-starting-programming/topics/multi-file-projects/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/multi-file-projects/topic.toml b/content/mods/Z-starting-programming/topics/multi-file-projects/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/mutation/slides.md b/content/mods/Z-starting-programming/topics/mutation/slides.md new file mode 100644 index 0000000..71d1915 --- /dev/null +++ b/content/mods/Z-starting-programming/topics/mutation/slides.md @@ -0,0 +1,49 @@ +--- +layout: section +--- + +# Mutation + +--- + +# Mutation (1) + +- How to modify a variable's value? + +```rust +// Get the sum over the items +let items = [1, 3, 3, 7]; +let sum = 0; + +for item in items { + let sum = sum + item; +} + +// Output: `0` +println!("{sum}"); +``` + +--- + +# Mutation (2) + +![Compiler Warning](images/A0-mutation-sum-warning.png) + +--- + +# Mutation (3) + +- Solution: *Mutation* + +```rust +// Get the sum over the items +let items = [1, 3, 3, 7]; +let mut sum = 0; + +for item in items { + sum = sum + item; +} + +// Will output `14` +println!("{sum}"); +``` diff --git a/content/mods/Z-starting-programming/topics/mutation/topic.toml b/content/mods/Z-starting-programming/topics/mutation/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/numbers/slides.md b/content/mods/Z-starting-programming/topics/numbers/slides.md new file mode 100644 index 0000000..6bde8db --- /dev/null +++ b/content/mods/Z-starting-programming/topics/numbers/slides.md @@ -0,0 +1,33 @@ +--- +layout: section +--- + +# Types --- Numbers + +--- + +# Types --- Numbers + +| Semantics | Example Values | +|-|-| +| Positive Integers | $0$, $1$, $1337$ | +| Signed Integers | $-1337$, $0$, $42$ | +| Floating Point | $3.1415$, $-4.3$, `INFINITY` | + +## Uses + +* Mathematical equations +* Counting +* Many, many others... + +--- + +# Types --- Signed Integers + +--- + +# Types --- Unsigned Integers + +--- + +# Types --- Floating diff --git a/content/mods/Z-starting-programming/topics/numbers/topic.toml b/content/mods/Z-starting-programming/topics/numbers/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/overview-memory/slides.md b/content/mods/Z-starting-programming/topics/overview-memory/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/overview-memory/topic.toml b/content/mods/Z-starting-programming/topics/overview-memory/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/printing/slides.md b/content/mods/Z-starting-programming/topics/printing/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/printing/topic.toml b/content/mods/Z-starting-programming/topics/printing/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/public-and-private/slides.md b/content/mods/Z-starting-programming/topics/public-and-private/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/public-and-private/topic.toml b/content/mods/Z-starting-programming/topics/public-and-private/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/ranges/slides.md b/content/mods/Z-starting-programming/topics/ranges/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/ranges/topic.toml b/content/mods/Z-starting-programming/topics/ranges/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/reading-input/slides.md b/content/mods/Z-starting-programming/topics/reading-input/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/reading-input/topic.toml b/content/mods/Z-starting-programming/topics/reading-input/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/recursion/slides.md b/content/mods/Z-starting-programming/topics/recursion/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/recursion/topic.toml b/content/mods/Z-starting-programming/topics/recursion/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/references-and-pointers/slides.md b/content/mods/Z-starting-programming/topics/references-and-pointers/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/references-and-pointers/topic.toml b/content/mods/Z-starting-programming/topics/references-and-pointers/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/scopes/slides.md b/content/mods/Z-starting-programming/topics/scopes/slides.md new file mode 100644 index 0000000..039fd9c --- /dev/null +++ b/content/mods/Z-starting-programming/topics/scopes/slides.md @@ -0,0 +1,55 @@ +--- +layout: section +--- + +# Scopes + +--- + +# Scopes (1) + +- A *scope* is an isolated variable and function environment +- Scope is indicated with `{ ... }` + +```rust +let x = 10; + +{ + let y = 20; +} + +// Will give an error: "cannot find value `y` in this scope" +let z = x + y; +``` + +--- + +# Scopes (2) + +- Many earlier concepts will open a new scope + +#### If Statements + +```rust +if x == y { + let z = 10; // `z` defined in this scope +} +// `z` inaccessible in this scope +``` + +#### Loops + +```rust +for character in text.chars() { + // `character` defined in this scope +} +// `character` inaccessible in this scope +``` + +#### Functions +```rust +fn double(number: i32) -> i32 { + // `number` defined in this scope +} +// `number` inaccessible in this scope +``` diff --git a/content/mods/Z-starting-programming/topics/scopes/topic.toml b/content/mods/Z-starting-programming/topics/scopes/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/stack/slides.md b/content/mods/Z-starting-programming/topics/stack/slides.md new file mode 100644 index 0000000..efde04e --- /dev/null +++ b/content/mods/Z-starting-programming/topics/stack/slides.md @@ -0,0 +1,24 @@ +--- +layout: section +--- + +# Stack + +--- + +# Stack + +- *Stack*: Variables that belong to a scope +- Scope ends $\implies$ Variable gone + +```rust +// `a` get pushed on the stack +let a = 3; +{ + // `b` get pushed on the stack + let b = 10; + + // `x` get pushed on the stack + let x = a * b; +} // `b` and `x` get removed from the stack +``` diff --git a/content/mods/Z-starting-programming/topics/stack/topic.toml b/content/mods/Z-starting-programming/topics/stack/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/standard-library/slides.md b/content/mods/Z-starting-programming/topics/standard-library/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/standard-library/topic.toml b/content/mods/Z-starting-programming/topics/standard-library/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/text-and-strings/slides.md b/content/mods/Z-starting-programming/topics/text-and-strings/slides.md new file mode 100644 index 0000000..437ff7d --- /dev/null +++ b/content/mods/Z-starting-programming/topics/text-and-strings/slides.md @@ -0,0 +1,40 @@ +--- +layout: section +--- + +# Types --- Text + +--- +layout: three-slots +--- + +# Types --- Text + +::left:: + +- Character: `c`, `🐵`, Space +- String: `Monkey 🐵`, `A piece of text` + +::right:: + +```rust +let text = "Monkey 🐵"; + +for character in text.chars() { + // `print` a `line` (ln) to the screen + println!("{character}"); +} +``` + +#### Output: + +``` +M +o +n +k +e +y + +🐵 +``` diff --git a/content/mods/Z-starting-programming/topics/text-and-strings/topic.toml b/content/mods/Z-starting-programming/topics/text-and-strings/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/tuples/slides.md b/content/mods/Z-starting-programming/topics/tuples/slides.md new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/tuples/topic.toml b/content/mods/Z-starting-programming/topics/tuples/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/types-intro/slides.md b/content/mods/Z-starting-programming/topics/types-intro/slides.md new file mode 100644 index 0000000..6605ffa --- /dev/null +++ b/content/mods/Z-starting-programming/topics/types-intro/slides.md @@ -0,0 +1,27 @@ +--- +layout: section +--- + +# Types + +--- + +# Types + +* **Types**: *meaning* of a variable +* Catch faulty programs early +* Make it easy for computer to reason about code + +```rust +// Obvious to the computer +let x = 10 + 20; + +// What does this mean? +let x = "This is some text" + 20; +``` + +* Type Categories + * Number (integer, floating point) + * Boolean (yes/no) + * Text (character, string of characters) + * Arbitrary Structure diff --git a/content/mods/Z-starting-programming/topics/types-intro/topic.toml b/content/mods/Z-starting-programming/topics/types-intro/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/variables/slides.md b/content/mods/Z-starting-programming/topics/variables/slides.md new file mode 100644 index 0000000..7adc9cd --- /dev/null +++ b/content/mods/Z-starting-programming/topics/variables/slides.md @@ -0,0 +1,36 @@ +--- +layout: section +--- + +# Variables + +--- + +# Variables + +```rust +let x = 10; + +let text = "ThIs Is SoMe TeXt"; + +let is_this_a_variable = true; +``` + +--- + +# Variables --- Math + +```rust +let x = 10; +let double_x = 2 * x; +let x_plus_twenty = x + 20; +``` + +--- + +# Variables --- Text + +```rust +let x = 10; +let double_x = 2 * x; +let x_plus_twenty = x + 20; diff --git a/content/mods/Z-starting-programming/topics/variables/topic.toml b/content/mods/Z-starting-programming/topics/variables/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/what-is-programming/slides.md b/content/mods/Z-starting-programming/topics/what-is-programming/slides.md new file mode 100644 index 0000000..c76308d --- /dev/null +++ b/content/mods/Z-starting-programming/topics/what-is-programming/slides.md @@ -0,0 +1,128 @@ +--- +layout: section +--- + +# What is Programming + +--- +layout: three-slots +--- + +# **Goal**: let machine turn *Input* into *Output* + +::left:: + +* Examples + * $x \mapsto 2x$ + * "ThIs Is SoMe TeXt" $\mapsto$ "this is some text" + * [1, 1337, 42] $\mapsto$ [uneven, uneven, even] + * Game Assets $\mapsto$ Pixels of the screen + +* Important Questions: + * How to **unambiguously** *express our intentions*? + * How to *revise* our intentions? + +::right:: + +Abstract Program + +--- +layout: three-slots +--- + +# Idea 1: Use Numbers + +::left:: + +* Numbers are simple for computers to understand + +```rust +// x --> 2x +2,x,01 + +// x --> 2x + 6 - 10 +2,x,01,6,02,10,03 + +// x --> 1 + x + x^2 + x^3 +1,x,02,x,x,01,02,x,x,01,x,01,02 +``` + +* **Problem**: Difficult for Humans to reason about + +::right:: + +| Operation Number | Behavior | +|------------------|-------------------------------| +| 01 | Multiply Previous Two Numbers | +| 02 | Add Previous Two Numbers | +| 03 | Subtract Previous Two Numbers | + +--- + +# Idea 2: Use normal language + +* Normal language is understandable people and is known almost everyone + +``` +// x --> 2x +Given an x, multiply 2 with that x. + +// x --> 2x + 6 - 10 +Given an number, multiply two with that number. Add six to that answer and substract ten from the answer. +``` + +* **Problems** + * Ambiguous: "Subtract from that answer". Which answer? + * Difficult to computers to reason about + * Verbose + +--- + +# Idea 3: Programming Language + +* A well-defined language understandable to machines + +```rust +// x --> 1 + x + x^2 + x^3 +let answer = 1 + x + x*x + x*x*x; +``` + +* Properties + * Concise + * Unambiguous + * Understandable to machines + +--- + +# What is Programming (1) + +* Programming Language: *Human-Readable* format to express machine instructions +* This course discusses the *Rust Programming Language* + +```rust +// Multiply `x` by 2 +2 * x + +// Convert some text to lowercase +"ThIs Is SoMe TeXt".to_lowercase() +``` + +--- + +# What is Programming (2) + +* Solve problems by a **divide-and-conquer** approach + +``` +Going to Bed: + 1. Brush Teeth + 1. Find Toothbrush + 2. Find Toothpaste + 3. Put Toothpaste on Toothbrush + 4. ... + 2. Get into Pyjamas + 1. ... + 3. Get into bed +``` + +* $\implies$ Programs consists of smaller *isolated* parts diff --git a/content/mods/Z-starting-programming/topics/what-is-programming/topic.toml b/content/mods/Z-starting-programming/topics/what-is-programming/topic.toml new file mode 100644 index 0000000..e69de29 diff --git a/content/mods/Z-starting-programming/topics/why-divide-and-conquer/slides.md b/content/mods/Z-starting-programming/topics/why-divide-and-conquer/slides.md new file mode 100644 index 0000000..adcbd80 --- /dev/null +++ b/content/mods/Z-starting-programming/topics/why-divide-and-conquer/slides.md @@ -0,0 +1,58 @@ +--- +layout: section +--- + +# Divide-and-Conquer + +--- + +# Divide-and-Conquer --- Functions (1) + +* Functions + * Take in input = *Parameters* + * Give back output = *Return Value* + + +```rust +// The `i32` is an integer type. +// +// `x: i32` gives the Parameters +// `-> i32` gives the Return Value +fn double(x: i32) -> i32 { + 2 * x +} + +// y = 2 * x +let y = double(x); + +// y = 2 * x + 6 +let y = double(x) + 6; +``` + +--- + +# Divide-and-Conquer --- Functions (2) + +```rust +fn brush_teeth() { + let toothbrush = find_toothbrush(); + let toothpaste = find_toothpaste(); + put_on(toothbrush, toothpaste); + + // ... +} + +fn get_into_pyjamas() { + // ... +} + +fn get_into_bed() { + // ... +} + +fn go_to_bed() { + brush_teeth(); + get_into_pyjamas(); + get_into_bed(); +} +``` diff --git a/content/mods/Z-starting-programming/topics/why-divide-and-conquer/topic.toml b/content/mods/Z-starting-programming/topics/why-divide-and-conquer/topic.toml new file mode 100644 index 0000000..e69de29