Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-04-18 12:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found