Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| language:types2 [2025/04/21 15:18] – [Macros] rajit | language:types2 [2025/09/19 10:22] (current) – [Functions] rajit | ||
|---|---|---|---|
| Line 199: | Line 199: | ||
| Note that ACT is very strict about type-checking; | Note that ACT is very strict about type-checking; | ||
| + | |||
| + | ==== Grouping parameters ==== | ||
| + | |||
| + | Parameters can be combined into [[language: | ||
| + | |||
| ===== Direction flags ===== | ===== Direction flags ===== | ||
| Line 311: | Line 316: | ||
| ==== Functions ==== | ==== Functions ==== | ||
| - | === Operator overloading === | + | In addition to macros, [[language: |
| + | |||
| + | <code act> | ||
| + | deftype signed_int (bool s; int< | ||
| + | { | ||
| + | methods { | ||
| + | function negative() : bool | ||
| + | { | ||
| + | chp { | ||
| + | self := s | ||
| + | } | ||
| + | } | ||
| + | function mag() : int< | ||
| + | { | ||
| + | chp { | ||
| + | self := v | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | With this definition, a user can use method calls to access the fields of the structure as follows: | ||
| + | |||
| + | <code act> | ||
| + | | ||
| + | ... | ||
| + | chp { | ||
| + | ... | ||
| + | [ s.negative() -> log (" | ||
| + | [] else -> log (" | ||
| + | ] | ||
| + | } | ||
| + | ... | ||
| + | </ | ||
| + | |||
| + | Note that functions cannot have any side-effects; | ||
| + | any of the members of the pure structure. Macros can be used to change those. | ||
| + | |||
| + | ==== Operator overloading ==== | ||
| + | |||
| + | Functions within pure structures are also used to support operator overloading. In particular, the following function methods are interpreted to be the definition of operator overloading for arithmetic operators: | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | An example of a fixed-point arithmetic datatype is provided in the [[https:// | ||
| + | In the linked example, '' | ||