RFC 168 (v1) Built-in functions should be functions

[email protected] (Perl6 RFC Librarian)
Newsgroups perl.perl6.language,perl.perl6.announce
Message-ID <[email protected]>
This and other RFCs are available on the web at
  http://dev.perl.org/rfc/

=head1 TITLE

Built-in functions should be functions

=head1 VERSION

  Maintainer: Johan Vromans <[email protected]>
  Date: 27 Aug 2000
  Mailing List: [email protected]
  Version: 1
  Number: 168

=head1 ABSTRACT

RFC 26 proposes to eliminate the distinction between functions and
operators from a language perspective.

This RFC proposes that all Perl built-in functions should be usable in
all ways normal functions can be used. It is part of a big consipracy
to remove the number of cases with exceptional behaviour in Perl.

=head1 DESCRIPTION

Named operators, like C<abs>, can be called like functions in which
case they behave like functions. However, that's where the similarity
ends. You cannot override most builtins, and cannot tack a reference
to them. 

There is no reason why the built-ins should be treated differently. A
famous Perl saying reads "if it looks like a function, it B<is> a
function." So be it.

In particular, it is desired that every built-in

=over 4

=item *

can be overridden by a user defined subroutine;

=item *

can have a reference taken;

=item *

has a useful prototype.

=back

=head2 Overriding

The principle of least surprise dictates that

    sub I<foo> { return 10 }
    print I<foo>();

should call I<foo>() and print "10" for all I<foo>.

Currently, most built-ins are excluded from this. For example:

    sub system { return 10 }
    print system();

Instead of calling the user defined system(), the built-in is used.

The second line may give a warning, but only if warnings are enabled:

    Ambiguous call resolved as CORE::system(), qualify as such or use &

=head2 References

You can call a built-in, but not take a reference.

    $a = \&system;
    print $a->(-1)

This gives an error:

    Undefined subroutine &main::system called

This should return a reference to the built-in instead.

Since C<&>I<foo> implicitly refers to the current package, it would be
acceptible to require

    $a = \&CORE::system;

Note that this currently (5.7.0 DEVEL6806) results in the error:

    Undefined subroutine &CORE::system called

which is surprising, if not misleading.

=head2 Prototypes

Currently, several built-ins do not provide prototype information. 

    prototype("CORE::abs")  ==>  ;$
    prototype("CORE::shift")  ==>  undef

This must be fixed. One might even call this a bug, although the
current prototype mechanism is not powerful enough to cope with all
built-ins. 

=head1 REFERENCES

RFC 26: Named operators versus functions

Tom Christiansen in <12231.967154045@chthon> (perl6-internals, Aug 24, 2000).
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.