Update Examples

Glen Whitney 2024-08-26 22:25:00 +00:00
parent 8361e23d0e
commit a24e40cc71

@ -1014,3 +1014,41 @@ It seems the only new point relevant to Husht that arises here is the need to tr
Apparently nothing else new in these sections.
### Functions
#### Methods
Doesn't seem to be anything new here, but ...
#### Closures
... this one appears to be a biggie. Rust's closure syntax is very unusual, and there's lots of commentary concerning it inline. So this first example block shows perhaps the "ideal" way we would recast it. The thing is, I can't understand why it isn't already this way, so maybe we are going to run into parsing problems? If so, we may need to revisit the syntax here.
<table>
<tr>
<th>Rust</th>
<th>Husht</th>
</tr>
<tr>
<td>
```
fn main() {
let outer_var = 42;
let closure_annotated = |i: i32| -> i32 { i + outer_var };
let closure_inferred = |i | i + outer_var ;
println!("closure_annotated: {}", closure_annotated(1));
println!("closure_inferred: {}", closure_inferred(1));
// Once closure's type has been inferred, it cannot be inferred again with another type.
//println!("cannot reuse closure_inferred with another type: {}", closure_inferred(42i64));
// TODO: uncomment the line above and see the compiler error.
let one = || 1;
println!("closure returning one: {}", one());
}
```
</td><td>
```
```
</td></tr></table>