File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -1811,6 +1811,50 @@ c.incr();
1811
1811
check (c.get() == 3);
1812
1812
@end example
1813
1813
1814
+ There is no @emph {this } or @emph {self } available inside an object's
1815
+ methods, either implicitly or explicitly, so you can't directly call
1816
+ other methods. For example:
1817
+ @example
1818
+ obj my_obj() @{
1819
+ fn get() -> int @{
1820
+ ret 3;
1821
+ @}
1822
+ fn foo() @{
1823
+ auto c = get(); // Fails
1824
+ @}
1825
+ @}
1826
+ @end example
1827
+
1828
+ The current replacement is to write a factory function for your type,
1829
+ which provides any private helper functions:
1830
+ @example
1831
+ type my_obj =
1832
+ obj @{
1833
+ fn get() -> int;
1834
+ fn foo();
1835
+ @} ;
1836
+
1837
+ fn mk_my_obj() -> my_obj @{
1838
+ fn get_helper() -> int @{
1839
+ ret 3;
1840
+ @}
1841
+
1842
+ obj impl() @{
1843
+ fn get() -> int @{
1844
+ ret get_helper();
1845
+ @}
1846
+ fn foo() @{
1847
+ auto c = get_helper(); // Works
1848
+ @}
1849
+ @}
1850
+
1851
+ ret impl();
1852
+ @}
1853
+ @end example
1854
+
1855
+ This factory function also allows you to bind the object's state
1856
+ variables to initial values.
1857
+
1814
1858
@node Ref.Item.Type
1815
1859
@subsection Ref.Item.Type
1816
1860
@c * Ref.Item.Type:: Items defining the types of values and slots.
You can’t perform that action at this time.
0 commit comments