in reply to Re^2: list reversal closure
in thread list reversal closure

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.

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

    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