New
v0.16.0
Added
Language
- Default argument values have been introduced to make it easier to implement optional arguments.
- For example, instead of:
You can write:f = |a, b| a + (b or 42)f = |a, b = 42| a + b
- For example, instead of:
- Wildcard imports have been added to make it easier to work with modules with lots of exported values.
-
from number import * assert_eq pi * 2, tau
-
- When calling a function, arguments can be now be unpacked at the call site.
#418
-
f = |a, b, c| a + b + c x = 1, 2, 3 f x... #: 6
-
- A power operator
^has been added for exponentiation operations, replacingnumber.pow.-
x = 2 ^ 3 #: 8 x ^= 2 #: 64
-
- Number literals can now include underscores.
#399
-
x = 1_000_000 y = 0xff_aa_bb
-
- Interpolated values can now be formatted with alternative representations.
-
print '{15:b}' #: 1111 - The
@debugmetakey 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
nullbeing used to fill the gaps.-
x = [1, , 3, , 5] #: [1, null, 3, null, 5]
-
exportcan now take any iterable that yields key/value pairs.-
export (1..=3).each |i| 'generated_{i}', i generated_3 #: 3
-
- Ranges can now be indexed by number.
-
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.
- Overridden operators define how the object on the right-hand side of an operation should behave via the
!=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.
- Objects can now define how arithmetic operations should behave when the object is on the RHS of an expression.
API
koto_serializehas been replaced bykoto_serde, which provides more complete support for converting between Koto values and types that implementserde::DeserializeandSerialize.- Types that implement
Deserializecan be built from aKValueusingfrom_koto_value. - Types that implement
Serializecan be converted into aKValueusingto_koto_value. koto_serdeis exported fromkotoaskoto::serdewhen theserdefeature is enabled.
- Types that implement
KotoObjecthas been extended with_rhsfunctions to support arithmetic operations where the object can appear on the right-hand side of the expression.Koto::call_exported_functionhas been added.Compiler::compile_asthas been added, useful for tools that want to work with the AST after checking that it compiles correctly.DisplayContext::debug_enabledhas been added to allow native objects to provide additional debug information whenKotoObject::displayis called.KMap::removeandremove_pathhave been added.- See the
prelude_value_remove.rsexample for motivation.
- See the
koto_parsernow has anerror_astfeature, which causes the parser to include the incomplete AST inkoto_parser::Errorwhen an error is an encountered.
Core Library
- New functions:
iterator.advancestring.strip_prefix/string.strip_suffixstring.trim_start/string.trim_endstring.trimnow also accepts a pattern to match against.
koto.unimplementedhas been added to allow overridden left-hand side arithmetic operators to defer to right-hand side implementations.
CLI
- The CLI now has a
--formatargument 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
stdinand the formatted version will be written tostdout.
- If a script path is provided then the file will be formatted in place, otherwise the script will be read from
- 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 containsnull.
- The previous empty-tuple syntax
- 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 asfoo(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.
'hello!' -> string.to_uppercase -> string.repeat 3 # Previously this would have failed due to the arguments being out of order #: HELLO!HELLO!HELLO!
- This makes it easier to build pipelines with functions that treat the first argument as the subject of the operations, like instance functions.
- Maps that implement
@typenow 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.generatehas been swapped to make it consistent with the bounded version ofiterator.repeat.- E.g. Instead of
iterator.generate(3, f)you should writeiterator.generate(f, 3).
- E.g. Instead of
iterator.skipnow skips when the iterator is advanced instead of immediately whenskipis called.koto.argshas been moved toos.args.
Extra Libs
- The
randomlibrary 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::runnow takes achunkargument instead of caching the output ofKoto::compile.- The
vmargument has been removed fromKotoObject::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.exportshas been removed.exportnow accepts any iterable value which provides support for exporting generated keys.
number.powhas 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) == 0would previously evaluate totrue.
- E.g.
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.
- E.g.