This repository has been archived by the owner on Jun 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Note: Block Result Values
Alex Rønne Petersen edited this page Jun 5, 2013
·
2 revisions
In Flect, every block (enclosed by {
and }
) has a value which corresponds to the last expression in the block. For example, this is valid:
pub fn foo() -> int {
let x = {
42;
};
x;
}
Or even the somewhat obscure version:
pub fn foo() -> int {
{
42;
};
}
Further, all expressions that use blocks (such as if
) have values:
pub fn foo(i : int) -> bool {
if i == 42 {
true
} else {
false
};
}
Some expressions (such as for
) have no sensible result value, so they return the unit value.
Blocks themselves are not values in the sense that they can be passed to other functions. They can, however, be passed to macros in order to create what looks like new syntax. For instance:
unless!(a == b, {
do_stuff();
});
- Home
- Introduction
- Motivation
- Features
- Tutorial
- Library
- FAQ
- General
- Interoperability
- Syntax
- Type System
- Macros and CTE
- Specification
- Introduction
- Lexical
- Common Grammar Elements
- Modules and Bundles
- Type System
- Declarations
- Expressions
- Macros
- Compile-Time Evaluation
- Memory Management
- Application Binary Interface
- Foreign Function Interface
- Unit Testing
- Documentation Comments
- Style
- Indentation
- Braces
- Spacing
- Naming