3,038
edits
(Use "user-defined" for the full name) |
(A+) |
||
Line 14: | Line 14: | ||
A tradfn can be [[niladic function|niladic]] which causes it to behave syntactically like an array. However, every time its name is referenced, it will run to create a result (if any). Such methods are often used to return a cache or as an entry point for the user. | A tradfn can be [[niladic function|niladic]] which causes it to behave syntactically like an array. However, every time its name is referenced, it will run to create a result (if any). Such methods are often used to return a cache or as an entry point for the user. | ||
== A+ == | |||
[[A+]] uses a reworked syle of function and operator definition than maintains the principle of a header that matches the way the function will be used, but differs in many details: | |||
* The result name is not included in the header; instead, the result of the last executed statement is returned (and so [[niladic function]]s cannot be defined). | |||
* The header is separated from the body with a colon, and the body of a multi-line function is enclosed in curly braces. | |||
* Functions have lexical scope. Variables assigned are local by default, and can be made global by enclosing their names in parentheses when assigning. | |||
== Comparison to dfns == | == Comparison to dfns == |