Function prototype: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 551: | Line 551: | ||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
There is no restriction on placement of prototype declarations. (Actually, we call them "stub declarations".) In fact, stub declarations are rarely needed in Perl 6 because post-declaration of functions is allowed, and normal function declarations do not bend the syntax the way they sometimes do in Perl 5. |
There is no restriction on placement of prototype declarations. (Actually, we call them "stub declarations".) In fact, stub declarations are rarely needed in Perl 6 because post-declaration of functions is allowed, and normal [http://design.perl6.org/S06.html#Subroutines_and_other_code_objects function declarations] do not bend the syntax the way they sometimes do in Perl 5. |
||
Note that the <tt>...</tt> in all of these stub bodies is literally part of the declaration syntax. |
Note that the <tt>...</tt> in all of these stub bodies is literally part of the declaration syntax. |
||
Line 580: | Line 580: | ||
A routine may make a named parameter mandatory using exclamation mark. (This is more useful in multi subs than in stubs though.) |
A routine may make a named parameter mandatory using exclamation mark. (This is more useful in multi subs than in stubs though.) |
||
<lang perl6>sub foo ($, :$option! --> Int) {...}</lang> |
<lang perl6>sub foo ($, :$option! --> Int) {...}</lang> |
||
A routine may unpack an <tt>Array</tt> automaticly. Here the first element is stored in a scalar and the rest in an <tt>Array</tt>. Other buildin types can be [http://design.perl6.org/S06.html#Unpacking_array_parameters unpacked] as well. |
|||
<lang perl6>sub foo ([$, @]) {...}</lang> |
|||
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> |
|||
=={{header|PL/I}}== |
=={{header|PL/I}}== |