Write less.
Mean more.

OSL is a readable, typed language that compiles to native code. Write it top to bottom like a script, check it like a compiled language, and ship it as one executable.

curl -fsSL https://gosl.mistium.com | sh

OSL 9.3.0 · MIT licence · Source · Other ways to install

main.osl
string[] crew = ["Ada", "Grace", "Linus"]

for i, name in crew (
  log `${i}. Hello, ${name}!`
)

def shout(string text) string -> text.toUpper() ++ "!"
log shout("one binary, no runtime")
Click the code to edit it

This is the real compiler, running in your browser. Click the code to change it.

Why OSL

readable

Read it aloud

A file runs from top to bottom. Types come first, blocks are parentheses, and counting starts at one. You can read an OSL program aloud.

fast

Native, with nothing to install

OSL compiles to Go, and Go builds a native executable. No virtual machine and no runtime to install: one file you copy to a server and run.

dependable

Checked before it runs

Declare types where they matter and let the rest be inferred. Failure is a value in the signature, and the compiler follows your guards.

complete

The whole toolkit in the box

Web servers, databases, desktop apps, games, threads and crypto ship with the compiler. Anything else is one Go import away.

What OSL believes

Six ideas shape the language. Each example is live: run it, change it, break it.

01

A program is just the code

No main, no package line, no build file. A file that says log "Hello, world" is a complete program, and so is a web server. When a project grows, imports and Opal take over; the first line never needs them.

main.osl
log "Hello, world"
Click the code to edit it
02

Types where they earn their keep

Write the type at the edges, where functions meet, and let auto fill in the middle. The compiler checks every boundary and generates direct Go for what it knows, so the types you write make the program faster as well as safer.

main.osl
def average(number[] values) number (
  auto total = values.sum()
  return total / values.len
)

log average([3, 4, 8])
Click the code to edit it
03

Failure is a value you can see

A call that can fail returns a result. Match on it, pass it up with !, or unwrap it on purpose. The compiler warns about failures nobody handles, and it reads your if guards so a call you've made safe stops warning.

main.osl
import "std:json"

struct User (
  string name
  int age = 0
)

switch json.parse<User>(`{"name": "Ada", "age": 36}`) (
  case ok(user)
    log `${user.name} is ${user.age}`
  case err(e)
    log "bad input: " ++ e.message
)
Click the code to edit it
04

The compiler explains itself

An error says what went wrong, where, and how to fix it, often with the exact code to write. osl fix applies the fixes it is sure of, and the language server shows them as you type. Press Compile to see one.

main.osl
int count = "three"
Click the code to edit it
05

Counting starts at one

The first item of an array is [1], the last is [-1], and a loop over five things counts to five. OSL is written for the way people count, and position 0 is a compile error rather than an off-by-one.

main.osl
string[] planets = ["Mercury", "Venus", "Earth"]
log planets[1]
log planets[-1]
Click the code to edit it
06

Go is one import away

Every Go package is an import "go:…" away, with no bindings to write. OSL values convert to Go types at the call, so the Go ecosystem is part of the standard library.

main.osl
import "go:strings"

log strings.Repeat("na", 8) ++ " batman"
Click the code to edit it

Build it in OSL

One language from the server to the window. Every project here has a step-by-step tutorial.

Web servers

Routes, JSON, middleware, WebSockets and TLS from std:serve and std:ws. One binary serves the API and the site.

Build a web API
main.osl
import "std:serve"

*serve.Router app = serve.new()

app.get("/hello/:name", def(*serve.Context c) -> (
  c.json(200, {greeting: "Hello, " ++ c.param("name")})
))

app.run(":8080").unwrap()
Click the code to edit it

One command for the whole loop

The compiler is also the formatter, the test runner, the fixer and the language server. Opal, the package manager, ships with it.

The command line

Everything in the box

71 packages ship with the compiler. Each one has a tutorial and a complete reference generated from its source.

Get started