in reply to Re^2: Function call
in thread Function call

Perhaps moritz was referring to multimethods, aka multiple dispatch, which are provided by Perl 6 but not Perl 5.

Replies are listed 'Best First'.
Re^4: Function call
by moritz (Cardinal) on Mar 02, 2012 at 10:08 UTC

    That's correct. But in Perl 6 it's not restricted to methods, it also works on subroutines.

    Basically it means that you have several routines (called "candidates" in p6 speak) with the same name but different signatures, and the closest match between the run-time argument list and the signatures determines the candidate to call

    $ perl6 -e 'multi f(0) { 1 }; multi f(Int $x) {$x * f($x - 1) }; say f + 5' 120

    The lack of subroutine signatures and user-exposed core types make it hard to introduce multis in Perl 5; but some of the current improvements and plans for Perl 5 make me hopeful that some day we'll have enough infrastructure to support them.

    S06 has many more details on the Perl 6 multis.

Re^4: Function call
by tobyink (Canon) on Mar 02, 2012 at 10:07 UTC
Re^4: Function call
by JavaFan (Canon) on Mar 02, 2012 at 10:05 UTC
    Even with multiple dispatch, just one method is called. Multiple dispatch allows you to have several methods with the same name, but because the signature is different (that is, each of them accepts a different set of parameter types), the compiler can figure out which one should be called.

    It's a little bit like Perls ability to have a scalar, array, hash, subroutine and filehandle, all by the same name, and still knowing which is which. Or values having both string and numeric values, without Perl getting confused.