About Koto

Koto is a simple and expressive programming language, usable as an extension language for Rust applications, or as a standalone scripting language.

print 'Hello, World!'
#: Hello, World!

square = |n| n * n
'8 squared is {square 8}'
#: 8 squared is 64

(2, 4, 6, 8)
  .each square
  .to_list()
#: [4, 16, 36, 64]

Background

Koto was started in 2020 with the goal to create an ideal language for adding scripting to applications developed in Rust. Of particular interest were interactive systems like animation or game engines, where rapid iteration demands a lightweight programming interface that compiles and runs quickly.

The guiding design principle is that Koto should be simple, conceptually as well as visually. To that end, a focus throughout the language's development has been on reducing syntax noise and minimizing core concepts wherever possible.

Current State

Koto is a new language and should be considered to have a prominent 'use at your own risk' disclaimer.

With that said, Koto is becoming more stable with each release, and although we're still some way from a 1.0 version, breaking changes are becoming much less frequent.

Early adopter feedback is invaluable, so if you do try out Koto please get in touch and share your experiences, positive or otherwise! You're welcome to reach out in Discussions, or on Discord, or by opening an issue.

You can read the guide, try it out in the playground or the CLI, and see how well it works in your existing Rust application.

Features

  • Simple and clean syntax: Koto aims to reduce visual noise and cognitive load wherever possible, while still enabling full intuitive control of your program.
  • Easy integration with Rust: Koto is implemented in Rust, and is designed to be easily added to existing applications. Custom value types can be added to the Koto runtime by implementing the KotoObject trait.
  • Fast compilation: The compiler has been written with rapid iteration in mind, with the goal of compiling a script as quickly as possible.
  • Rich iterator support: Koto has a focus on using iterators for data manipulation, with a large collection of iterator generators, adaptors, and consumers available in the core library's iterator module.
  • Built-in testing: Automated testing has first-class support in Koto, making it natural to write tests along with your code.
  • Optional multi-threaded runtime By default, Koto has a single-threaded runtime. For applications that require multi-threaded scripting, a feature flag enables a thread-safe runtime.
  • Tooling: Support for Koto is available for several popular editors. Tree-sitter and LSP implementations are also available. Auto-formatting and linting are future topics, contributions are welcome!

Missing/Incomplete Features

  • Async tasks: Koto doesn't have support for async/await-style asynchronous tasks, although support is planned for the future.
  • Integration with other languages: There's currently no C API for Koto, which would allow it to be integrated with languages other than Rust.

Tooling

Editors

Plugins that provide Koto support are available for the following editors:

Helix has built-in Koto support (since 25.01).

Tree-sitter

A Tree-sitter implementation is available here. If you're using Neovim then it's easy to set up with nvim-treesitter.

LSP

An implementation of the Language Server Protocol for Koto is available here.

Projects using Koto

  • Kotoist
    • A VST plugin for live coding and algorithmic composition
  • Metabuild
    • A scriptable build automation system with dependency manager
  • Ohm
    • A live coding language/DSL for audio synthesis and processing
  • bevy-koto
    • A proof of concept for scripting Bevy entities using Koto
  • fidget-koto
    • Koto scripting support for Fidget
  • koto-midi
    • A module for working with MIDI messages in Koto scripts

Please open a PR if you would like to add your project to this list.

Influences

Koto was influenced by and is indebted to many other languages.

  • Scope: Lua was a strong influence on Koto, showing the strength of a minimalistic feature-set in an embeddable scripting language.
  • Syntax: Coffeescript and Moonscript show how languages can be made easy on the eye by minimizing visual distractions, while also managing to avoid inexpressive terseness.
  • Language Design: Although the syntax and core purpose is very different, Rust had a huge impact on Koto's design. In particular Rust's rich iterator support was a major influence on emphasizing the role of iterators in Koto.

Performance

Koto's runtime is fast enough for many applications, with similar performance to other embedded scripting languages for Rust (see here for a comparison).

By default, Koto uses a single-threaded runtime. The multi-threaded runtime is available via a feature flag, but comes with a runtime performance cost typically in the range of ~5-10%.

When Koto is used as an embedded language within a host application, runtime performance is heavily affected by the way that the application itself is compiled. See The Rust Performance Book for lots of excellent advice on how to improve performance. In particular, the choice of allocator used by the application should be considered.