KScript ドキュメント
JA

言語

英語から自動翻訳されています。原文は英語です。

fn のフィールドとメソッド

関数です。ラムダ fn(x) => $x * 2 と <fn> 関数があります。

フィールドは、値についての単純な事実で、ドットを使い角括弧なしで読み取ります: $value.name。メソッドは引数を取るか処理を行い、-> で呼び出します: $value->name(arguments)。または、値をパイプで渡して呼び出します: $value |> name(arguments)。

KScript.Core から

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

引数を指定して関数を呼び出します。
例
<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')

any のメソッド