Overriding/redefining p6 built-in functions

9 views
Skip to first unread message

Andrew Savige

unread,
May 8, 2005, 12:39:03 AM5/8/05
to perl6-l...@perl.org
A crude hack sometimes used by gung ho p5 testers is to redefine
perl built-in functions. For example:

BEGIN {
*CORE::GLOBAL::read = sub (*\$$;$) { return undef };
}

to test read failures (and so boost your Devel::Cover score :-).
This technique is not very convenient (must be in a BEGIN block).
Moreover, some p5 functions (e.g. print) cannot be overridden.

I was wondering how/if p6 will support the overriding of built-in
functions (I imagine QA would be the main use for this).

/-\


Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com

Larry Wall

unread,
May 8, 2005, 10:20:04 AM5/8/05
to perl6-l...@perl.org
On Sun, May 08, 2005 at 02:39:03PM +1000, Andrew Savige wrote:
: A crude hack sometimes used by gung ho p5 testers is to redefine

: perl built-in functions. For example:
:
: BEGIN {
: *CORE::GLOBAL::read = sub (*\$$;$) { return undef };
: }
:
: to test read failures (and so boost your Devel::Cover score :-).
: This technique is not very convenient (must be in a BEGIN block).
: Moreover, some p5 functions (e.g. print) cannot be overridden.

It's not clear that Perl 6 has *any* built-in functions in the sense
that Perl 5 does. All global functions live in the * namespace, which
is the last place Perl looks. Any lexical or package scope will
override a * function.

You can also do partial overrides of multimethods when you have enough
type information.

You also have control of the Perl grammar so that, even if something
is more "built-in" than a global function, you can change the grammar
rule that parses it. On a small scale, this means you can define macros
in various grammatical categories.

: I was wondering how/if p6 will support the overriding of built-in


: functions (I imagine QA would be the main use for this).

Absolutely everything is overridable in Perl 6, except the fact that
the program is parsed as Standard Perl up till the first declaration
(which might, of course, occur before the program file in a switch.)

Larry

Gaal Yahas

unread,
May 8, 2005, 10:26:30 AM5/8/05
to perl6-l...@perl.org
On Sun, May 08, 2005 at 07:20:04AM -0700, Larry Wall wrote:
> Absolutely everything is overridable in Perl 6, except the fact that
> the program is parsed as Standard Perl up till the first declaration
> (which might, of course, occur before the program file in a switch.)

On that note, http://perlnomic.org/ .

--
Gaal Yahas <ga...@forum2.org>
http://gaal.livejournal.com/

Reply all
Reply to author
Forward
0 new messages