-
Notifications
You must be signed in to change notification settings - Fork 4
Groups
Often times, when a program utilizes a large number of top-level identifiers, namely those for structure and function prototypes, cluster the identifier/namespace register. FastCode utilizes the group keyword to organize identifiers into easily manageable components.
Groups are not declared using the open and close braces, which are reserved for control flow structures (if, else, while, etc...), but rather with group
and endgroup
. Note that group names do not have to be unique, as they can be used as partial "modules". Every structure prototype, create structure, function prototype, and function call get their identifiers substituted with a new identifier which consists of their old identifiers followed by their group names.
group math
proc abs(n) => if n >= 0 => return n else => return -n
endgroup
The above example ultimately gets translated into the following after preprocessing.
proc abs@math(n) => if n >= 0 => return n else => return -n
The same goes for nested groups.
group math
group trig
proc sec(n) => return cos(n)^-1
proc cosec(n) => return sin(n)^-1
proc cotan(n) => return tan(n)^-1
endgroup
endgroup
The above gets translated into...
proc sec@trig@math(n) => return cos@trig@math(n)^-1
proc cosec@trig@math(n) => return sin@trig@math(n)^-1
proc cotan@trig@math(n) => return tan@trig@math(n)^-1
Note that groups can also be used for ease of identifier access.
group math
print(abs(mynum))
endgroup
Instead of typing abs@math
, you'd only have to type abs
.
Note that group identifier preprocessing doesn't apply to constants, but applies to everything else (structures, procedures, and variables).