ソースを参照

operator NEW documentation

Vladislav Folts 10 年 前
コミット
087eeb5b1c
2 ファイル変更32 行追加0 行削除
  1. 31 0
      doc/wiki/eberon-operator-NEW.md
  2. 1 0
      doc/wiki/eberon.md

+ 31 - 0
doc/wiki/eberon-operator-NEW.md

@@ -0,0 +1,31 @@
+Original procedure NEW in Oberon is not always convenient to use - it requires already declared pointer variable:
+
+    PROCEDURE make(): Pointer;
+    VAR
+        result: Pointer;
+    BEGIN
+        NEW(result);
+        RETURN result;
+    END;
+
+Operator NEW in [[Eberon|eberon]] returns a pointer to created record. So code above could be rewritten in shorter form like:
+
+    PROCEDURE make(): Pointer;
+        RETURN NEW T();
+    END;
+
+Also operator NEW can be used to initialize a pointer variable to base record (while creating derived record):
+
+    IF condtition1 THEN
+        base := NEW Dervied1();
+    ELSE
+        base := NEW Derived2();
+    END;
+
+Operator NEW also can be used to create a record having constructor with parameters:
+
+    r := NEW T(param1, param2);
+
+Operator NEW from language grammar standpoint is a part of *designator* so it is possible to denote record fields right after creating:
+
+    NEW T().field

+ 1 - 0
doc/wiki/eberon.md

@@ -12,6 +12,7 @@ Eberon basically extends original Oberon (excluding additional [restrictions](#r
 * [[Array indexOf() method|eberon-array-methods]]
 * [[Record fields read-only export|eberon-record-fields-read-only-export]]
 * [[Procedure call result can be denoted|eberon-procedure-call-result]]
+* [[Operator NEW|eberon-operator-NEW]]
 * [[Syntax relaxations|eberon-syntax-relaxations]]
 * Non-scalar variables (arrays and records) can be exported (forbidden in oberon for some unknown reason).