in reply to Re: An Unreal Perl Hacker!
in thread An Unreal Perl Hacker!

Well, something more than Eliza/Doctor, but something less than ST/TNG Data. :)

I see it as a big challenge, yes. Just parsing the code fragments, let alone the English, would be daunting.

Okay, here's a limited subset that I think might be do-able.
  1. Ignore anything outside of <c> </c> or <code> </code> tags
  2. ignore anything that uses modules
  3. ignore anything that writes the filesystem
  4. ignore anything that uses filehandles other than STD*
  5. eval perl code
  6. ponder error message and/or output
  7. look through k-base for similar code structures and error messages
  8. suggest a list of nodes with code similar to the code near the failure that might work
Eventually, I'd like it to do more, and to be allowed to post its own responses to real nodes, but that would be a long way away. This limited subset would allow us to experiment with parsing, pattern recognition, and k-base building, and I believe it could be made to have real utility, at least for the newbie errors.

UPDATE: added exclusions #3 and #4

Replies are listed 'Best First'.
Re^3: An Unreal Perl Hacker!
by GrandFather (Saint) on Oct 13, 2005 at 19:28 UTC

    I hate to be a nay sayer, but if you follow exclusions 2, 3 and 4 you likely cut out about 75% of the material posted. Many of the best contributions are best exactly because they do use a module to get work done.

    Likely the best code discoverd by such a system will be the system's own code! Bet modules are used to write it though.

    In any case, best of luck with it. It's a neat idea, but I suspect pretty tricky to realise.


    Perl is Huffman encoded by design.
      That's why I'm drastically limiting its initial functionality spec, GrandFather. I would like to see something that might work, first. Of course I'd like to be able to include modules, and read/write, and everything else, but the problem space explosion would make it completely un-doable. Just building an expression modeller that would handle a limited subset of Perl imperative and declarative code would be a non-trivial undertaking, and, of course, I expect that we will use modules in its execution. How much code is there in your Ook! interpreter??? This is a much bigger problem domain, even if we also throw out ReGex and things like that. My SPICE equation parser was 26 pages of code, no modules, and that was pretty trivial compared to this. Even if we just handle loops, conditionals, assignments and things like that, it's a big set of possible patterns.
Re^3: An Unreal Perl Hacker!
by Sandy (Curate) on Oct 13, 2005 at 22:11 UTC
    Regarding #6
    6. ponder error message and/or output

    how would the ai (or perl program) even know if the output is what the user wanted or required.

    More than half the time, my problems stem from an incorrect algorithm, or misunderstanding of the intracies of Perl. However, my output usually looks quite agreeable, without any hint of malice.

    Sandy

      That's why I've reduced the earlier spec to only include 'does it run', not 'does it run correctly'. :) I still think that a critter that can help with simple coding errors would be a Good Thing. As has been pointed out, it's still a heck of a challenge.
Re^3: An Unreal Perl Hacker!
by pajout (Curate) on Oct 14, 2005 at 08:14 UTC
    Thanks, I am more enlightened :0). But I cannot imagine the typical (and ideal) case of use. Can you, please, describe user's goal, user's input, what happens in the guts, and output?
      Sure. Suppose noob comes up to his screen with a program that isn't working right:
      #!/usr/bin/perl for ($i=0,$i<=5,$i++) { print "FOO\n"; }
      which prints:
      FOO FOO FOO
      no matter what he does. (classic newbie mistake that used to bug me when I was doing C :) He checks a box that says "output is incorrect."

      Our critter will extract the for() loop from his code, and wrap it in :
      eval { for (i=0,$i<=5,$i++) { print "FOO\n"; } }; print "'$@'";
      This tells our critter that the code did execute. It's next step is to examine node replies for similar code fragments. Pretty soon (!), it discovers that a for() loop should have ';' instead of ',' as iterator separators, and hands back the code:
      #!/usr/bin/perl for ($i=0;$i<=5;$i++) { print "FOO\n"; }
      A further refinement would have it make a scope declaration pass, and hand back:
      #!/usr/bin/perl use strict; use warnings; for (my $i=0;$i<=5;$i++) { print "FOO\n"; }
        Thanks for reply, good idea, I keep it in mind for my week-end contemplations :) Specially, how much complicated code could be (succesively) processed by this way, and, if this can be effective with a small set of categorized context (
        my $current_context = ['syntax error','unexpected warning','unexpected + output','neverending loop'];
        )