in reply to list reversal closure

Two immediate thoughts.

  1. Very few languages support lexical closures, so your test excludes many of them.
  2. Your test is a GUOLCAAS. A gratuitous use of lexical closures and anonymous subs--neither is a requirement for performing the function of the code which would be equally achieved by:
    #!/usr/bin/perl -l print for reverse @ARGV;
    • It is no more succinct than the simpler version.
    • It is no more correct than the much simpler version.
    • It is no more understandable than the simpler version.
    • It is no more efficient than the simpler version.
    • It is no more flexible that the simpler version.
    • It is no more reusable than the simpler version.
    • It is no more reliable that the simpler version.

It's also rather limiting to write a filter program that only accepts input from the command line and not via redirection.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: list reversal closure
by apotheon (Deacon) on Aug 21, 2006 at 11:46 UTC

    While I agree with the thesis that appears to be implicit in your post (that only real-world problem solving can provide a truly comprehensive measure of a language's benefits), that's not terribly useful for discussion with "hard" data on hand. As such, I've gone a little closer to the scientific method approach by trying to work with a series of clearly defined, strictly regulated mini-tests that each focus on specific characteristics of languages while minimizing the problem of additional, unnecessary variables. As such, for this particular test, I'm looking for fewer untargeted variables in the test, not more of them.

    This unfortunately tends to result in a test whose conditions appear somewhat arbitrary and extraneous, until one considers the fact that the conditions are sorta the point.

    If, however, you think another approach than using @ARGV would be better, I certainly encourage you to modify my code (or write code from scratch) to improve upon my original, and if you have suggestions for addressing the needs of this little test directly as opposed to attempting to turn it into a real-world problem, I'm open to that as well.

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

      Put more simply, most languages assume the existence of command line arguments in an array, which eliminates the overhead of using the language or system libraries to process input for the test.

      That does treat some languages more fairly, but it's not really reflective of any real world condition. You might as well begin by having the language explicitly set an array or variable with a specified input.

      Side note on the closures bit -- a better, practical closures example is probably some sort of argument currying.

      sub first_n_chars { my $n = shift; return sub { return substr( shift, 0, $n ) }; } my $first_4 = first_n_chars(4); print $first_4->("hello world");

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

        You make some excellent points, and you're right about an argument currying example being perhaps more practical. On the other hand, if I start chasing practicality, I then end up wanting to input data to the closure (both as the closure variable and when calling it) from "somewhere else", which begins to increase the complexity of the example to the point where it distracts from the core intent of the test.

        Maybe I just have a personal problem with setting arbitrary limits rather than following decisions to their logical extremes in a case like this.

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