Acme::ComeFrom - Parallel goto-in-reverse
use Acme::ComeFrom; sub func { print "@_" }; func("start\n"); print "won't happen\n"; comefrom &func; print "branch 1\n"; exit; comefrom &func; print "branch 2\n"; label: print "won't happen either\n"; comefrom label; print "branch 2.1\n"; exit; comefrom label; print "branch 2.2\n"; expr0: print "to be\n"; exit; comefrom "expr".int(rand(2)); print "not to be\n";
INTERCAL programmers have been for a long time monopolized the enormously powerful construct COME FROM, both as a flow-control replacement to goto, as well as an obvious way to mark parallel execution branches.
COME FROM
goto
But now, with Acme::ComeFrom, perl hackers finally could match them on the front of wackiness, if not of obfuscation.
Just like goto, comefrom comes in three different flavors:
comefrom
The comefrom-LABEL form finds the statement labeled with LABEL and jumps to the comefrom just before that statement's execution. The comefrom may not be within any construct that requires initialization, such as a subroutine or a foreach loop.
comefrom-LABEL
foreach
The comefrom-EXPR form expects a label name, whose scope will be resolved dynamically. This allows for computed comefroms by checking the EXPR before every labels (a.k.a. watchpoints), so you could write ($i evaluates in the LABEL's scope):
comefrom-EXPR
EXPR
goto ("FOO", "BAR", "GLARCH")[$i];
Please note that the value of EXPR is frozen the first time it is checked. This behaviour might change in the future.
The comefrom-&NAME form is quite different from the other forms of comefrom. In fact, it isn't a comefrom in the normal sense at all, and doesn't have the stigma associated with other comefroms. Instead, it installs a post-processing handler for the subroutine, so a jump is made just after the subroutine's execution.
comefrom-&NAME
If two or more comefrom applies to the same LABEL, EXPR or NAME, they will be executed simultaneously via fork(). The parent process will receive the latest installed comefrom.
fork()
To numerous to be counted. This is only a prototype version.
To the INTERCAL language, the endless inspiration. As its manual said: "The earliest known description of the COME FROM statement in the computing literature is in [R. L. Clark, "A linguistic contribution to GOTO-less programming," Commun. ACM 27 (1984), pp. 349-350], part of the famous April Fools issue of CACM. The subsequent rush by language designers to include the statement in their languages was underwhelming, one might even say nonexistent. It was therefore decided that COME FROM would be an appropriate addition to C-INTERCAL."
To Maestro Damian Conway, the source of all magic bits in the Hook::LexWrap and Filter::Simple modules, on which this module is based.
To Ton Hospel, for his tolerance on my semantic hackeries, and suggesting the correct semantic of comefrom-LABEL and comefrom-EXPR.
Autrijus Tang <autrijus@autrijus.org>
Copyright 2001 by Autrijus Tang <autrijus@autrijus.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
To install Acme::ComeFrom, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Acme::ComeFrom
CPAN shell
perl -MCPAN -e shell install Acme::ComeFrom
For more information on module installation, please visit the detailed CPAN module installation guide.