KScript docs
EN

The language

Variables and output

<let name="count" value="0" /> <!-- declare -->
<let name="people" value="[{ name: 'Joan', age: 82 }]" />
<set name="count" value="$count + 1" /> <!-- change it -->
<set name="count" op="+=" value="1" />
<let name="total" value="$price * $qty" />
<const name="limit" value="10" />
<let name="n" type="int" value="$args[0]" /> <!-- convert, or stop with a clear error -->

<echo>Hello, {$name}! You have { $count } new { $count == 1 ? 'message' : 'messages' }.</echo>
<echo>{ $person.name } is { $person.age }</echo>
<echo>{ $people }</echo> <!-- a map or list of maps prints as indented JSON -->
$count = 0 // declare
$people = [{ name: 'Joan', age: 82 }]
$count = $count + 1 // change it
$count += 1
$total = $price * $qty
const $limit = 10
$n: int = $args[0] // convert, or stop with a clear error

echo "Hello, {$name}! You have { $count } new { $count == 1 ? 'message' : 'messages' }."
echo "{ $person.name } is { $person.age }"
echo "{ $people }" // a map or list of maps prints as indented JSON

A map, or a list of maps, on its own in echo prints as indented JSON, coloured in a terminal (unless NO_COLOR is set). Inside text it stays on one line. echo(format: json) reformats JSON text, and ->convert(to: json) gives compact JSON.

Variables belong to the block they are declared in. {{ and }} are literal braces.

"Double quotes" interpolate expressions in { } after echo, in assignments, in return values, and in call arguments. In .kscript, KS6019 catches bare references and offers to wrap them in braces. 'Single quotes' keep text exactly as written, so text with nothing to fill in goes in them (KS6020 suggests the change). Quoted text after echo is printed as written too, with its spaces: echo " - { $item }" prints the two spaces. In XML, the text between <echo> and </echo> is trimmed and loses the indentation its lines share, and the values filled into it are left alone, except that an empty value leaves no stray space behind and the text never ends in a line break.

<let name="greeting" value="&quot;Hello { $name }, you have { $count * 2 } points.&quot;" />
<let name="label" value="'Write $name to use a variable.'" /> <!-- kept as written -->
<let name="boxes" value="&quot;{ 2 * 3 } boxes, { [1, 2]->count() } lists&quot;" /> <!-- a { } always holds an expression -->
<let name="route" value="'/users/{id}'" /> <!-- text with braces of its own goes in single quotes -->
$greeting = "Hello { $name }, you have { $count * 2 } points."
$label = 'Write $name to use a variable.' // kept as written
$boxes = "{ 2 * 3 } boxes, { [1, 2]->count() } lists" // a { } always holds an expression
$route = '/users/{id}' // text with braces of its own goes in single quotes

A { } in double quotes always holds an expression, whatever it opens with: a variable, a command, a type ({ Order->count() }), a number or a bracketed sum. Text with braces of its own, such as a route ('/users/{id}'), a pattern ('\d{3}'), CSS or translation text ('Hello {name}'), goes in single quotes, or doubles them: "/users/{{id}}". The text given to @sql is the one exception: its { } are sent as parameters, never pasted in (see Data).