re-do deepaksirone's fix on the actual source file
[rust-101.git] / workspace / src / part01.rs
index bcc1b03bbd6ae9efea5d963241dc973e73cf2d0f..be2c2d261c85bb18c73a7fda54f1abdae59aed2f 100644 (file)
@@ -1,5 +1,3 @@
-// ***Remember to enable/add this part in `main.rs`!***
-
 // Rust-101, Part 01: Expressions, Inherent methods
 // ================================================
 
@@ -10,7 +8,7 @@
 // ## Expression-based programming
 fn sqr(i: i32) -> i32 { i * i }
 
-// Conditionals are also just expressions. You can compare this to the ternary `? :` operator
+// Conditionals are also just expressions. This is comparable to the ternary `? :` operator
 // from languages like C.
 fn abs(i: i32) -> i32 { if i >= 0 { i } else { -i } }
 
@@ -26,6 +24,12 @@ fn number_or_default(n: NumberOrNothing, default: i32) -> i32 {
     }
 }
 
+// It is even the case that blocks are expressions, evaluating to the last expression they contain.
+fn compute_stuff(x: i32) -> i32 {
+    let y = { let z = x*x; z + 14 };
+    y*y
+}
+
 // Let us now refactor `vec_min`.
 fn vec_min(v: Vec<i32>) -> NumberOrNothing {
     fn min_i32(a: i32, b: i32) -> i32 {
@@ -64,8 +68,7 @@ pub fn main() {
 // You will have to replace `part00` by `part01` in the `main` function in
 // `main.rs` to run this code.
 
-// **Exercise 01.1**: Write a funtion `vec_sum` that computes the sum of all values of a `Vec<i32>`.
+// **Exercise 01.1**: Write a function `vec_sum` that computes the sum of all values of a `Vec<i32>`.
 
 // **Exercise 01.2**: Write a function `vec_print` that takes a vector and prints all its elements.
 
-// [index](main.html) | [previous](part00.html) | [next](part02.html)