-
Notifications
You must be signed in to change notification settings - Fork 0
Types
behave
has multiple inbuilt types, and also lets you define your own, custom types.
Strings are denoted by the type str
.
You can create string literals by surrounding your text with double quotes ("
). For example, "Hello, World!"
creates a string that contains the text Hello, World!
.
Numbers are denoted by the type num
.
They can hold any number that can be an integer or floating-point number.
Booleans are denoted by the type bool
.
They can hold a value that is either true
or false
.
Arrays can hold a list of one specific type: this can be a composite type like a map, another array, a sum type, or even user-defined types like struct
s and enum
s.
They are denoted by the type [<type>]
, where <type>
is any type.
You can create array literals:
[<expr>, <expr>, ...]
/// Which would be something like:
["Hello" + "World", "Hi"]
expr
: Is an expression that results in the type of the array. All of the types must be exactly the same.
Maps can hold a set of key-value pairs, each of which can be any type.
They are denoted by the type [<type> : <type>]
.
You can create map literals:
[<expr> : <expr>, <expr> : <expr>, ...]
/// Which would be something like:
["From string" : 1 + 2.0]
You can create sum types (which are essentially types that can be either one type or another).
Sum types are denoted by <type> | <type> | <type>
.
They can be instantiated with any of the allowed types.
behave
has first-class functions (I don't know why).
They are denoted by fn(<type>, <type>) -> <type>
, where the return type and arguments are optional.
You can create functions:
fn (<ident>: <type>, ...) -> <type> {
<code>
}
/// Which would be something like:
fn (cool_number: num) -> num {
cool_number * 2
}
You can create your own struct
s in secondary files.
They are defined:
struct <ident> {
<ident>: <type>,
<ident>: <type> = <expr>,
...
}
/// Which would be something like:
struct MyStruct {
a_number: num,
a_string: str,
a_default: str = "Hello"
}
You can instantiate them:
<path> {
<ident>: <expr>,
...
}
/// Which would be something like:
MyStruct {
a_number: 69,
a_string: "This is a struct"
}
You can create custom enumerations to signify that a value can only be one out of a certain set. They are also defined in secondary files.
They are defined:
enum <ident> {
<ident>,
<ident> = <number>,
...
}
/// Which would be something like:
enum MyEnum {
This,
That = 2,
There = 5
}
They can be instantiated:
<path>.<ident>
/// Which would be something like:
MyEnum.There