Skip to content

Releases

v0.54.0

Choose a tag to compare

@github-actions github-actions released this 03 Dec 14:35
a82a975

Highlights

Masks by name, on anything that holds cells. Pass a mask first, straight to text, a list, a grid or a 3D list. ->grid() isn't needed first any more:

fn get_tree_count(input: string): number {
  return $input->shapes(Tree, rotated)->count()
}

$input->shapes([Block, Ell], rotated)        // several masks at once
$input->shapes(Block, square, of: '#')       // masks and built-in shapes together

rotated turns a mask every way the input allows: back to front along a row, four quarter turns in a grid, and all 24 orientations in 3D (where points also have a layer).

Masks are just pictures. Every layout character matches a cell holding the same character, so symbols only lists the exceptions, and any marks a cell that isn't part of the shape:

type Tree extends Mask {
  layout: ```text
    #.#
    ...
    #.#
    ```
  symbols: { '.': any }
}

A blank line in a layout starts the next layer. Hovering a mask's name draws its picture with a legend.

Cleaner suggestions in calls. An argument slot offers only what it can take: no stray variables after a comma, each flag once as its bare word (rotated, never rotated:), and nothing that's already written. Signature help stays open and highlights the parameter you're on, and ->shapes() shows one form at a time.

Breaking changes

  • like: is removed from ->shapes(). Write the mask first: ->shapes(like: Tree) becomes ->shapes(Tree). The quick fix rewrites the call.
  • null in a mask's symbols is now any, with a quick fix.
  • Mask members are written with :. layout = ... is an error with a fix.
  • New mask checks: an empty layout, a layout that's all any, a tab in the picture, layers of different heights, a symbol longer than one character, and a symbol listed twice are errors. KS6025 warns about a character mapped to itself, and KS6026 fades a symbol the layout doesn't use. Each comes with a fix.
  • of:, size:, radius: and distance: given beside only masks are errors, with a fix that removes them.

Run kscript update to get this release.

What's Changed

Full Changelog: v0.53.0...v0.54.0

v0.53.0

Choose a tag to compare

@github-actions github-actions released this 03 Dec 12:30
cf68eae

Highlights

Masks extend Mask. A mask is now a type that extends the built-in Mask, and its members need no type written:

/// Trees at the four corners of a 3x3 square, anything between.
type Corners extends Mask {
  layout: ```text
    #.#
    ...
    #.#
    ```
  symbols: { '#': '#', '.': null }
}

echo $grid->shapes(like: Corners)->count()
  • The indentation every layout line shares isn't part of the layout, so a closing fence indented less than the picture works.
  • Mask and Mask[] can be parameter types, taking any type that extends Mask.
  • In the editor, Mask is suggested after extends, a new mask gets layout and symbols written out with a key for each layout character, missing keys are suggested inside symbols: { }, layout characters are coloured by what they match, and hovers explain each part.

Faster macOS release builds. The macOS binaries are built on a larger machine, so releases finish sooner.

Breaking changes

  • A type passed to ->shapes(like:) must extend Mask. Any other type is an error, with a quick fix that adds extends Mask. A mask without layout or symbols is an error too. See docs/upgrading.md.

Run kscript update to get this release.

What's Changed

Full Changelog: v0.52.0...v0.53.0

v0.52.0

Choose a tag to compare

@github-actions github-actions released this 03 Dec 11:20
76271af

What's Changed

Full Changelog: v0.51.0...v0.52.0

v0.51.0

Choose a tag to compare

@github-actions github-actions released this 03 Dec 10:16
8fa1839

Highlights

Debug in the terminal. kscript --debug app.kscript (or kscript run --debug) runs a script in a terminal debugger. It pauses before the first statement, shows the lines around it, and reads commands: n step over (Enter repeats), s step into, o step out, c continue, p <expr> print, v variables, w call stack, b <line> / d <line> breakpoints, q quit and h help. --break 12 pauses at that line instead. Stepping and breakpoints behave the same as in VS Code.

Grids by rows and columns. A list of lists reads like a csv with ->cells(), and ->positions_of() finds where things are:

for column in $grid->cells(columns) {
  echo $column->join('')
}

$trees = $field->grid()->positions_of('#')     // every { row, column } holding a tree

Name each item of a pick. A function given to a pick from ->combinations() or ->permutations() can take one parameter per item:

$trees->combinations(2)->count_of(fn(left, right) => $left.row == $right.row)

