Syntax
This page covers the Kotlin syntax that Skotch currently compiles.
Declarations
Section titled “Declarations”Functions
Section titled “Functions”fun add(a: Int, b: Int): Int { return a + b}
// Expression body shorthandfun multiply(a: Int, b: Int): Int = a * bVariables
Section titled “Variables”val name = "Skotch" // immutable, type inferredvar count: Int = 0 // mutable, explicit typeExtension functions
Section titled “Extension functions”fun Int.isEven(): Boolean = this % 2 == 0
fun main() { println(4.isEven()) // true}Local functions
Section titled “Local functions”fun main() { fun helper(x: Int): Int = x * 2 println(helper(21)) // 42}Literals
Section titled “Literals”Integers
Section titled “Integers”val decimal = 42val hex = 0xFFval binary = 0b1010val withSeparator = 1_000_000val long = 100LStrings
Section titled “Strings”val regular = "hello\nworld"val raw = """ no escape processing preserves newlines"""val template = "value: $x"val exprTemplate = "sum: ${a + b}"Characters
Section titled “Characters”val letter = 'A'val newline = '\n'val tab = '\t'Booleans
Section titled “Booleans”val yes = trueval no = falseOperators
Section titled “Operators”| Category | Operators |
|---|---|
| Arithmetic | + - * / % |
| Comparison | == != < > <= >= |
| Logical | && || ! |
| Unary | - (negation), ! (not) |
| Assignment | = += -= *= /= %= |
| String concat | + (String + String, String + Int) |
Comments
Section titled “Comments”// Line comment
/* Block comment */Semicolons
Section titled “Semicolons”Semicolons are optional. Skotch uses newlines as statement terminators, consistent with standard Kotlin.