-
Notifications
You must be signed in to change notification settings - Fork 2
lambda en
ab25cq edited this page Jan 29, 2018
·
2 revisions
lambda is a chunk of code that can be handled as an object. It is a familiar function in functional programming languages. There is also closure in lambda, lambda can not access parent variables, closure can also access parent variables. I think it is quick to see an example.
> a: lambda(int) = lambda(num: int) {
for (i := 0; i < num; i ++) {
println ("HO!");
}
}
> a(3)
HO!
HO!
HO!
> n:int = 3;
> b:lambda () = closure () {
for (i: = 0; i < n; i ++) {
println ("HO!");
}
n = 999;
}
> b ()
HO!
HO!
HO!
> n
999
Since closure is a type of lambda, the type name is supposed to be written with lambda. closure has access to the parent n variable. It is also possible to rewrite parent variables. You can also create a return value. Please look at the following.
> a: lambda (int): int = lambda (n: int): int {
return n * 2;
}
> a (123)
246
lambda (n: int): int with int and n as an argument and return value of int type lambda. In this case the contents are lambda which returns twice the argument, so a (123) returns 246.
- フリーフォーマット
- 変数と関数について
- 条件分岐と演算子
- 論理演算子
- ビット演算子
- ループ
- ブロック
- コメント
- アノテーション
- ナルエイブル
- プリミティブクラス
- 配列
- クラス
- クラスフィールドとクラスメソッド
- dynamic_class
- boxingとunboxing
- プリミティブ型とスペシャルフィールド
- スペシャルメソッド
- インターフェース
- 移譲
- モジュール
- ジェネリクス
- メソッドジェネリクス
- 関数
- 列挙型(enum)
- 自動setterとgetterの定義
- when文
- 変数の宣言の取り消し
- 例外処理
- 多重代入
- 代入時の自動キャスト
- C言語へのFFI
- ローカル変数の宣言
- メモリーセーフなポインタ
- 例外演算子
- 糖衣構文