KScript documentação
PT

Idioma

Traduzido automaticamente do inglês, que é a versão original.

Campos e métodos de fn

Funções: lambdas fn(x) => $x * 2 e funções <fn>.

Um campo é um dado simples sobre o valor, lido com um ponto e sem colchetes: $value.name. Um método recebe argumentos ou executa alguma ação, e é chamado com ->: $value->name(arguments), ou com o valor passado por pipe: $value |> name(arguments).

Do KScript.Core

#fn->call(args...) → any

Chama a função com estes argumentos.
Exemplo
<let name="area" value="fn(width, height) => $width * $height" />
<!-- 42, because call gives 6 to width and 7 to height. -->
<echo>{ $area->call(6, 7) }</echo>
<!-- 'Hello Ada'. The brackets end the fn: without them, |> call('Ada') would be part of its body, and nothing would call it. -->
<echo>{ (fn(name) => 'Hello ' + $name) |> call('Ada') }</echo>
$area = fn(width, height) => $width * $height
// 42, because call gives 6 to width and 7 to height.
echo $area->call(6, 7)
// 'Hello Ada'. The brackets end the fn: without them, |> call('Ada') would be part of its body, and nothing would call it.
echo (fn(name) => 'Hello ' + $name) |> call('Ada')

Métodos de qualquer tipo