KScript 文档
ZH

fn 字段与方法

函数:lambda 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 的方法