Цитатник канала #FreeBSD

Цитаты в формате fortune
Всего цитат: 4034
Цитат в очереди: 8



5548
7
Approved by nuclight 2010-07-02 20:08:31
The interesting thing about "&" is that you can generate new syntax
with it, provided it's in the initial position:

sub try (&@) {
    my($try,$catch) = @_;
    eval { &$try };
    if ($@) {
        local $_ = $@;
        &$catch;
    }
}
sub catch (&) { $_[0] }

try {
    die "phooey";
} catch {
    /phooey/ and print "unphooey\n";
};

That prints "unphooey". (Yes, there are still unresolved issues having
to do with visibility of @_. I'm ignoring that question for the
moment. (But note that if we make @_ lexically scoped, those anonymous
subroutines can act like closures... (Gee, is this sounding a little
Lispish? (Never mind.))))