v0.16.02025-07-23
Added
Language
- Default argument values have been introduced to make it easier to implement optional arguments.
- For example, instead of:
``coffee
f = |a, b|
a + (b or 42)
`
You can write:
`coffee
f = |a, b = 42|
a + b
`
- Wildcard imports have been added to make it easier to work with modules with lots of exported values.
- `coffee
from number import *
asserteq pi 2, tau
`
- When calling a function, arguments can be now be unpacked at the call site.
#418
- `coffee
f = |a, b, c| a + b + c
x = 1, 2, 3
f x...
#: 6
`
- A power operator ^ has been added for exponentiation operations, replacing number.pow.
- `coffee
x = 2 ^ 3
#: 8
x ^= 2
#: 64
`
- Number literals can now include underscores.
#399
- `haskell
x = 1000000
y = 0xffaabb
`
- Interpolated values can now be formatted with alternative representations.
- `coffee
print '{15:b}'
#: 1111
`
- The @debug metakey has been added to allow for additional debug information to be provided when formatting an object as a string.
- Values in lists or tuples definitions can now be omitted, with null being used to fill the gaps.
- `coffee
x = [1, , 3, , 5]
#: [1, null, 3, null, 5]
`
- export can now take any iterable that yields key/value pairs.
- `coffee
export (1..=3).each |i| 'generated_{i}', i
generated_3
#: 3
`
- Ranges can now be indexed by number.
- `coffee
r = 100..200
r[50]
#: 150
`
- Overridden operator improvements
- Objects can now define how arithmetic operations should behave when the object is on the RHS of an expression.
- Overridden operators define how the object on the right-hand side of an operation should behave via the @r+, @r-, @r*, @r/, @r^, and @r% metakeys.
- If the LHS value doesn't implement the operation, then the RHS value is checked for an available implementation.
- != now derives its result by default from @== if it's implemented.
- If @< and @== are implemented, then the other comparison operators are now derived automatically by default.
API
- kotoserialize has been replaced by kotoserde, which provides more complete support for converting between Koto values and types that implement serde::Deserialize and Serialize.
- Types that implement Deserialize can be built from a KValue using fromkotovalue.
- Types that implement Serialize can be converted into a KValue using tokotovalue.
- koto_serde is exported from koto as koto::serde when the serde feature is enabled.
- KotoObject has been extended with _rhs functions to support arithmetic operations where the object can appear on the right-hand side of the expression.
- Koto::callexportedfunction has been added.
- Compiler::compile_ast has been added, useful for tools that want to work with the AST after checking that it compiles correctly.
- DisplayContext::debug_enabled has been added to allow native objects to provide additional debug information when KotoObject::display is called.
- KMap::remove and remove_path have been added.
- See the preludevalueremove.rs example for motivation.
- kotoparser now has an errorast feature, which causes the parser to include the incomplete AST in koto_parser::Error when an error is an encountered.
Core Library
- New functions:
- iterator.advance
- string.stripprefix / string.stripsuffix
- string.trimstart / string.trimend
- string.trim now also accepts a pattern to match against.
- koto.unimplemented has been added to allow overridden left-hand side arithmetic operators to defer to right-hand side implementations.
CLI
- The CLI now has a --format argument that formats Koto scripts.
- If a script path is provided then the file will be formatted in place, otherwise the script will be read from stdin and the formatted version will be written to stdout.
- The REPL now supports tab completion for variables and help searches.
Changed
Language
- Empty tuples are now created with ().
- The previous empty-tuple syntax (,) now evaluates as a single-element tuple that contains null.
- Calls to Koto functions with the incorrect number of arguments will now throw an error.
- Default values should be provided for optional arguments.
- Variadic arguments should be used to capture additional arguments.
- Commas inside container definitions that were previously parsed as call arguments or inline function bodies are now more consistently parsed as entry separators.
- [foo x, bar y] is now parsed as [foo(x), bar(y)], not [foo(x, bar(y))].
- This allows functions to be more easily defined inside containers.
- {square: |x| x ^ 2, cube: |x| x ^ 3} would have previously triggered a parsing error.
- Inline function bodies that return tuples now require parentheses.
- {swap: |a, b| b, a} should now written as {swap: |a, b| (b, a)}
- Parentheses-free calls with multiple arguments that were wrapped in parentheses will need to be adjusted.
- (foo 1, 2, 3) will now be parsed as (foo(1), 2, 3),
and should be rewritten as foo(1, 2, 3).
- The -> pipe operator now inserts the piped value as the first argument to the call to the right of the pipe, instead of as the last argument.
- This makes it easier to build pipelines with functions that treat the first argument as the subject of the operations, like instance functions.
`coffee
'hello!'
-> string.to_uppercase
-> string.repeat 3 # Previously this would have failed due to the arguments being out of order
#: HELLO!HELLO!HELLO!
`
- Maps that implement @type now have their type included by default when rendering the map as a string. #478
- Integer arithmetic operations now wrap when overflowing the boundaries of the 64-bit signed range.
Core Library
- The argument order for the bounded version of iterator.generate has been swapped to make it consistent with the bounded version of iterator.repeat.
- E.g. Instead of iterator.generate(3, f) you should write iterator.generate(f, 3).
- iterator.skip now skips when the iterator is advanced instead of immediately when skip is called.
- koto.args has been moved to os.args.
Extra Libs
- The random library now uses xoshiro256++ as its default random generator.
- This is a faster and simpler algorithm than the previously used ChaCha8.
- Seeded sequences will now be stable in future updates.
API
- Koto::run now takes a chunk argument instead of caching the output of Koto::compile.
- The vm argument has been removed from KotoObject::negate.
CLI
- The CLI is now built with extra optimizations by default, resulting in a faster binary at the expense of longer build times.
- Ctrl+C in the REPL now clears the line rather than exiting.
Removed
Core Library
- koto.exports has been removed.
- export now accepts any iterable value which provides support for exporting generated keys.
- number.pow has been removed in favour of the ^ operator.
Fixed
Language
- Compound assignments in parenthesized comparisons are now evaluated correctly.
- E.g. x = [0]; (x[0] += 1) == 0 would previously evaluate to true.
Core Library
- Iterator adaptors can now be used as standalone functions.
- E.g. for i, n in iterator.enumerate 'abc'` would previously throw an error.