func.orchid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
-- An Orchid program demonstrating the use of the `func!` keyword.
import! orchid.console;
main! {
-- Functions can only be invoked as part of an expression. Invoking a function is as simple as
-- stating the name of the function and then the arguments, separated by spaces.
-- If there are multiple layers of function calls, or if the programmer simply wishes to be
-- explicit, a function call can be delimited with parentheses. It is idiomatic to omit the
-- parentheses in simple cases.
bind! message = silly_join "Hello, " "Orchid";
call! console.write_line message;
}
-- The `func! NAME (ARG: TYPE...) : RET { CODE... }` statement defines a new function. Orchid
-- functions are much more similar to functions from languages like Haskell: they cannot have
-- mutable bindings, they cannot touch external mutable state, they cannot operate directly on
-- unsafe pointers (but can interact with safe wrapper types), and they cannot have side effects
-- (i.e. invoking procedures).
func! silly_join (lhs: String, rhs: String) -> String {
-- Unlike Haskell, functions are still made up of multiple sequential statements; these statements
-- are just restricted to a pure subset of all statements.
return! lhs + rhs;
}