Function prototype: Difference between revisions
Content added Content deleted
mNo edit summary |
|||
Line 726: | Line 726: | ||
A routine may ask for a closure parameter to implement higher order functions. Typed or untyped signatures can be supplied. |
A routine may ask for a closure parameter to implement higher order functions. Typed or untyped signatures can be supplied. |
||
<lang perl6>sub foo (@, &:(Str --> Int)) {...}</lang> |
<lang perl6>sub foo (@, &:(Str --> Int)) {...}</lang> |
||
=={{header|Phix}}== |
|||
As explicit forward definitions, and optional - unless (eg) you want to use named parameters in a forward call.<br> |
|||
Should be identical to the actual definition, but preceded by "forward" and with no body. |
|||
<lang Phix>forward function noargs() -- Declare a function with no arguments |
|||
forward procedure twoargs(integer a, integer b) -- Declare a procedure with two arguments |
|||
forward procedure twoargs(integer, integer /*b*/) -- Parameter names are optional in forward (and actual) definitions |
|||
forward function anyargs(sequence s) -- varargs are [best/often] handled as a (single) sequence in Phix |
|||
forward function atleastonearg(integer a, integer b=1, ...); -- Default makes args optional (== actual defn)</lang> |
|||
No special syntax is needed on actual or forward function definitions for named parameters, and calls are identical whether still forward or now fully defined.<br> |
|||
Defaults on optional parameters in forward definitions can also be dummy (but type compatible) values should the actual not yet be defined. |
|||
=={{header|PL/I}}== |
=={{header|PL/I}}== |