Variables & Types
Variables
wyn
var x = 42 // mutable
const y = 100 // immutableBasic Types
wyn
var age: int = 25 // 64-bit integer
var price: float = 19.99 // double precision
var name: string = "Alice" // string
var active: bool = true // booleanType inference works — you can omit the type when the compiler can figure it out:
wyn
var count = 0 // int
var pi = 3.14 // float
var msg = "hello" // stringStrings
String interpolation with ${}:
wyn
var name = "Wyn"
var version = 1
println("${name} v${version}") // "Wyn v1"Arrays
wyn
var numbers = [1, 2, 3, 4, 5]
var names: [string] = ["Alice", "Bob"]
var first = numbers[0] // 1
var len = numbers.len() // 5List Comprehensions
wyn
var squares = [x * x for x in 0..10]
var evens = [x for x in 0..20 if x % 2 == 0]Slices
wyn
var nums = [1, 2, 3, 4, 5]
var first3 = nums[0:3] // [1, 2, 3]
var hello = "hello world"[0:5] // "hello"Constants
wyn
const MAX_SIZE = 1024
const PI = 3.14159
const GREETING = "Hello"Try It
Press Run or Ctrl+Enter