I've come up with an interlanguage comparison test based on a suggestion from someone else. The idea is, simply, to examine a fairly arbitrary set of metrics for three characteristics of a language: expressiveness, power, and flexibility. The metrics are, of course: succinctness as measured in distinct syntactic elements, list handling, and use of data in a largely arbitrary manner.

Requirements for the code to be at all meaningful for the test include readability, understandability for someone new to the language with only a brief explanation at most, and "correct" idiomatic style for the language.

My initial thought is to define the test as requiring input when calling the program and output without further interaction with the user (in other words, acting as a "filter"), doing something meaningful between input and output in a manner that maximizes demonstration of power and flexibility in a relatively simple operation. Toward that end, I figure a good test is a program that sends the input into a lexical closure, which operates on that data and sends it to STDOUT (with linebreaks) when it is called.

My question, then, is twofold. First, what (if anything) is a better option than the above test (and why)? Second, for the above described test, is there a better Perl example than the one below?

#!/usr/bin/perl -l sub foo { my @list = @_; sub { print for reverse @list }; } my $bar = foo(@ARGV); $bar->();

print substr("Just another Perl hacker", 0, -2);
- apotheon
CopyWrite Chad Perrin


In reply to list reversal closure by apotheon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.