Grokbase Groups Perl ai March 2005
FAQ
Hi all,

I need some advice. I'm going to be at a conference giving a
presentation about logic programming to a bunch of Perl programmers.
However, after reviewing the notes of my presentation, I've realized
that I have a more daunting task than I realized and I'm beginning to
second-guess my approach. I possibly go in a couple of different
directions.

One approach is to start by showing them the basics of embedding Prolog
in Perl (http://search.cpan.org/dist/AI-Prolog/ and
http://search.cpan.org/dist/Language-Prolog-Yaswi/) and show them
beginning Prolog (family trees, the append function, and maybe a simple
text adventure). The advantage is the programmers get a chance to
understand how to actually use this stuff. This was my initial
approach. However, it's been pointed out to me by several people that
the smaller the example, the more difficult it is to show the strength
of logic programming (the multiple uses of append/3 are cool, but
people want to know how this helps them write purchase order software.)

The other approach is, instead, to give them a tiny taste of *how*
Prolog works and then show a powerful example or two that's difficult
to replicate in an imperative, OO, or functional environment. I've
considered snarfing an example or two from "The Art of Prolog" by
Sterling and Shapiro, but I'm not sure of the legal implications and,
in any event, I don't know if I'd have enough time to really get those
examples across.

My question in a nutshell: given 45 minutes to show a roomful of
programmers with no prior experience in logic programming just how
powerful it can be, what approach would you take? Do you have any
particular sample applications that would be worthwhile? Everything
that I've come up with seems too small to really be more than a toy or
too large to show in 45 minutes.

Cheers,
Ovid

If this message is a response to a question on a mailing list, please send
follow up questions to the list.

Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/

Search Discussions

  • Mark Kvale at Mar 8, 2005 at 8:16 pm
    I would opt for a couple of small examples that are almost self-explanaotry
    and then describe in a high level way a seriously useful Prolog application.
    Folks are not going to be able to pick up complex new constructs in 45
    minutes, so give then simple stuff they feel like they can get their head
    around and then tempt them with power.

    I learned Prolog back in the 80's when it was still a hot language and liked
    it alot. For constraint programming, it truly makes easy problems easy and
    many hard problems possible with a minimum of hassle. More recently, the
    Mercury language seems like a cool declarative approach as well.

    However, I am happy to be a devil's advocate as well :-) Here are some
    aggressive questions you might have to field from folks who have heard of
    Prolog:

    1) Prolog was hot in the 80's but is hardly ever used these days. If it hasn't
    stood the test of time, why should I care?

    2) There are about 20 Prolog compilers out there, all incompatible due to a
    weak language spec. This a recipe for vendor lock-in; how could I make my
    prolog programs last?

    3) Why is Prolog a good match with Perl?

    4) Pretty CS langauages are all well and good, but how do I get real work
    done? Are there Prolog bindings for databases, network and systems
    libraries, graphical toolkits? Is there a decent Prolog IDE?

    -Mark

    On Tuesday 08 March 2005 11:18 am, Ovid wrote:
    Hi all,

    I need some advice. I'm going to be at a conference giving a
    presentation about logic programming to a bunch of Perl programmers.
    However, after reviewing the notes of my presentation, I've realized
    that I have a more daunting task than I realized and I'm beginning to
    second-guess my approach. I possibly go in a couple of different
    directions.

    One approach is to start by showing them the basics of embedding Prolog
    in Perl (http://search.cpan.org/dist/AI-Prolog/ and
    http://search.cpan.org/dist/Language-Prolog-Yaswi/) and show them
    beginning Prolog (family trees, the append function, and maybe a simple
    text adventure). The advantage is the programmers get a chance to
    understand how to actually use this stuff. This was my initial
    approach. However, it's been pointed out to me by several people that
    the smaller the example, the more difficult it is to show the strength
    of logic programming (the multiple uses of append/3 are cool, but
    people want to know how this helps them write purchase order software.)

    The other approach is, instead, to give them a tiny taste of *how*
    Prolog works and then show a powerful example or two that's difficult
    to replicate in an imperative, OO, or functional environment. I've
    considered snarfing an example or two from "The Art of Prolog" by
    Sterling and Shapiro, but I'm not sure of the legal implications and,
    in any event, I don't know if I'd have enough time to really get those
    examples across.

    My question in a nutshell: given 45 minutes to show a roomful of
    programmers with no prior experience in logic programming just how
    powerful it can be, what approach would you take? Do you have any
    particular sample applications that would be worthwhile? Everything
    that I've come up with seems too small to really be more than a toy or
    too large to show in 45 minutes.

    Cheers,
    Ovid

    If this message is a response to a question on a mailing list, please send
    follow up questions to the list.

    Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/
  • Mark Rogaski at Mar 8, 2005 at 8:29 pm
    An entity claiming to be Ovid (publiustemp-perlai@yahoo.com) wrote:
    :
    : My question in a nutshell: given 45 minutes to show a roomful of
    : programmers with no prior experience in logic programming just how
    : powerful it can be, what approach would you take? Do you have any
    : particular sample applications that would be worthwhile? Everything
    : that I've come up with seems too small to really be more than a toy or
    : too large to show in 45 minutes.
    :

    I guess the first question is what sort of applications does the audience
    find useful? If there are large examples that you think would raise
    interest but are too big, just simplify the task or concentrate on some
    representative section. For instance, the example of a compiler written in
    Prolog impressed me but it would take too much time to cover. Simply
    constructing Prolog code to convert RPN expressions to Perl code might
    work.

    And, I'd make sure that the example allows you demonstrate cuts ... they're
    a bit alien to procedural programmers.

    Mark


    --
    [] |
    [] Mark Rogaski | Nothing spells caveat emptor like a mannequin
    [] wendigo@pobox.com | with a severed head.
    [] mrogaski@cpan.org | -- Brooke McEldowney, _9 Chickweed Lane_
    [] |
  • Ovid at Mar 8, 2005 at 8:47 pm

    --- Mark Kvale wrote:
    I would opt for a couple of small examples that are almost
    self-explanaotry
    and then describe in a high level way a seriously useful Prolog
    application.
    Sounds workable.
    However, I am happy to be a devil's advocate as well :-) Here are
    some
    aggressive questions you might have to field from folks who have
    heard of
    Prolog:
    Wonderful idea! Thanks. Let me know if you think I'm goofing any of
    these.

    Preface: I'd like to show programmers how to use Prolog from their
    Perl programs, not just how to use Prolog.
    1) Prolog was hot in the 80's but is hardly ever used these days. If
    it hasn't stood the test of time, why should I care?
    Prolog has traditionally been viewed as rather slow and, due to the
    nature of its design, debugging is sometimes a painful experience.
    Further, because so many programmes are weaned on imperative or OO
    languages, Prolog just seems "foreign". Building large applications
    can be cumbersome, as a result of these factors.

    I argue that programmers should use Perl for the bulk of the work and
    use Prolog for those portions of the application where a rule-based
    approach is clearly merited, or where data is heavily relational in
    nature. Thus, they can leverage the strengths of logic programming
    only when it's cleary a good choice.
    2) There are about 20 Prolog compilers out there, all incompatible
    due to a
    weak language spec. This a recipe for vendor lock-in; how could I
    make my
    prolog programs last?
    Hopefully, my long-term goal is to port the bulk of AI::Prolog to C and
    write a "sugar" wrapper that allows someone to write logic programs in
    Perl. Eventually, I might consider a WAM (Warren Abstract Machine) in
    Parrot. I'd like to avoid the external dependencies. However, for the
    time being, if you can figure out Language::Prolog::Yaswi, it's a good
    choice, though it does require SWI-Prolog.
    3) Why is Prolog a good match with Perl?
    Perl can already handle functional, OO, and imperative progamming.
    However, if a declarative approach is merited, it's rather tough to
    pull that off in Perl. I'd like to solve that.
    4) Pretty CS langauages are all well and good, but how do I get real
    work
    done? Are there Prolog bindings for databases, network and systems
    libraries, graphical toolkits? Is there a decent Prolog IDE?
    I would argue that most of that should be done in Perl and let the
    Prolog layer handle only those bits that Perl is not well suited for.

    Cheers,
    Ovid

    If this message is a response to a question on a mailing list, please send
    follow up questions to the list.

    Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/
  • Mark Kvale at Mar 9, 2005 at 3:41 am

    On Tuesday 08 March 2005 12:46 pm, Ovid wrote:
    --- Mark Kvale wrote:
    I would opt for a couple of small examples that are almost
    self-explanaotry
    and then describe in a high level way a seriously useful Prolog
    application.
    Sounds workable.
    However, I am happy to be a devil's advocate as well :-) Here are
    some
    aggressive questions you might have to field from folks who have
    heard of
    Prolog:
    Wonderful idea! Thanks. Let me know if you think I'm goofing any of
    these.

    Preface: I'd like to show programmers how to use Prolog from their
    Perl programs, not just how to use Prolog.
    1) Prolog was hot in the 80's but is hardly ever used these days. If
    it hasn't stood the test of time, why should I care?
    Prolog has traditionally been viewed as rather slow and, due to the
    nature of its design, debugging is sometimes a painful experience.
    Further, because so many programmes are weaned on imperative or OO
    languages, Prolog just seems "foreign". Building large applications
    can be cumbersome, as a result of these factors.

    I argue that programmers should use Perl for the bulk of the work and
    use Prolog for those portions of the application where a rule-based
    approach is clearly merited, or where data is heavily relational in
    nature. Thus, they can leverage the strengths of logic programming
    only when it's cleary a good choice.
    2) There are about 20 Prolog compilers out there, all incompatible
    due to a
    weak language spec. This a recipe for vendor lock-in; how could I
    make my
    prolog programs last?
    Hopefully, my long-term goal is to port the bulk of AI::Prolog to C and
    write a "sugar" wrapper that allows someone to write logic programs in
    Perl. Eventually, I might consider a WAM (Warren Abstract Machine) in
    Parrot. I'd like to avoid the external dependencies. However, for the
    time being, if you can figure out Language::Prolog::Yaswi, it's a good
    choice, though it does require SWI-Prolog.
    3) Why is Prolog a good match with Perl?
    Perl can already handle functional, OO, and imperative progamming.
    However, if a declarative approach is merited, it's rather tough to
    pull that off in Perl. I'd like to solve that.
    4) Pretty CS langauages are all well and good, but how do I get real
    work
    done? Are there Prolog bindings for databases, network and systems
    libraries, graphical toolkits? Is there a decent Prolog IDE?
    I would argue that most of that should be done in Perl and let the
    Prolog layer handle only those bits that Perl is not well suited for.

    Cheers,
    Ovid
    Those all sound like reasonble replies. Even people who are wary of Prolog for
    general use might be amenable to using it as a special purpose logic engine.

    Good luck with the talk,
    Mark
  • Adrian Howard at Mar 13, 2005 at 12:51 am

    On 8 Mar 2005, at 20:46, Ovid wrote:
    --- Mark Kvale wrote:
    [snip]
    1) Prolog was hot in the 80's but is hardly ever used these days. If
    it hasn't stood the test of time, why should I care?
    Prolog has traditionally been viewed as rather slow and, due to the
    nature of its design, debugging is sometimes a painful experience.
    Further, because so many programmes are weaned on imperative or OO
    languages, Prolog just seems "foreign". Building large applications
    can be cumbersome, as a result of these factors.
    [snip]

    I think another reason Prolog didn't catch on is that it got a bad rap
    as an "AI" language (along with Lisp and, to a lesser extent,
    Smalltalk) and suffered in the post-hype AI winter of the late eighties
    / early nineties.

    It's also a far bigger leap in style. If you're used to procedural
    programming you can carry on writing procedural code in most OO
    languages (indeed a depressing number of people do just that in my
    experience :-) With Prolog, and similar languages, you've got to jump
    in with both feet.

    Cheers,

    Adrian
  • Adrian Howard at Mar 12, 2005 at 7:18 pm
    On 8 Mar 2005, at 19:18, Ovid wrote:
    [snip]
    My question in a nutshell: given 45 minutes to show a roomful of
    programmers with no prior experience in logic programming just how
    powerful it can be, what approach would you take?
    [snip]

    I've used this little example to impress people (shamelessly stolen
    from <http://www.ainewsletter.com/newsletters/aix_0305.htm>.)

    Start off with

    member( X, [ X | _ ] ).
    member( X, [ _ | Z ] ) :- member( X, Z ).

    which is enough to demonstrate the declarative and generative stuff you
    can get out of simple statements, then hit them with:

    send( Object, Message ) :-
    class( Object, methods( Methods ) ),
    member( ( Message :- Method ), Methods ),
    call( Method ).

    class(
    rectangle( H, W ),
    methods( [
    ( area(A) :- A is H * W ),
    ( perimeter(P) :- P is 2 * (H + W) )
    ] )
    ).

    class(
    circle(R),
    methods( [
    ( area(A) :- A is pi * R * R ),
    ( perimeter(P) :- 2 * pi * R )
    ] )
    ).

    allowing us to do:

    ?- send( circle(1), area(A) ).
    A = 3.14159

    Implementing a basic OO system in 6 lines of code is kinda neat :-)

    Cheers,

    Adrian

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupai @
categoriesperl
postedMar 8, '05 at 7:18p
activeMar 13, '05 at 12:51a
posts7
users4
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase