Update Examples

Glen Whitney 2024-08-25 02:45:02 +00:00
parent 9aeee6e04b
commit 06aa81ce06

@ -581,4 +581,66 @@ Nothing here.
Or here. Or here.
### Types ### Types
Nothing new syntax-wise in this entire section. Nothing new syntax-wise in this entire section.
### Conversion
Or here, so far as I can see.
### Expressions
<table>
<tr>
<th>Rust</th>
<th>Husht</th>
</tr>
<tr>
<td>
```
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);
}
```
</td><td>
```
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
}
```
</td></tr></table>