mykongee / koto

A simple, expressive, embeddable programming language, made with Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Koto

Docs Crates.io rustc 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

# 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

The language guide gives an overview of Koto's features.

There are also 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 
» 1 + 1
 2
» print "{}, {}!", "Hello", "World"
Hello, World!
 null

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

About

A simple, expressive, embeddable programming language, made with Rust

License:MIT License


Languages

Language:Rust 100.0%