| Next | You can't get there from here | 36 |
sub halts {
my ($source_code, $input) = @_;
my $newcode = q{sub { my $n = shift;
my $f = eval "CODE";
$f->("INPUT");
return $n * $n;
}};
$newcode =~ s/CODE/$source_code/;
$newcode =~ s/INPUT/$input/;
return calculates_squares($newcode);
}
But there's nothing really special about calculating squares
For example, we can't recognize whether a function will call die:
sub halts {
my ($source_code, $input) = @_;
my $newcode = q{sub { my $f = eval "CODE";
eval { $f->("INPUT"); }
die "BOOGA BOOGA!";
}};
$newcode =~ s/CODE/$source_code/;
$newcode =~ s/INPUT/$input/;
return dies($newcode);
}
$newcode dies only if the call $f->("...") will halt
| Next | ![]() |
Copyright © 2005 M. J. Dominus |