in reply to Re^2: Prototype for constant items???
in thread Prototype for constant items???

I want the possibility of a more rigid compile-time checking

And therein lies your problem.

Prototypes are primarily hints for the parser what to expect next, and allow you to write functions that syntactically resemble built-in functions.

When you abuse them for anything else you're bound to run into limitations rather soon.

Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^4: Prototype for constant items???
by LanX (Saint) on Sep 25, 2009 at 13:52 UTC
    Sadly thats only half of the truth. Many builtins can't be modelled with prototypes and rely on magicly hidden parsing rules.

    So prototypes are only a crippled mechanism.

    The fact that you can restrict to scalarrefs of $variables with \$ but not to refs of literals is an obvious gap in the definition, which you can't deny.

    The possibility to warn about errors like in join @a,@b could make perl much more user friendly.

    I don't even see a possibility to warn about this at runtime!!!

    (well except magic things like using caller to parse the calling the line of code)

    Cheers Rolf

      Sadly thats only half of the truth. Many builtins can't be modelled with prototypes and rely on magicly hidden parsing rules.

      That's why I wrote syntactically resemble

      And yes, this is indeed a problem. Maybe not for own function (which rarely need such things), but when you try to override built-ins. For example autodie does that, but can't handle all the variants that the core functions do.

      It's one of the things we try to make better in Perl 6: no built-in should rely on magic that's not available to the user, so that everything can be overridden and mimicked. So far I think we did a rather good job at that, though much of that isn't implemented yet.

      As far as we can assure that candidate lists known at compile time, it would also be possible to catch some form of errors then (like arity mismatch).

      Perl 6 - links to (nearly) everything that is Perl 6.