Dear Monks,

for reasons that are far beyond the scope of this node (and far beyond my english abilities to explain), I feel that there is a functionality missing, that'd bring qualitative advantage for coding a certain class of problems: Cheating God(s of computer science). :-)

I will try to give a very rough overview of my thoughts and would be very happy if some of you would find this problem worthy for a meditation.

Gödel's Undecidability Theorem (see here for a short introduction) - for some a very very theoretical thing - can be applied to some very real programming problems one can encounter with Perl: the standard halting problem for Turing machines

Let's say, you have some code given. Untested by you (or others), unknown to you. Probably all you know is, that it runs. You - however - don't know how long it will take to run. It may very well be, that it will run into an endless loop. The aforementioned Theorem by Gödel and the mathematical proof of the standard halting problem by Turing brought R. PENROSE to the conclusion, that machines will always lack a "functionality" people have: a machine cannot decide if a problem has a solution or not therefore it may stick for infinite time on computing a solution for an unsolvable problem 'till hell freezes.

This is exactly where Perl comes in. Hard things are possible and impossible things are just hard. Let's say you'd have something like that:

sub cheatemall { my $givetime = shift; &InitMagicWatchdog($givetime,"Y"); # ... Do wild computations # ... If successfully computed return X # ... Return Y if computation ends, but the result is "false" }
Let's forget for a moment about this MagicWatchdog thingie. The Wild computation is just an regexp searching for a string. If it finds it, cheatemall returns X, if it doesn't find it, Y is returned.

Now: We give the MagicWatchdog - say - 5 seconds. If everything what comes after the InitMagicWatchdog needs more than 5 seconds until the sub is exited, well - then a magic Watchdog exits the cheatemall sub with a return value of "Y".

Shouldn't be too hard to implement? Thought so. But the magic Watchdog has to be some kind of supervision to the whole Perl program, because it has to exit cheatemall with return value Y even if the program is currently in some other subroutine (which was called doing the wild computetions).

And finally - my brave monks - my brain completedly lost track what should happen if cheatemall calls recursively itself. Then - hapily - I found it again: The subroutine calling cheatemall has to simply init its own MagicWatchdog. So yes, it should be possible to have these Magic Watchdogs spread across the whole source.

What do you say? Could one enhance Perl, so that it'd provide this functionality? I searched but only found these (seem not related):

Probably a Watchdog::Eval?

I'm excited about your input.

Bye
 PetaMem


In reply to Builtin Watchdog for a sub (or block) by PetaMem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.