1 language for everything
Ship CLI tools, web services, desktop apps, mobile apps, and games â from one language, on every platform.
$ curl -fsSL https://wynlang.com/install.sh | sh
> irm https://wynlang.com/install.ps1 | iex
test "math operations" { assert(1 + 1 == 2) assert_eq(3 * 3, 9) } test "string methods" { assert_eq("hello".upper(), "HELLO") assert_eq("hello".len(), 5) } fn greet(name: string = "world") -> string { return "hello ${name}" } test "default parameters" { assert_eq(greet(), "hello world") assert_eq(greet("wyn"), "hello wyn") }
struct User { name: string age: int fn greeting(self) -> string { return "Hi, ${self.name}!" } fn is_adult(self) -> int { return self.age >= 18 } } fn main() { var users = [User{name: "Alice", age: 25}, User{name: "Bob", age: 17}] for u in users { println(u.greeting()) } }
fn main() { // List comprehensions var squares = [x * x for x in 0..10] var evens = [x for x in 0..20 if x % 2 == 0] // Slice syntax var first3 = squares[0:3] // [0, 1, 4] var hello = "hello world"[0:5] // "hello" // Functional chains var data = [1, 2, 3, 4, 5] var result = data .filter(fn(x: int) -> int { return x > 2 }) .map(fn(x: int) -> int { return x * 10 }) println(result.join(", ")) // 30, 40, 50 }
trait Drawable { fn draw(self) -> string } struct Circle { r: int } struct Rect { w: int, h: int } impl Drawable for Circle { fn draw(self) -> string { return "circle" } } impl Drawable for Rect { fn draw(self) -> string { return "rect" } } // Dynamic dispatch â any Drawable fn render(shape: Drawable) { println(shape.draw()) } fn safe_div(a: int, b: int) -> ResultInt { if b == 0 { return Err("divide by zero") } return Ok(a / b) }
fn compute(n: int) -> int { var sum = 0 for i in 0..n { sum = sum + i } return sum } fn main() { // Spawn 3 parallel tasks â 2Ξs each var f1 = spawn compute(100000) var f2 = spawn compute(200000) var f3 = spawn compute(300000) var total = await f1 + await f2 + await f3 // Channels for message passing var ch = Task.channel(10) Task.send(ch, total) println(Task.recv(ch).to_string()) }
// Numbers var answer = 42.to_string() // "42" var absolute = Math.abs(-5) // 5 var power = Math.pow(2, 8) // 256 var rounded = Math.round(3.7) // 4 // Strings var clean = " hello world " .trim().capitalize() // "Hello world" var shout = "hello" .upper().replace("L", "*").reverse() // "O**EH" // Arrow lambdas var nums = [1, 2, 3, 4, 5] var doubled = nums.map(fn(x) => x * 2) // [2,4,6,8,10] var big = nums.filter(fn(x) => x > 3) // [4,5] // Chain everything var result = "HELLO" .lower().capitalize().len() .to_string() // "5"
fn main() { // Fetch + parse + store in 10 lines var body = Http.get("https://api.example.com/users") var doc = Json.parse(body) var name = Json.get(doc, "name") var token = Encoding.base64_encode("user:secret") var hash = Crypto.sha256(body) var db = Db.open("app.db") Db.exec(db, "INSERT INTO users(name) VALUES('${name}')") var csv = Csv.parse(File.read("data.csv")) println("Saved ${name}") }
Honest numbers. All benchmarks reproducible â source in the repo.
| Metric | Wyn | Go | Rust | Python |
|---|---|---|---|---|
| Hello world binary | 222 KB | 1.8 MB | 300 KB | N/A |
| Fibonacci(35) | 52 ms | 48 ms | 35 ms | 3,200 ms |
| 1M concurrent tasks | 153 MB | 2,636 MB | â | N/A |
| Dev compile | 260 ms | 300 ms | 5â30 s | N/A |
| REST API (lines) | 45 | 120 | 85 | 35 |
| Deploy to production | 1 command | 4+ steps | 4+ steps | 5+ steps |
Write it in Wyn, ship it as a native library for any language.
wyn init mylib --lib python
wyn init mylib --lib node
wyn init mylib --lib c
wyn init mylib --lib wyn
Write performance-critical code in Wyn, use it from Python, Node, or C. Wyn generates the bindings for you.