Skip to content

Releases: koto-lang/koto

v0.16.0

23 Jul 09:29

Choose a tag to compare

Added

Language

  • Default argument values have been introduced to make it easier to implement optional arguments.
    • For example, instead of:
      f = |a, b|
        a + (b or 42)
      You can write:
      f = |a, b = 42|
        a + b
  • 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, replacing number.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 @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.
    • x = [1, , 3, , 5]
      #: [1, null, 3, null, 5]
  • export can 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.
    • != 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

  • koto_serialize has been replaced by koto_serde, 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 from_koto_value.
    • Types that implement Serialize can be converted into a KValue using to_koto_value.
    • 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::call_exported_function 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 prelude_value_remove.rs example for motivation.
  • koto_parser now has an error_ast 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.strip_prefix / string.strip_suffix
    • string.trim_start / string.trim_end
      • 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.
      '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.

v0.15.3

07 Apr 11:31
@irh irh

Choose a tag to compare

  • Compound assignments in parenthesized comparisons are now evaluated correctly.
    • E.g. x = [0]; (x[0] += 1) == 0 would previously evaluate to true.
  • The error message for iterator.repeat has been fixed.

v0.15.2

22 Jan 11:07
@irh irh

Choose a tag to compare

What's Changed

  • Fixed a crash when calling a native function directly from another native function (#413)
  • Enabled optimizations for release builds (#406 and #414
  • Extra PartialEq and PartialOrd impls for KString (#411)

v0.15.1

08 Jan 14:09
@irh irh
117ab52

Choose a tag to compare

What's Changed

  • Allow iterator adaptors to be used as standalone functions by @irh in #404

Full Changelog: v0.15.0...v0.15.1

v0.15.0

07 Jan 17:17
@irh irh

Choose a tag to compare

What's Changed

  • The pipes created during parsing instead of lexing by @Tarbetu in #311
  • Remove the @Not metakey by @irh in #313
  • Reserve some keywords that might be needed in the future by @irh in #314
  • Don't rely on \r\n line endings in tests when running on Windows by @irh in #316
  • Various tweaks by @irh in #317
  • API Improvements by @irh in #318
  • docs: Fix readme for poetry example by @madskjeldgaard in #319
  • AST Newtypes by @irh in #321
  • AST improvements by @irh in #323
  • Add PartialEq + Eq to StringSlice derives by @irh in #324
  • Implement Display for MetaKeyId by @irh in #325
  • Prevent exhausted generators causing a panic by @edenbynever in #326
  • Various tweaks by @irh in #327
  • Implementing Typed Variable Declarations by @Tarbetu in #322
  • Implement type checks for let expressions by @irh in #329
  • Implementing Type Hints of Let expressions for Wildcards by @Tarbetu in #330
  • Various tweaks by @irh in #331
  • Add support for adding type hints to functions by @irh in #332
  • More type checks by @irh in #333
  • Ensure that type checks respect an object's @base entry by @irh in #334
  • Add multi-assignment-support to export by @irh in #335
  • Various tweaks by @irh in #336
  • Tweaks and Fixes by @irh in #337
  • Fix span placement for IDs with type hints by @irh in #338
  • Type hints for generators by @irh in #340
  • Ensure that libs can be used with the rc build variant by @irh in #342
  • Fix minor typo in docs by @JamesHallowell in #341
  • Better Argument Error Message For String Module by @Tarbetu in #345
  • Indexable maps by @irh in #346
  • Simplify Rc build variant selection by @irh in #348
  • Improve errors for calls with unexpected arguments by @irh in #350
  • Don't crash when random.pick is called with empty input by @irh in #351
  • Add a Callable type hint by @irh in #352
  • Add docs for overloads of iterator.product/sum that take an initial value by @irh in #353
  • Type-checked catch blocks by @irh in #354
  • Add support for generic types in the derive macros by @irh in #355
  • iterator.repeat improvements and string.repeat by @irh in #356
  • Implement TryFrom<KValue> for some std types by @irh in #357
  • Various tweaks by @irh in #358
  • Inline strings by @irh in #359
  • Rework the color module by @irh in #360
  • Mutable indexing improvements by @irh in #361
  • stdio improvements by @irh in #363
  • Optional chaining by @irh in #364
  • Parser improvements by @irh in #365
  • Remove the @tests metakey by @irh in #366
  • Add an @index_mut metakey by @irh in #367
  • Allow space before colon in Maps by @unlessgames in #369
  • Flexible map syntax followups by @irh in #370
  • Update some dependencies by @irh in #371
  • Wasm followups by @irh in #373
  • Move koto/test/libs tests into their respective crates by @irh in #374
  • script_path / script_dir improvements by @irh in #375
  • Add random.shuffle by @irh in #376
  • Add exported map keys to local scope by @irh in #377
  • Introduce semicolons by @irh in #378
  • Add os.command to support spawning child processes by @irh in #380
  • Docs update by @irh in #381
  • Fix loading previously declared variables in the REPL by @irh in #382
  • Performance improvements by @irh in #385
  • Fix function comparisons by @irh in #386
  • Make the runtime single-threaded by default by @irh in #387
  • Add Color.alpha and .set_alpha by @irh in #388
  • Ensure result registers are set to null when a chain fails a null check by @irh in #389
  • Add support for optional type hints by @irh in #390
  • API improvements by @irh in #391
  • Various tweaks by @irh in #392
  • release prep by @irh in #393

New Contributors

Full Changelog: v0.14.1...v0.15.0

v0.14.1

11 Jun 12:36
@irh irh

Choose a tag to compare

What's Changed

  • Ensure that libs can be used with the rc build variant by @irh in #343

Full Changelog: v0.14.0...v0.14.1