The Fundamental Unit of Encapsulation

Eric Wilhelm: the fundamental unit of reuse is the loop.

Me: the fundamental unit of encapsulation is the lexical scope.

Perl 5 had a lot of goals. It was most effective in encouraging the development of custom extensions (see also CPAN, The). It has been less effective in its greater goal: encouraging the development of local language modifications.

You can trace the primary goal of Perl 6 (and the primary goal of Perl 6 isn't merely cleaning up inconsistencies of Perl 1 - 5 and Unix) to this design goal of Perl 5. Perl 6 adds a lot of great features, like multiple dispatch and function signatures and a powerful object system built on roles and hyperoperators. Perl 6's biggest and most important feature is grammars and rules.

If you look at Perl 5 a particular way, pragmas such as strict make a sublanguage (or a pidgin), in this case by restricting the possibilities of the code you could write to a smaller set of valid code. Of course, you can make the same argument for anything which exports symbols into another namespace, but then you annoy the people who think that writing APIs makes them elite DSL creators.

The most interesting feature of the strict pragma is that its effect is lexical. A lexical scope encapsulates language modifications from strict. That pidgin does not escape into outer scopes.

Extrapolate to Perl 6.

(If you've worked with macros in C or C++ or source filters in Perl 5, note that they have file scope, unless you have a flash of brilliance or obsessive attention to detail to restrict their scope. That's a pale shadow of Perl 6 grammars, and that's one reason Perl 6 implementation takes a while: you have to invent a grammar engine which allows arbitrary customization of tokens and precedence and productions in a composable and lexical fashion.)

... and it all builds on the notion of lexical scoping.

Modern Perl: The Book

cover image for Modern Perl: the book

The best Perl Programmers read Modern Perl: The Book.

sponsored by the How to Make a Smoothie guide

Categories

Pages

About this Entry

This page contains a single entry by chromatic published on June 1, 2010 4:33 PM.

How to Parse Perl 5 on the JVM was the previous entry in this blog.

The False Uniformity of Oatmeal Code is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.


Powered by the Perl programming language

what is programming?