So now it's trivial to find out if "marcus" is an average taxpayer (no) or if mary is (yes). You'd have to write a bit more Perl code than I would have to write Prolog code.
Actually, you don't. It translates pretty straightforward:
$foreigner{abdul} = 1; $foreigner{marcus} = 1; $spouse{edward} = "sally"; $spouse{sally} = "edward"; $spouse{bill} = "hillary"; $spouse{hillary} = "bill"; $gross_income{hillary} = 100_000; $gross_income{edward} = 20_000; $gross_income{bill} = 30_000; $gross_income{marcus} = 49_999; $gross_income{mary} = 35_000; sub average_taxpayer {my $Person = @_ ? shift : $_; !$foreigner{$Person} and not ($spouse = $spouse{$Person} and $income1 = $gross_income{$spouse} and $income1 > 30_000) and $income2 = $gross_income{$Person} and $income2 < 50_000 }
You might want to declare some variables to make it strict (that would be extra code). About the only extra code the Perl part has is 2 extra spouse declarations, as hashes aren't symmetric. How does Prolog know that the "spouse" relationship is symmetric?
However, this is the kicker. What if I want a list of all average taxpayers? Well, I know you have to have a gross income to be an average tax payer, so I issue the following query:
And in Perl:
@avg_taxpayers = grep {average_taxpayer} keys %gross_income;
Now, I know about logic coding, and I'm aware of its merits. No need to convice me. But you've to come with a better example to show you need less code.

In reply to Re^7: (why to use logic programming) by Anonymous Monk
in thread Easy Text Adventures in Perl by Ovid

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.