2023-10-30 04:47:00 +00:00
|
|
|
// This is a Conlang file.
|
2023-09-23 04:57:30 +00:00
|
|
|
|
2023-09-28 06:31:46 +00:00
|
|
|
// This is a function. It can be called with the call operator.
|
|
|
|
// The function called `main` is the program's entrypoint
|
2023-10-30 05:07:27 +00:00
|
|
|
fn main() -> (&str, bool, i128) {
|
2023-09-28 06:31:46 +00:00
|
|
|
// An if expression is like the ternary conditional operator in C
|
2023-10-30 04:47:00 +00:00
|
|
|
let y = if 10 < 50 {
|
2023-10-24 02:02:45 +00:00
|
|
|
"\u{1f988}"
|
2023-09-28 06:31:46 +00:00
|
|
|
} else {
|
2023-10-24 02:02:45 +00:00
|
|
|
"x"
|
2023-09-28 06:31:46 +00:00
|
|
|
};
|
|
|
|
|
2023-10-17 03:55:07 +00:00
|
|
|
// A `while` expression is like the while-else construct in Python,
|
|
|
|
// but it returns a value via the `break` keyword
|
|
|
|
let z = while false {
|
2023-09-28 06:31:46 +00:00
|
|
|
// do a thing repeatedly
|
|
|
|
break true
|
2023-10-17 03:55:07 +00:00
|
|
|
// If `while` does not `break`, fall through to the `else` expression
|
2023-09-28 06:31:46 +00:00
|
|
|
} else {
|
|
|
|
false
|
2023-10-30 04:47:00 +00:00
|
|
|
};
|
2023-10-17 03:55:07 +00:00
|
|
|
// The same is true of `for` expressions!
|
|
|
|
let w = for idx in 0..100 {
|
2023-10-30 04:47:00 +00:00
|
|
|
if idx > 2 * 2 {
|
|
|
|
break idx
|
|
|
|
}
|
2023-10-17 03:55:07 +00:00
|
|
|
} else {
|
|
|
|
12345
|
2023-10-30 04:47:00 +00:00
|
|
|
};
|
|
|
|
// A block evaluates to its last expression,
|
|
|
|
// or Empty if there is none
|
|
|
|
(y, z, w) // (🦈, false, 5)
|
2023-09-28 06:31:46 +00:00
|
|
|
}
|