[pgh-pm] Ideas for technical talks for 9 April 2003 meeting

Tom Moertel tom at moertel.com
Fri Mar 28 14:58:59 CST 2003


Perlfolk,

At the last meeting I volunteered to give a talk or two at the
upcoming technical meeting.  Since that meeting is rapidly
approaching, it's time for me to figure out what to talk about.  Here
are a couple of ideas that are based on work I have done recently.
Please let know whether you would be interested in having me talk
on either or both (or something else).

    Functional Templates

        Most template systems encourage programmers to view templates
        as documents that contain placeholders or processing
        instructions that can be replaced or evaluated dynamically.
        However, there is another way of looking at templates that
        yields a simple yet powerful method for building and managing
        complex sets of information.  That way is to view templates as
        *functions* (hence the name) that take named values as input
        and yield documents or other templates as output.  The real
        power of this method is revealed by passing functional
        templates as *arguments* to other templates, which allows for
        global sharing and local specialization.  A host of other
        interesting properties appear when one considers that the
        arguments themselves can be the results of calling other
        functional templates.  Mind-bending fun for all!

        In this talk I will describe functional templates and then
        demonstrate a Perlriffic functional-template system that I
        created to build web sites for my company and its clients.
        The system not only processes functional templates but also
        tracks dependencies among templates, their arguments, and
        results to ensure that output can be kept up to date with
        a minimum of template processing.


    Layout Rule for Perl

        Python allows programmers to define blocks based on code
        layout (i.e., the indentation of lines).  At first I mocked
        these layout-based blocks, thinking they were restrictive,
        pedantic, and generally dumb.  Then I started programming in
        Haskell, which allows programmers to define blocks either by
        the use of braces { } or by layout.  To my surprise (and
        chagrin), I discovered that I preferred layout blocks.  Thus I
        hacked together LayoutRule.pm, which brings Haskell-style
        layout blocks to Perl:

            use LayoutRule;

            # old-style blocks can still be used

            while (<>) {
                if ($i++ % 2) {
                    print "odd:  ";
                } else {
                    print "even: ";
                }
                print;
            }

            # same as above, but using layout rule
            # (the syntax {| opens a layout block)

            while (<>) {|
                if ($i++ % 2) {|
                    print "odd:  ";
                else {|
                    print "even: ";
                print;

            # another, more compact version of the above

            while (<>) {|  
                if ($i++ % 2) {|  print "odd:  ";
                else {|           print "even: ";
                print;

            # yet more compact version of the above
            # (you can open more than one block on a line)

            while (<>) {|  if ($i++ % 2) {|  print "odd:  ";
                           else {|           print "even: ";
                           print;

            # layout blocks can be used anywhere you need a block

            my $fnref   = sub {| return "hello, world!";
            my $hashref = {|
                A => 1, B => 2
                C => 3, D => 4
            LINE: {|
                $i++;
                last LINE if $i == 10;

            # you can mix and match old blocks with layout blocks

            while (<>) {
                if (/^FN/) {| print "function";
                if (/^VR/) {| print "variable";
            }

            # fine from the command line, too

            $ perl -MLayoutRule -lne'if ($i++%2) {| print $i'

        In this talk, I'll introduce layout blocks and the layout rule
        and explain my motivation for bringing them to Perl.  Then
        I'll provide some layout block examples and, finally, talk
        about the inner workings of LayoutRule.pm.

Please let me know whether you would be interested in these talks.

Cheers,
Tom





More information about the pgh-pm mailing list