Update Examples
parent
c003fc3719
commit
6ee89e28df
29
Examples.md
29
Examples.md
@ -34,23 +34,29 @@ fn main
|
|||||||
(Skipping for now because we likely want "f-strings" in Husht, which require some thought/design.)
|
(Skipping for now because we likely want "f-strings" in Husht, which require some thought/design.)
|
||||||
|
|
||||||
### Primitives
|
### Primitives
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Rust</th>
|
||||||
|
<th>Husht</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
|
||||||
```
|
```
|
||||||
fn main() {
|
fn main() {
|
||||||
// Variables can be type annotated.
|
|
||||||
let logical: bool = true;
|
let logical: bool = true;
|
||||||
|
|
||||||
let a_float: f64 = 1.0; // Regular annotation
|
let a_float: f64 = 1.0; // Regular annotation
|
||||||
let an_integer = 5i32; // Suffix annotation
|
let an_integer = 5i32; // Suffix annotation
|
||||||
|
|
||||||
// Or a default will be used.
|
|
||||||
let default_float = 3.0; // `f64`
|
let default_float = 3.0; // `f64`
|
||||||
let default_integer = 7; // `i32`
|
let default_integer = 7; // `i32`
|
||||||
|
|
||||||
// A type can also be inferred from context.
|
// Can infer from another line; here i64:
|
||||||
let mut inferred_type = 12; // Type i64 is inferred from another line.
|
let mut inferred_type = 12;
|
||||||
inferred_type = 4294967296i64;
|
inferred_type = 4294967296i64;
|
||||||
|
|
||||||
// A mutable variable's value can be changed.
|
|
||||||
let mut mutable = 12; // Mutable `i32`
|
let mut mutable = 12; // Mutable `i32`
|
||||||
mutable = 21;
|
mutable = 21;
|
||||||
|
|
||||||
@ -61,24 +67,23 @@ fn main() {
|
|||||||
let mutable = true;
|
let mutable = true;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
<->
|
|
||||||
|
</td><td>
|
||||||
|
|
||||||
```
|
```
|
||||||
fn main
|
fn main
|
||||||
// Variables can be type annotated.
|
|
||||||
let logical: bool = true
|
let logical: bool = true
|
||||||
|
|
||||||
let a_float: f64 = 1.0 // Regular annotation
|
let a_float: f64 = 1.0 // Regular annotation
|
||||||
let an_integer = 5i32 // Suffix annotation
|
let an_integer = 5i32 // Suffix annotation
|
||||||
|
|
||||||
// Or a default will be used.
|
|
||||||
let default_float = 3.0 // `f64`
|
let default_float = 3.0 // `f64`
|
||||||
let default_integer = 7 // `i32`
|
let default_integer = 7 // `i32`
|
||||||
|
|
||||||
// A type can also be inferred from context.
|
// Can infer from another line; here i64:
|
||||||
let mut inferred_type = 12 // Type i64 is inferred from another line.
|
let mut inferred_type = 12
|
||||||
inferred_type = 4294967296i64
|
inferred_type = 4294967296i64
|
||||||
|
|
||||||
// A mutable variable's value can be changed.
|
|
||||||
let mut mutable = 12 // Mutable `i32`
|
let mut mutable = 12 // Mutable `i32`
|
||||||
mutable = 21
|
mutable = 21
|
||||||
|
|
||||||
@ -88,3 +93,5 @@ fn main
|
|||||||
// Variables can be overwritten with shadowing.
|
// Variables can be overwritten with shadowing.
|
||||||
let mutable = true
|
let mutable = true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
</td></tr></table>
|
Loading…
Reference in New Issue
Block a user