Damian Conway wrote:

matt diephouse wrote:

    $junction = $x | $y | $z;
    foo($junction);            # Call foo($x), foo($y), and foo($z)
                               # in parallel and collect the results
                                   # in a disjunction


Looking at that code, I'm wondering how you pass a junction. Suppose I want to pass a junction to a subroutine instead of calling the sub with each value of the junction... how would I do that?

Tell the sub that it's expecting an undistributed junction as its argument:

sub foo($param is junction) {...}

Damian
Doesn't that go against perl's dynamic philosophy? That requires me to type my methods where I may not want to. Let's say I have a sub that logs errors:

sub log_error($fh, $error) { # filehandle and error msg
$error_num++; # global
print $fh: "$error_num: $error\n";
}
my $file = open "error.log";
log_error $file, "This message is phony";

However, during my debugging, I realize that I need two error logs (Don't ask me why, I just do). Instead of changing the one line to

my $file = open "error.log" & "../some/other.log"; # I hope this is legal

I also need to change the subroutine now, because the error count will be off, even though my change is temporary. It reduces the ability to write subs that accept anything and DWIM. The question is when/how do you choose whether to pass a junction or evaluate all of them. I think that the solution would be best left out of the sub's signature though. Of course this has to stop somewhere; you eventually have to pick a state.

m:att d:iephouse

Reply via email to