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:50] – [Functions] rajit | language:types2 [2025/05/02 10:18] (current) – [Default parameters] 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 317: | Line 322: | ||
{ | { | ||
methods { | methods { | ||
- | function | + | function |
{ | { | ||
chp { | chp { | ||
self := s | 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 === | === 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, '' | ||