Function prototype: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
m (→‎{{header|Raku}}: Fix links and comments: Perl 6 --> Raku)
Line 1,153: Line 1,153:
=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly 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 [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.
There is no restriction on placement of prototype declarations. (Actually, we call them "stub declarations".) In fact, stub declarations are rarely needed in Raku because post-declaration of functions is allowed, and normal [http://design.raku.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 1,174: Line 1,174:
<lang perl6>sub foo ($, :$faster, :$cheaper --> Int) {...}</lang>
<lang perl6>sub foo ($, :$faster, :$cheaper --> Int) {...}</lang>


Example of prototype declarations for subroutines or procedures, which in Perl 6 is done simply by noting that nothing is returned:
Example of prototype declarations for subroutines or procedures, which in Raku is done simply by noting that nothing is returned:
<lang perl6>sub foo ($, $ --> Nil) {...}</lang>
<lang perl6>sub foo ($, $ --> Nil) {...}</lang>


Line 1,183: Line 1,183:
<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.
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.raku.org/S06.html#Unpacking_array_parameters unpacked] as well.
<lang perl6>sub foo ([$, @]) {...}</lang>
<lang perl6>sub foo ([$, @]) {...}</lang>