Releases: koto-lang/koto
Releases · koto-lang/koto
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.
v0.15.3
v0.15.2
v0.15.1
v0.15.0
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
exportby @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
catchblocks by @irh in #354 - Add support for generic types in the derive macros by @irh in #355
iterator.repeatimprovements andstring.repeatby @irh in #356- Implement
TryFrom<KValue>for somestdtypes 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
stdioimprovements by @irh in #363- Optional chaining by @irh in #364
- Parser improvements by @irh in #365
- Remove the
@testsmetakey by @irh in #366 - Add an
@index_mutmetakey 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_dirimprovements by @irh in #375- Add
random.shuffleby @irh in #376 - Add exported map keys to local scope by @irh in #377
- Introduce semicolons by @irh in #378
- Add
os.commandto 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
- @madskjeldgaard made their first contribution in #319
- @edenbynever made their first contribution in #326
- @JamesHallowell made their first contribution in #341
- @unlessgames made their first contribution in #369
Full Changelog: v0.14.1...v0.15.0