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->();
|
- apotheon
CopyWrite Chad Perrin |
In reply to list reversal closure by apotheon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |