Types and variables
Type inference, annotations, nullables and constants; the type list.
$a = "osman" # mutable, type inferred
$a as string = 10 # type annotation; becomes "10"
$a as string? = null # nullable: string | null
$a as string *= "osman" # constant; assigning again is an error$a as string = null is invalid — null requires ?. That a value may be empty should be visible where the value is read.
Types#
int8 int16 int32 int64 uint8 uint16 uint32 uint64
float32 float64 string text
bool check object array
null void
element eventvoid is only a function return type:
func close() as void
out("closed")
end funcReturning a value from it is an error.
check has three states: true / false / null. A checkbox that was left unchecked is not the same thing as one that was never submitted.
element and event are only meaningful inside javascript blocks: one is a DOM element, the other a browser event. They have no server-side counterpart.
byte, float8, float16 and float128 do not exist.
Class names are not types#
A function returning a class instance is annotated as object. The object passes through as it is — its class and methods are preserved:
func page($title) as object
$doc = new html_document
$doc.title = $title
return $doc
end func
$res.send(page("Home")) # still an html_documentConstants#
$api_url as string *= "https://api.example.com"Assigning twice to a variable declared with *= is an error. This is not a readability convenience but a guarantee: you know the configuration value did not change midway through the run.
Objects and arrays#
$user = {name: "Osman", age: 30}
$languages = ["tr", "en"]
out($user.name)
out($languages.get(0))
out($languages.length.to_string())$user.surname raises an error if the field is absent. To read an optional field, use get:
$surname = $user.get("surname") # null if absentThe distinction is deliberate: a typo quietly producing null costs more than a program that stops.
String operations#
$s.split(",") $s.join("-") $s.replace("a", "b")
$s.slice(0, 5) $s.trim() $s.lower()
$s.upper() $s.starts_with("a") $s.contains("b")
$s.length $n.to_string()