Skip to content
LexerLangv0.1.0

Types and variables

Type inference, annotations, nullables and constants; the type list.

LexerLang
$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 invalidnull requires ?. That a value may be empty should be visible where the value is read.

Types#

Text
int8 int16 int32 int64        uint8 uint16 uint32 uint64
float32 float64               string text
bool check                    object array
null                          void
element event

void is only a function return type:

LexerLang
func close() as void
    out("closed")
end func

Returning 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:

LexerLang
func page($title) as object
    $doc = new html_document
    $doc.title = $title
    return $doc
end func

$res.send(page("Home"))          # still an html_document

Constants#

LexerLang
$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#

LexerLang
$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:

LexerLang
$surname = $user.get("surname")      # null if absent

The distinction is deliberate: a typo quietly producing null costs more than a program that stops.

String operations#

LexerLang
$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()

Next#

Classes and modules.