in reply to & function prototypes and parens

Prototypes are a hack. There are a bunch of keyword behaviours that just arent implemented for user functions, even with prototypes. But you do know that
foo(sub {$_ =~ /foo/}, $a, $b, $c);
works right?

--- demerphq
my friends call me, usually because I'm late....

Replies are listed 'Best First'.
Re: Re: & function prototypes and parens
by steves (Curate) on Feb 08, 2003 at 15:27 UTC

    I was aware that works. I just thought there'd be an explanation for why the other doesn't work when it does work with built-ins. Off the top of my head I can't think of anything else a built-in function can do that I can't. But maybe I'm distinguishing between functions and keywords when such a distinction really doesn't exist internally?

    Semi-enlightened. Thanks.

      The problem is that perls many little idiosyncracies make it difficult to generalize the behaviour of all the built ins. print is another exaple of a keyword whose behaviour cannot be emulated by a user defined function. As are all of the keywords which return undef when passed to prototype.

      As I said before prototypes are a hack. So not all of the special behaviour of map/grep is provided by the prototype. My guess is that this has to do with the issues related to providing complete map or print like behaviour to generalized subs. Too many rules are violated by these procedures for it to be worthwhile to support it except in very special cases. Consider that you didnt cover all the ways that map can be called:

      print map { "foo $_" } @list; print map({"foo $_"} @list); print map "foo $_", @list; print map("foo $_", @list); print map(sub { "foo $_" },@list); # this doesnt do what you think....
      The last one is an example of the troubles that come with map's handling. It parses as
      print map { sub { "foo $_" } } @list;
      which frankly would seem to be an odd interpretation for a user generated function. Luckily we are trained from the get go to treat map as an unusal keyword.

      --- demerphq
      my friends call me, usually because I'm late....