Find shapes. ->shapes() finds squares, rectangles, lines and circles in a grid or a list of points, and shapes you draw yourself:

$grid->shapes(square, of: '#', rotated)->count()    // level squares and diamonds
$grid->shapes(line, of: /[#@]/, size: 4)
$grid->shapes(circle, of: '~', radius: 3, distance: moves)

/// Three trees in a V, with anything between them.
type Fork {
  layout: string = ```text
    t~t
    ~t~
    ```
  symbols: map = { t: /[#@]/, '~': null }
}
$grid->shapes(like: [Fork], rotated)

Each match is { kind, points }, and the editor completes their fields. A missing of: on a grid, or a layout character missing from symbols, is an error with a fix.

Breaking changes

  • --debug now starts the terminal debugger. The old flag that shows the .NET stack trace is renamed to --stack-trace, and KSCRIPT_DEBUG to KSCRIPT_STACK_TRACE. --debug on any other command is an error naming --stack-trace.
  • ->transpose() is retired in favour of ->cells(columns). It is an error that names the replacement, with a quick fix. See docs/upgrading.md.

Run kscript update to get this release.

What's Changed

  • Read a grid's rows and columns, find points in it, and name picked items by @kylepantall in #352
  • Debug scripts in the terminal with kscript --debug; rename the stack-trace flag to --stack-trace by @kylepantall in #353
  • Find shapes in grids and point lists, and masks of your own by @kylepantall in #354

Full Changelog: v0.50.0...v0.51.0

v0.50.0

Choose a tag to compare

@github-actions github-actions released this 03 Dec 08:42
3deeda5

Highlights

A step debugger in VS Code. Press F5 in a .kscript or .ks.xml script, or click Debug above its first line, and it stops at your breakpoints.

  • Step Over (F10), Step Into (F11), Step Out (Shift+F11), Continue and Pause. Block functions such as ->map(fn(n) { ... }) are stepped into as their own frame.
  • Breakpoints with conditions, hit counts (3, >= 3, % 3) and log points.
  • The Call Stack shows every function the script is inside, each with Locals, Globals and Built-in variables. Lists, maps and records open to show their items.
  • Hovers, watches and the Debug Console work out expressions in the selected frame.
  • The script pauses where an error is thrown, before anything catches it.

The debugger is also available to other editors as kscript debug (the Debug Adapter Protocol on stdio). See docs/debugging.md.

Variables have their $ everywhere. A variable is now written the same way where it is declared, changed and read:

$apples = 12           // declares
$apples += 1           // changes
$count: int = $raw     // declares with a type
const $tax = 0.2       // never changes
echo $apples

Breaking changes

  • The bare spellings apples = 12, count: int = 4 and const tax = 0.2 are now KS6010 errors. The quick fix adds the $, and kscript check --fix rewrites a whole project. Parameters and loop items stay bare (fn double(n), for item in $list), and inside a type's methods a field is still .count += 1. See docs/upgrading.md.

Not yet

  • Debugging test files, @ask() input while debugging, and editing values in the Variables view.

Run kscript update to get this release.

What's Changed

  • Add a step debugger: breakpoints, stepping and variables in VS Code by @kylepantall in #350
  • Declare and assign variables with their $: $x = 12 by @kylepantall in #351

Full Changelog: v0.49.0...v0.50.0

v0.49.0

Choose a tag to compare

@github-actions github-actions released this 02 Dec 12:28
b45e13a

Highlights

One-line if. An if, elif or else that does one thing can be written on one line with =>, like match arms and fn(x) =>:

if $score >= 90 => return 'A'
if $temperature < 5 => echo 'Cold'
elif $temperature < 20 => echo 'Mild'
else => echo 'Warm'

Constants from other scripts in the editor. With const puzzle_input = ... in lib/puzzle-input.kscript, typing puz or $puz in main.kscript offers $puzzle_input. Picking it adds import "lib/puzzle-input.kscript" when the file isn't imported yet.

Fixes

  • $puzzle_input written without its import now says which file declares it, with an Import lib/puzzle-input.kscript quick fix (or Change to $day.puzzle_input when the file is imported as day).
  • A line that is only a value's name (puzzle_input) now says to write it with its $, with a fix that writes it (and the import, when one is needed).
  • At the start of a line, a constant is offered as $limit instead of limit, since a constant can't be given a new value.
  • Typing the { that opens a for, while, if, else, try or catch block no longer opens suggestions, so Enter starts a new line instead of writing echo.
  • Inside a collection, the editor suggests and allows only item.

What's Changed

  • Quiet suggestions after a block's opening brace; a collection suggests only item by @kylepantall in #347
  • One-line if with =>: if $continue => @method_call() by @kylepantall in #348
  • Suggest constants from other project scripts, and import them when picked by @kylepantall in #349

Full Changelog: v0.48.1...v0.49.0

v0.48.1

Choose a tag to compare

@github-actions github-actions released this 02 Dec 01:30
1aa3565

Highlights

Every row or every column. ->cells(rows) gives every row and ->cells(columns) every column (keyed by the header when there is one). row: and rows are one choice, and so are column: and columns:

$prices->cells(columns)               // { fruit: ['apple', 'plum'], price: [3, 5] }
$numbers->cells(columns)              // [[-903, 692], [-642, 853], [-518], ...]
$prices->cells(rows, column: 'price') // every row's price

Without a header, a column skips the rows too short to reach it, so ->cells(column: 2) is the third number of every row that has one.

Fixes

  • Hovers whose examples hold a ```csv block (such as ->cells()) showed the rest of the example as prose and the docs link as raw text. Code in hovers is now fenced so text blocks stay inside it.
  • ->cells(row) now says row needs a value and offers Change to rows. ->cells(rows, row: 0) is an error in the editor, not only when it runs.

Behaviour changes

  • Without a header, ->cells(column: n) skips rows too short to reach the column instead of failing. A column no row reaches is still an error.

What's Changed

  • Every row or column with ->cells(rows) / ->cells(columns), and fix hovers with text blocks by @kylepantall in #346

Full Changelog: v0.48.0...v0.48.1

v0.48.0

Choose a tag to compare

@github-actions github-actions released this 02 Dec 00:25
1a8cbb5

Highlights

One method for csv cells. ->cells() reads every row, one row, one column, or one cell:

$prices->cells()                          // every row
$prices->cells(row: 0)                    // the first row (-1 is the last)
$prices->cells(column: 'price')           // [3, 5]
$prices->cells(row: 1, column: 'price')   // 5

Puzzle input just works. A ```csv block of space-separated numbers splits into numbers, rows can have different lengths, and a first line of numbers is data, not a header:

echo $numbers->cells(row: 0)          // [-903, -642, -518, -585, 446]
echo $numbers->cells(row: -1)->sum()  // 1545

Cells written as numbers come out as numbers (codes such as 007 stay text). Tabs and semicolons split cells too, when there are no commas.

->numbers() on lists. Numbers stay, text gives the numbers in it, and inner lists are read: ['-3 4', 5]->numbers() is [-3, 4, 5].

Flags written as flags. header: false now gets a KS6024 style warning with a fix that writes not header (and overwrite: true becomes overwrite).

Behaviour changes

  • A csv's ->rows() and ->column() are retired in favour of ->cells(). Each is an error that names the replacement, and the quick fix keeps the arguments (->column('price') becomes ->cells(column: 'price')). See docs/upgrading.md.
  • csv cells written as numbers are now numbers, not text.
  • When a script doesn't say header or not header, a csv's first line is a header unless every cell on it is a number. .headers is empty for such a csv.
  • KS6024 (style warning): a yes/no option given true or false by name.

What's Changed

  • Read csv cells with one ->cells(row:, column:), and split numbers by spaces by @kylepantall in #345

Full Changelog: v0.47.0...v0.48.0

v0.47.0

Choose a tag to compare

@github-actions github-actions released this 01 Dec 22:19
4e20016

Highlights

One way to convert between formats. ->convert(from:, to:) reads and writes every format, with ->from() and ->to() as shortcuts:

order = $reply->convert(from: json)                 // read text as a value
fruits = $prices->convert(from: csv, as: Fruit[])   // read and check against a type
echo $basket->convert(to: csv, headers: ['fruit'])  // write a value as csv
echo $settings->convert(from: yaml, to: json)       // both at once

A csv type. A ```csv block (or data: csv = 'a,b') is now real CSV, checked where it is written. Read it with .headers, ->rows(not header, as: Row) and ->column(0, not header, as: int[]), or save it with ->save('prices'). Types in as: are written as declarations write them: as: int, as: Price[].

Doc comment names are links. @see @welcome, @deprecated Use @welcome instead., @throws PageMissing and calls in @example are links: Cmd+click goes to the declaration, hovers link to it, and find references and rename include them.

Better suggestions after a typed variable. x: LineValues = 123 then x-> suggests the type's methods and adds the missing $. A type's rules (one_of, not, min, max, pattern, extra) are checked against its base type by one checker shared by the run and the editor, and the type docs table now says which options suit which types.

Printing a fn is caught. Echoing a fn instead of calling it is a KS2006 warning, with a fix when |> call(...) was swallowed into the fn's body. The fn->call docs example is fixed.

Behaviour changes

  • ->json(), ->yaml(), ->csv(), ->markdown(), ->to_json(), ->to_yaml(), ->to_csv(), a response's ->json(), and a document's ->html(), ->latex() and ->markdown() are retired. Each is now an error that names its ->convert() replacement, and the editor's quick fix rewrites the call and keeps its arguments (->json(as: Price[]) becomes ->convert(from: json, as: Price[])). See docs/upgrading.md.
  • @read_csv($data) with csv text in $data is an error: csv text isn't a file path. The same goes for Markdown, LaTeX, json and fenced source given as a path.
  • A text block given to a declared non-csv type (const data: LineValues = ```csv) is an error, with a fix that appends ->column(...) or ->rows(as: ...).
  • A quoted or bracketed type in as: (as: 'Price[]', as: [Price]) is an error with a "Change to Price[]" fix.
  • one_of / not values the base type can't hold, a non-number min / max, a pattern no value can match, and extra: written inside a record's block are errors.
  • Text that isn't a number, given to an int-based type, is an error ('12' still fits).

What's Changed

  • Link names in doc comments (Cmd+click and hover links) by @kylepantall in #340
  • Fix the fn->call example that printed its own code; warn when a fn is printed by @kylepantall in #341
  • Suggest a typed variable's methods after ->, and check a type's rules against its base by @kylepantall in #342
  • Add a csv type for csv text blocks, and write as: types without quotes by @kylepantall in #343
  • Convert formats with one ->convert(from:, to:) by @kylepantall in #344

Full Changelog: v0.46.0...v0.47.0

v0.46.0

Choose a tag to compare

@github-actions github-actions released this 01 Dec 18:04
fecf4e3

Highlights

Arguments are checked strictly, in one place. One core rule decides whether an argument fits its parameter. The editor, kscript check and the run all use it and report the same words:

rolls = [4, 6, 6, 2]
$rolls->common(1, least)          // [2]: least on its own is true
$rolls->common(1, least: {})      // Error: The 'least' argument needs true or false, but this is a map.
$rolls->common(fn() => 2)         // Error: The 'count' argument needs a number, but this is a function.
$rolls->common(1, by: 3)          // Error: The 'by' argument needs a function, but this is a number.

A flag given a value offers the quick fix "Write least on its own".

Block functions must give a value where it is used. An empty or return-less block passed to ->map(), ->common(by:) and similar is an error. ->each() and blocks that throw are fine.

Trailing commas. A comma before the closing bracket on the same line is an error in every list: fn(a,), [1, 2,], { a: 1, }, ->take(2,) and fn name(a,). The quick fix is "Remove the comma". Lists written one item per line can still end with a comma.

A default main script. kscript and kscript run with no file now run the project's main script. They look for app.main in kscript.json, then main.kscript or index.kscript. kscript run tools runs a folder's main script. VS Code gets a Run Project command.

Declaration blocks. Completion inside type, native type, model, job, error, extend and enum blocks offers only what that block holds, at every caret position. A statement written there (echo, if, return) is now an error that says where to put it. Keyword hovers link to the docs.

Testing. @check_script(path) returns what kscript check reports for another script, so tests can check editor errors next to run errors.

Behaviour changes

  • A number passed for a true/false parameter is an error. It used to be read as true when it wasn't 0.
  • ->map(fn(x) { ... }) with no return is an error. Use ->each() when only what the block does matters.
  • [1, 2,], fn(a,) and other one-line lists that end in a comma are errors.
  • A statement inside a type, model, job or error block is a KS3007 error.

What's Changed

  • Suggest only what a declaration's block holds, and link keyword hovers to the docs by @kylepantall in #339
  • main.kscript and index.kscript are default entry scripts by @kylepantall in #337
  • Strictly check argument kinds, block results and trailing commas by @kylepantall in #338

Full Changelog: v0.45.0...v0.46.0