KScript 문서
KO

언어

영어에서 자동 번역되었습니다. 원문은 영어입니다.

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의 메서드