Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.6 / 3....
  • Linux Kernel 3.0.82 LTS...
  • KDE Software Compilatio...
  • PulseAudio 4.0
  • Wireshark 1.10.0
  • NetworkManager 0.9.8.2
  • LibreOffice 3.6.6 / 4.0...
  • SystemRescueCd 3.7.0
  • Linux Kernel 3.10 RC6
  • Ubuntu Tweak 0.8.5
  • Home > Linux > Programming > Libraries

    AI::Prolog::Introduction 0.739

    Download button

    No screenshots available
    Downloads: 511  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Curtis Poe | More programs
    Perl Artistic License / FREE
    July 4th, 2007, 10:05 GMT
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    AI::Prolog::Introduction description

    AI::Prolog::Introduction Perl module contains the what and the why of logic programming.

    AI::Prolog::Introduction Perl module contains the what and the why of logic programming.

    You can skip this if you already know logic programming.

    Note that most of this was pulled from my write-up about logic programming in Perl at http://www.perlmonks.org/?node_id=424075.

    In Perl, generally you can append one list to another with this:

    my @Z = (@X, @Y);

    However, that's telling the language what to do. As sentient beings, we can look at that and infer more information. Given @Z and @X, we could infer @Y. Given just @Z, we could infer all combinations of @X and @Y that can be combined to form @Z.

    Perl cannot do that. In logic programming, however, by defining what append() looks like, we get all of that other information.

    In Prolog, it looks like this:

    append([], X, X).
    append([W|X],Y,[W|Z]) :- append(X,Y,Z).

    (There's actually often something called a "cut" after the first definition, but we'll keep this simple.)

    What the above code says is "appending an empty list to a non-empty list yields the non-empty list." This is a boundary condition. Logic programs frequently require a careful analysis of boundary conditions to avoid infinite loops (similar to how recursive functions in Perl generally should have a terminating condition defined in them.)

    The second line is where the bulk of the work gets done. In Prolog, to identify the head (first element) of a list and its tail (all elements except the first), we use the syntax [head|tail]. Since ":-" is read as "if" in Prolog, what this says if we want to concatenate (a,b,c) and (d,e,f):

    Given a list with a head of W and a tail of X:

    @list1 = qw/a b c/; (qw/a/ is W, the head, and qw/b c/ is X, the tail)

    If it's appended to list Y:

    @Y = qw/d e f/;

    We get a list with a head of W and a tail of Z:

    @list2 = qw/a b c d e f/;

    Only if X appended to Y forms Z:

    X is qw/b c/. Y is qw/d e f/. Z is qw/b c d e f/.

    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    logic programming | prolog introduction | Perl module | AI::Prolog::Introduc | logic | programming

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM