# Learn OSL

> A course in short lessons. Read a little, run the examples, answer a question, solve an exercise, move on.

This is the Markdown version of https://osl-lang.org/learn. Every page of the OSL docs has one: add .md to its path. https://osl-lang.org/llms.txt lists them all.

Every lesson is small and builds on the one before. The examples are live: click into any of them to change the code, and the compiler, running in your browser, checks it as you type.

### Start here

- [Install OSL](/install.md): Install the compiler, check it works, and set up your editor. About two minutes.
- [Your first program](/learn/first-program.md): Write a program, run it, and turn it into an executable. Meet log, comments and the compiler.

### The basics

- [Variables](/learn/variables.md): Name values with variables, give them types, change them, and keep the ones that shouldn't change fixed.
- [Types](/learn/types.md): Numbers, text and truth; values that might be missing; converting between types; and naming your own.
- [Strings](/learn/strings.md): Join, slice, search and reshape text, and build strings from values with templates.
- [Arrays](/learn/arrays.md): Keep lists of values, read and change them by position, and transform them with map, filter and friends.
- [Objects and maps](/learn/objects.md): Group named values into objects, look things up by key with typed maps, and loop over both.
- [Control flow](/learn/control-flow.md): Make decisions with if, repeat work with for, loop, while and until, and leave loops early.
- [Match and switch](/learn/match.md): Choose between many cases with match, which gives a value, and switch, which runs code.

### Reusing code

- [Functions](/learn/functions.md): Name a piece of code, give it parameters and a return type, and call it from anywhere.
- [Lambdas](/learn/lambdas.md): Write small functions on the spot, pass them around, and let them remember the variables around them.

### Your own types

- [Structs](/learn/structs.md): Define your own value types with named, typed fields, give them methods, and load them from JSON.
- [Enums](/learn/enums.md): Say that a value is one of a fixed set of cases, carry data with each case, and let match check you've handled them all.
- [Classes](/learn/classes.md): Model things with identity and changing state, with constructors, private fields, methods and inheritance.
- [Interfaces](/learn/interfaces.md): Describe what a value can do, not what it is, and write functions that accept anything that fits.
- [Generics](/learn/generics.md): Write one function or type that works for many types, and constrain what those types must support.

### Beyond the basics

- [Errors](/learn/errors.md): Handle things that can go wrong with result values, catch, and !, and know when to throw or exit.
- [Iterators](/learn/iterators.md): Produce values one at a time with generators, and build lazy chains that only do the work you use.
- [Operators](/learn/operators.md): Every operator in one place, including the two OSL rules that surprise people: left-to-right maths and loose string equality.
- [Modules and imports](/learn/modules.md): Split a program across files and folders, choose what each file exposes, and use packages from the standard library, Git and Go.
- [Concurrency](/learn/concurrency.md): Do several things at once with async functions, share data safely, pass messages through channels, and run work in parallel.
- [Testing](/learn/testing.md): Keep checks next to your code with test blocks, run them with osl test, and write test files for bigger cases.
- [Using Go](/learn/go.md): Use any Go package from OSL with a go: import, pass values both ways, and read the Go that OSL generates.
- [What's next](/learn/next.md): You've finished the course. Here's where to go from here.
