Optional parameters: Difference between revisions

GP and PARI
(Go solution)
(GP and PARI)
Line 1,014:
{T sort(ordering:fun {$ A B} {Length B} < {Length A} end)}</lang>
 
 
=={{header|PARI/GP}}==
As it happens the built-in <code>vecsort()</code> function fulfills all the requirements of this task. In general optional arguments are handled in GP by default values:
<lang parigp>sort(v, ordering=0, column=0, reverse=0)</lang>
while in PARI it is handled by checking for NULL (assuming parser code DG, see 5.7.3 in the User's Guide to the PARI library):
<lang C>/*
GP;install("test_func", "vDG", "test", "path/to/test.gp.so");
*/
void
test_func(GEN x) {
if (x == NULL)
pari_printf("Argument omitted.\n");
else
pari_printf("Argument was: %Ps\n", x);
}</lang>
 
=={{header|Perl}}==
Line 1,038 ⟶ 1,053:
{printf "%-5s", $_;}
print "\n";}</lang>
 
=={{header|Perl 6}}==
Using named parameters: