Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

cjf asked, in regards to why not much OO seems to be done in Perl:

Why is this? Is Perl not suited for AI applications? Is it too slow? Is Perl OO programming too messy? Is it because Perl's considered 'just a scripting language' and not meant for serious projects?

Not every problem is approached the same way. If you have a system where the data rapidly changes, object-oriented programming is often a good choice. However, if the data is relatively static but the functionality rapidly changes, then you might find a straight-forward procedural design better than an object-oriented one.

That is to say, not every problem should be approached the same way and just as we acknowledge that Perl is not a great tool for programming device drivers, it's also not the most optimal tool for artificial intelligence. Because AI often involves creating a lot of rules, searching through those rules, backtracking through them (the bane of regexen, remember?), it tends to require a fast programming language to drive it. Consider the little snippet I wrote about thieves. Rather than make you rush off to another link, I'll reproduce it here.


Imagine that I want to know what a given person might steal. I might assume that they will steal stuff given the following conditions:

  • That person is a thief.
  • The stuff is valuable.
  • The stuff is owned by someone (how do you steal something if it's not owned by anyone?).
  • And the person doesn't know the person who owns the stuff they might steal.

If I were programming in Prolog, I might have the following program:

steals(PERP, STUFF) :- thief(PERP), valuable(STUFF), owns(VICTIM,STUFF), not(knows(PERP,VICTIM)). thief(badguy). valuable(gold). valuable(rubies). owns(merlyn,gold). owns(ovid,rubies). knows(badguy,merlyn).

It's fairly easy to read, once you know Prolog. :- is read as "if" and a comma is read as "and" (if outside of parentheses).

I can then ask what a given person might steal:


?- steals(badguy,X).

X = gold

Yes
?- steals(merlyn,X).

No

Now, try to program that in Perl. I've seen Prolog::Alpha, but it needs quite a bit of work, and apparently there is a Language::Prolog::Interpreter, which I know nothing about and couldn't seem to download. Just glancing through their code bases, however, lets you know that this requires a lot of work.

Rather than trying to copy another language, though, how would you write the above program in Perl? Then, just to ensure that you have an extensible solution, try adding a rule the the thief will only steal stuff if he or she knows the stuff exists in a city at least 50 miles from where the thief lives. That's not hard in Prolog.

My point, which I alluded to in the first paragraph, is that some languages are better suited for some problems than others. AI, I suspect, is not Perl's strong suit.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to Who's a thief? by Ovid
in thread Artificial Intelligence Programming in Perl by cjf

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (11)
    As of 2014-10-23 06:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (124 votes), past polls