Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Perl and Prolog and Continuations... oh my!

by adrianh (Chancellor)
on Aug 29, 2002 at 03:01 UTC ( #193649=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub foo {
        bar() or die "we failed";
    ...
    };
    
    die "it worked" if foo();
    
  2. or download this
    sub foo {
        my $c = shift;
    ...
    };
    
    foo( sub {die 'it worked'} ) || die "we failed\";
    
  3. or download this
    /* frank and dean are male */
    male(frank).
    ...
    /* frank sang with judy, frank sang with dean */
    sang_with(frank, judy).
    sang_with(frank, dean).
    
  4. or download this
    use Test::More 'no_plan';
    
    ...
    ok(!$v2->bind($v1),            'cannot bind bound var');
    ok( $v1->bind($v2),            'can bind unbound var');
    is( $v1->value, "hello",    '  to correct value');
    
  5. or download this
    use strict;
    use warnings;
    ...
        my $self = shift;
        $$self = \undef;
    };
    
  6. or download this
    sub unify {
        my ($v1, $v2, $continuation) = @_;
    ...
        };
        return(0);
    };
    
  7. or download this
    male(frank).
    male(dean).
    
  8. or download this
    sub male {
        my ($var, $continuation) = @_;
        unify("frank", $var, $continuation);
        unify("dean", $var, $continuation);
    };
    
  9. or download this
    sub male {
        unify("frank", @_);
        unify("dean", @_);
    };
    
  10. or download this
    # print out all the males
    my $a = Var->new;
    ...
    # is dean male
    eval {male("dean", sub {Success->throw})};
    print $@ ? "dean is male" : "dean is not male", "\n";
    
  11. or download this
    
    sub female {
    ...
        my ($var, $continuation) = @_;
        female($var, sub {acts($var, $continuation)});
    };
    
  12. or download this
    # print out all of the actors
    my $c = Var->new;
    ...
    # is ella an actress
    eval {actress("ella", sub {Success->throw})};
    print $@ ? "ella is an actress" : "ella is not an actress", "\n";
    
  13. or download this
    /* frank sang with judy, frank sang with dean */
    sang_with(frank, judy).
    sang_with(frank, dean).
    
  14. or download this
    sub sang_with {
        my ($p1, $p2, $continuation) = @_;    
        unify($p1, 'frank', sub {unify($p2, 'judy', $continuation)});
        unify($p1, 'frank', sub {unify($p2, 'dean', $continuation)});
    };
    
  15. or download this
    sub unify_all {
        my ($a, $b, $continuation) = @_;
    ...
        };
        return(0);
    };
    
  16. or download this
    sub sang_with {
        my ($p1, $p2, $continuation) = @_;
        unify_all(['frank', 'judy'], [$p1, $p2], $continuation);
        unify_all(['frank', 'dean'], [$p1, $p2], $continuation);
    };
    
  17. or download this
    my $x = Var->new;
    eval { 
    ...
        )
    };
    print "frank did sing with an actor\n" if $@;
    
  18. or download this
    my $x = Var->new;
    my $succeed = sub { Success->throw };
    my $sang_with = sub { sang_with("frank", $x, $succeed) };
    eval { actor($x, $sang_with) };
    print "frank did sing with an actor\n" if $@;
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://193649]
Approved by Elian
Front-paged by rinceWind
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2015-07-04 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls