#scripting #language #koto

koto_runtime

The runtime used by the Koto programming language

11 releases (breaking)

0.9.1 Nov 1, 2021
0.8.1 Aug 18, 2021
0.7.0 Mar 27, 2021
0.5.0 Dec 17, 2020

#56 in Development tools

Download history 14/week @ 2021-08-05 50/week @ 2021-08-12 10/week @ 2021-08-19 35/week @ 2021-08-26 2/week @ 2021-09-09 13/week @ 2021-09-16 8/week @ 2021-09-23 40/week @ 2021-09-30 28/week @ 2021-10-07 37/week @ 2021-10-14 24/week @ 2021-10-21 24/week @ 2021-10-28 14/week @ 2021-11-04 4/week @ 2021-11-11 9/week @ 2021-11-18

92 downloads per month
Used in 8 crates (7 directly)

MIT license

745KB
19K SLoC

Koto

Docs Crates.io CI Discord

Koto is an embeddable scripting language, written in Rust. It has been designed for ease of use and built for speed, with the goal of it being an ideal choice for adding scripting to Rust applications.

Koto is versatile enough to be useful in a variety of applications, although there has been a focus during development on interactive systems, such as rapid iteration during game development, or experimentation in creative coding.

Current State

The language itself is far enough along that I'm happy to share it with the wider world, although you should be warned that it's at a very early stage of development, and you can expect to find missing features, usability quirks, and bugs. Parts of the language are likely to change in response to it being used in more real-world contexts. We're some distance away from a stable 1.0 release.

That said, if you're curious and feeling adventurous then please give Koto a try, your early feedback will be invaluable.

Getting Started

A Quick Tour

import io.print, test.assert_eq

# Numbers
x = 1 + 2.5 + 100.sqrt()
assert_eq x, 13.5

# Strings
name = "Koto"
print "Hello, $name!"

# Functions
square = |n| n * n
print "8 squared is ${square 8}"

add_squares = |a, b| (square a) + (square b)
assert_eq (add_squares 2, 4), 20

# Iterators, ranges, and lists
fizz_buzz = (1..100)
  .keep |n| (10..=15).contains n
  .each |n|
    match n % 3, n % 5
      0, 0 then "Fizz Buzz"
      0, _ then "Fizz"
      _, 0 then "Buzz"
      else n
  .to_list()
assert_eq
  fizz_buzz,
  ["Buzz", 11, "Fizz", 13, 14, "Fizz Buzz"]

# Maps and tuples
x = {peaches: 42, pears: 99}
assert_eq
  x.keys().to_tuple(),
  ("peaches", "pears")

y = # Maps can also be defined using indented `key: value` pairs
  apples: 123
  plums: 99

fruits = x + y # Maps can be combined using the `+` operator

fruit, amount = fruits.max |(_, amount)| amount
print "The highest amount of fruit is: $amount $fruit"

Learning the Language

While there's not yet a complete guide to Koto, there are some code examples that are a good starting point for getting to know the language.

Reference documentation for Koto's core library can be found here.

You're also welcome to ask for help in Discussions, or on the discord server.

Installation

The most recent release of the Koto CLI can be installed with Cargo:

cargo install koto_cli

REPL

A REPL is provided to allow for quick experimentation. Launching the koto CLI without providing a script enters the REPL.

» koto
Welcome to Koto v0.1.0
» 1 + 1
2
» io.print "{}, {}!", "Hello", "World"
Hello, World!
()

A help system is included in the REPL. Run help for instructions.

Language Goals

  • A clean, minimal syntax designed for coding in creative contexts.
  • Fast compilation.
    • The lexer, parser, and compiler are all written with speed in mind, enabling as-fast-as-possible iteration when working on an idea.
  • Fast and predictable runtime performance.
    • Memory allocations are reference counted.
    • Currently there's no tracing garbage collector (and no plan to add one) so memory leaks are possible if cyclic references are created.
  • Lightweight integration into host applications.
    • One of the primary use cases for Koto is for it to be embedded as a library in other applications, so it should be a good citizen and not introduce too much overhead.

Editor Support

Dependencies

~1.5MB
~29K SLoC