"Chris Yocum" <[EMAIL PROTECTED]> writes:
> Hi All,
>      At the risk of sounding a bit thick, I have a couple of questions
> about Perl6's multi keyword and mutilmethod in general.  This seems
> like overloaded functions from C++ so why do we need a key word to
> declare them rather than using something like C++'s name mangling?  Is
> there something that I am just missing here?

Because of your question I had a look at Synopsis 6
(http://dev.perl.org/perl6/doc/design/syn/S06.html). I should do this
more often. Maybe you should also have a look. It's always refreshing.

At least the many keywords seem to be necessary to map the complexity
of different paradigms possible in Perl6. Multimethods are not just
overloading as in C++. Second, the different keywords declare
different behaviour you can choose. Just read S06, it's explained
quite understandable.


> can we now write generic/overloaded functions in Perl6 without OO or
> have I conflated OO with overloading incorrectly?

However it's currently called, with multimethods you can elegantly
"divide and conquer" your code into different subs instead of ugly
"parameter checking if-cascades".

  multi sub talk () { say 'Loose Talk Is Noose Talk.'; }
  multi sub talk (String $msg) { say $msg; }
  multi sub talk (String $msg, Int $times) { say $msg x $times; }
  
  talk("Hi", 10);
  talk("Hello");
  talk;


GreetinX
Steffen 
-- 
Steffen Schwigon <[EMAIL PROTECTED]>
Dresden Perl Mongers <http://dresden-pm.org/>

Reply via email to