|
10 | 10 | - [Statements](#statements)
|
11 | 11 | - [Schema](#schema)
|
12 | 12 | - [Database](#database)
|
13 |
| - - [Trait](#trait) |
14 | 13 | - [Import](#import)
|
15 | 14 | - [Query](#query)
|
16 | 15 | - [Ungrounded Error: Unassigned/Unbound Error](#ungrounded-error-unassignedunbound-error)
|
@@ -59,7 +58,6 @@ A GödelScript program may include:
|
59 | 58 | - [Module and symbol import statements](#import)
|
60 | 59 | - [Schema type declarations](#schema)
|
61 | 60 | - [Database type declarations](#database)
|
62 |
| -- [Trait declarations](#trait) |
63 | 61 | - [Method implementations](#method-implementation)
|
64 | 62 | - [Function declarations and implementations](#function)
|
65 | 63 | - [Query declarations](#query)
|
@@ -87,22 +85,10 @@ database NewDB {
|
87 | 85 | file: *File
|
88 | 86 | }
|
89 | 87 |
|
90 |
| -// Trait declaration |
91 |
| -trait FileTrait { |
92 |
| - fn getId(self) -> int; |
93 |
| -} |
94 |
| - |
95 |
| -// Impl trait for |
96 |
| -impl FileTrait for File { |
97 |
| - fn getId(self) -> int { |
98 |
| - return self.id |
99 |
| - } |
100 |
| -} |
101 |
| - |
102 | 88 | // Impl
|
103 | 89 | impl File {
|
104 | 90 | @data_constraint
|
105 |
| - fn all() -> *File { |
| 91 | + fn __all__() -> *File { |
106 | 92 | yield File {id: 1}
|
107 | 93 | yield File {id: 2}
|
108 | 94 | }
|
@@ -639,22 +625,9 @@ fn out() -> bool {
|
639 | 625 | }
|
640 | 626 | ```
|
641 | 627 |
|
642 |
| -##### Custom Full Set Method |
643 |
| - |
644 |
| -A `schema` allows using static methods with different names than `__all__` to indicate that some sets also exist within its full set. This method must also contain the special annotation `@data_constraint`. This method is generally used to manually add some data to the full set of that type. |
645 |
| - |
646 |
| -```rust |
647 |
| -impl File { |
648 |
| - @data_constraint |
649 |
| - fn extend_example() -> *File { |
650 |
| - yield File {id: 1234567} |
651 |
| - } |
652 |
| -} |
653 |
| -``` |
654 |
| - |
655 | 628 | #### Constructing Anonymous Instances
|
656 | 629 |
|
657 |
| -GödelScript allows for the creation of anonymous instances with a specific syntax. The creation of anonymous instances is contingent on the instance existing within the full set of the `schema`, unless this usage appears within a `@data_constraint` method, in which case the result will be empty. |
| 630 | +GödelScript allows for the creation of anonymous instances with a specific syntax. The creation of anonymous instances is contingent on the instance existing within the full set of the `schema`, unless this usage appears within a `__all__` method, in which case the result will be empty. |
658 | 631 |
|
659 | 632 | ```rust
|
660 | 633 | schema A {
|
@@ -713,6 +686,7 @@ schema MyFile extends File {}
|
713 | 686 | ##### Method Override
|
714 | 687 |
|
715 | 688 | If the subclass implementation contains a method with the same name as the parent class, the parent method will be **overridden** by the subclass method.
|
| 689 | +The overridden method can use different parameter and return type. There's no need to use the same parameter and return type of parent class method. |
716 | 690 |
|
717 | 691 | ```rust
|
718 | 692 | schema File {
|
@@ -799,38 +773,6 @@ fn getAnnotation() -> Annotation {
|
799 | 773 | }
|
800 | 774 | ```
|
801 | 775 |
|
802 |
| -### Trait |
803 |
| - |
804 |
| -#### Trait Declaration |
805 |
| - |
806 |
| -The syntax for declaring a `trait` is as follows: |
807 |
| - |
808 |
| -```rust |
809 |
| -trait Example { |
810 |
| - fn getId(self) -> int; |
811 |
| - fn getName(self) -> string; |
812 |
| - fn getValueByName(self, name: string) -> string; |
813 |
| -} |
814 |
| -``` |
815 |
| - |
816 |
| -#### Impl Trait |
817 |
| - |
818 |
| -The syntax is similar to `impl`, but you must implement all the functions declared in the `trait` to pass compilation. |
819 |
| - |
820 |
| -```rust |
821 |
| -impl Example for XmlElement { |
822 |
| - fn getId(self) -> int {return self.id} |
823 |
| - fn getName(self) -> int {return self.name} |
824 |
| - fn getValueByName(self, name: string) -> int { |
825 |
| - for(attr in XmlAttribute(XmlDB::load("...")) { |
826 |
| - if (attr.getName() = name && attr.id = self.getAttribute().id) { |
827 |
| - return attr.getValue() |
828 |
| - } |
829 |
| - } |
830 |
| - } |
831 |
| -} |
832 |
| -``` |
833 |
| - |
834 | 776 | ### Import
|
835 | 777 |
|
836 | 778 | GödelScript uses the `use` keyword to import symbols from other files:
|
@@ -996,7 +938,7 @@ Query is used for simple queries and is guaranteed to be output even without dec
|
996 | 938 |
|
997 | 939 | ```rust
|
998 | 940 | query name from
|
999 |
| - variable in initial value, |
| 941 | + variable in initial value, |
1000 | 942 | variable in initial value,
|
1001 | 943 | variable in initial value
|
1002 | 944 | where condition
|
@@ -1044,8 +986,8 @@ fn db() -> JavaDB {
|
1044 | 986 | }
|
1045 | 987 |
|
1046 | 988 | query class_method from
|
1047 |
| - Callable m in Callable(db()), |
1048 |
| - Class c in Class(db()) |
| 989 | + m in Callable(db()), |
| 990 | + c in Class(db()) |
1049 | 991 | where
|
1050 | 992 | c.id = m.getBelongedClass().id
|
1051 | 993 | select
|
|
0 commit comments