From 06aa81ce0659ac67dea27e015c0fb65894bfecf9 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Sun, 25 Aug 2024 02:45:02 +0000 Subject: [PATCH] Update Examples --- Examples.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/Examples.md b/Examples.md index 956984a..5261681 100644 --- a/Examples.md +++ b/Examples.md @@ -581,4 +581,66 @@ Nothing here. Or here. ### Types -Nothing new syntax-wise in this entire section. \ No newline at end of file +Nothing new syntax-wise in this entire section. + +### Conversion +Or here, so far as I can see. + +### Expressions + + + + + + +
RustHusht
+ +``` +fn main() { + let x = 5u32; + + let y = { + let x_squared = x * x; + let x_cube = x_squared * x; + x_cube + x_squared + x + }; + + let z = { + // The semicolon suppresses this expression and `()` is assigned to `z` + 2 * x; + }; + + println!("x is {:?}", x); + println!("y is {:?}", y); + println!("z is {:?}", z); +} +``` + + +``` +fn main + let x = 5u32 + + let y = + let x_squared = x * x + let x_cube = x_squared * x + x_cube + x_squared + x + + //! We encounter two important Husht points just below. + //! (1) Since there is only a single expression following the `let z=` + //! without the `scope` keyword this would just amount to + //! `let z = 2 * x` + //! (2) The final semicolon is allowed and preserved by Husht to + //! suppress the return value from the scope, but returning + //! the last expression from a scope is the default for Husht + let z = scope + // The semicolon suppresses this expression and `()` is assigned to `z` + 2 * x; + + println! "x is {:?}", x + println! "y is {:?}", y + println! "z is {:?}", z +} +``` +
+