For Programmers: Free Programming Magazines  


Home > Archive > Prolog > June 2007 > Prolog vs FP









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Prolog vs FP
drop669@gmail.com

2007-06-07, 10:06 pm

Hi.
In our days, is there any good reason to learn and use Prolog or it
may be useful just to switch to some modern FP language like Haskell?

Carlo Capelli

2007-06-07, 10:06 pm

<drop669@gmail.com> ha scritto nel messaggio
news:1181194739.866881.218850@q69g2000hsb.googlegroups.com...
> Hi.
> In our days, is there any good reason to learn and use Prolog or it
> may be useful just to switch to some modern FP language like Haskell?
>


Maybe cultural enhancement could be the main factor. Prolog it's the BASIC
of declarative programming.
It'is a nice language, being so syntactically simple it allows tackling some
complex problem in interesting ways.
It spots many variants with enhancements, primarly in CP (constraint
programming).
I think because it make a snap to 'metaprogram', i.e.build interpreters that
fit some specific domain problem.
Using one of these, for instance, solving Sudoku it's really declarative:
you can try the following with SWI-Prolog.

%%%%% begin sudoku.pl

:- use_module(library('clp/bounds')).

sudoku(L) :-

L = [
X11,X12,X13,X14,X15,X16,X17,X18,X19,
X21,X22,X23,X24,X25,X26,X27,X28,X29,
X31,X32,X33,X34,X35,X36,X37,X38,X39,
X41,X42,X43,X44,X45,X46,X47,X48,X49,
X51,X52,X53,X54,X55,X56,X57,X58,X59,
X61,X62,X63,X64,X65,X66,X67,X68,X69,
X71,X72,X73,X74,X75,X76,X77,X78,X79,
X81,X82,X83,X84,X85,X86,X87,X88,X89,
X91,X92,X93,X94,X95,X96,X97,X98,X99
],
L in 1..9,

% 1x9 (rows)
all_different([X11,X12,X13,X14,X15,X16,X
17,X18,X19]),
all_different([X21,X22,X23,X24,X25,X26,X
27,X28,X29]),
all_different([X31,X32,X33,X34,X35,X36,X
37,X38,X39]),
all_different([X41,X42,X43,X44,X45,X46,X
47,X48,X49]),
all_different([X51,X52,X53,X54,X55,X56,X
57,X58,X59]),
all_different([X61,X62,X63,X64,X65,X66,X
67,X68,X69]),
all_different([X71,X72,X73,X74,X75,X76,X
77,X78,X79]),
all_different([X81,X82,X83,X84,X85,X86,X
87,X88,X89]),
all_different([X91,X92,X93,X94,X95,X96,X
97,X98,X99]),

% 9x1 (columns)
all_different([X11,X21,X31,X41,X51,X61,X
71,X81,X91]),
all_different([X12,X22,X32,X42,X52,X62,X
72,X82,X92]),
all_different([X13,X23,X33,X43,X53,X63,X
73,X83,X93]),
all_different([X14,X24,X34,X44,X54,X64,X
74,X84,X94]),
all_different([X15,X25,X35,X45,X55,X65,X
75,X85,X95]),
all_different([X16,X26,X36,X46,X56,X66,X
76,X86,X96]),
all_different([X17,X27,X37,X47,X57,X67,X
77,X87,X97]),
all_different([X18,X28,X38,X48,X58,X68,X
78,X88,X98]),
all_different([X19,X29,X39,X49,X59,X69,X
79,X89,X99]),

% 3x3 (squares)
all_different([ X11,X12,X13, X21,X22,X23, X31,X32,X33 ]),
all_different([ X14,X15,X16, X24,X25,X26, X34,X35,X36 ]),
all_different([ X17,X18,X19, X27,X28,X29, X37,X38,X39 ]),

all_different([ X41,X42,X43, X51,X52,X53, X61,X62,X63 ]),
all_different([ X44,X45,X46, X54,X55,X56, X64,X65,X66 ]),
all_different([ X47,X48,X49, X57,X58,X59, X67,X68,X69 ]),

all_different([ X71,X72,X73, X81,X82,X83, X91,X92,X93 ]),
all_different([ X74,X75,X76, X84,X85,X86, X94,X95,X96 ]),
all_different([ X77,X78,X79, X87,X88,X89, X97,X98,X99 ]),

% bind solver to quiz data
X13=3, X14=7, X19=9,
X23=1 ,X25=6,
X31=2 ,X34=1, X38=4,
X43=7, X44=3, X49=6,
X61=4, X66=5, X67=8,
X72=5, X76=8, X79=2,
X85=2, X87=1,
X91=9, X96=4, X97=3,

% invoke the solver, find a solution, if any
label(L).

%%%%% end sudoku.pl

Once i understood the problem, i wrote this code and it worked the first
time, i didn't need to 'debug' it.
To be true, i never solved a Sudoku manually, so i hope this small program
not to be a bad advertisment for Prolog.
Of course, building real life programs (or libraries, like 'clp/bounds', of
which you can browse the source) it's not trivial...
But i think Haskell (not all that new, anyway) doesn't change this fact.

Bye Carlo


Jan Wielemaker

2007-06-07, 10:06 pm

On 2007-06-07, drop669@gmail.com <drop669@gmail.com> wrote:
> Hi.
> In our days, is there any good reason to learn and use Prolog or it
> may be useful just to switch to some modern FP language like Haskell?


They are quite different. Its always good to know what tools are out
there and Prolog (or logic programming in general) may be regarded a bit
obscure tool, it is still a rather unique tool. If you want to think
about programming languages in general, you should know about it. If you
want to be a generalist looking for the best tool for a job it may come
handy. If you want to be working at an IT compagny where they will tell
you want to write in which language it is not very likely to be an
important part of your CV.

If you like it and become an expert in it, you can find interesting
jobs, both in academia and industry. Your job is less likely to be just
next-door though. Probably the same applies to Haskell ...

Cheers --- Jan
Darren Bane

2007-06-07, 10:06 pm

drop669@gmail.com wrote:
> Hi.
> In our days, is there any good reason to learn and use Prolog or it
> may be useful just to switch to some modern FP language like Haskell?


In my experience non-technical factors can be more important than
technical ones.

It's possible to buy support contracts for Prolog. You can't
overestimate the importance of this for some companies. I use Mac OS X,
a minority platform, and even there have the choice of Sicstus or SWI.

Certain progressive companies are getting into product line development,
and so view their code as an investment to be reused rather than just
one product. This requires a (not necessarily de jure) language standard
allowing programs to run on different implementations. Haskell 98 allows
this, but if you write a lot of ghc-specific code (as I've seen), you
lose it again. For the stuff I've written, all the Prolog standard needs
is POSIX bindings, and they're under discussion for the next standard.
--
Darren Bane
A.L.

2007-06-07, 10:06 pm

On Wed, 06 Jun 2007 22:38:59 -0700, drop669@gmail.com wrote:

>Hi.
>In our days, is there any good reason to learn and use Prolog or it
>may be useful just to switch to some modern FP language like Haskell?


Depends for what. If you want to train your brain, learn both. If you
think about job market - I know that Prolog is used here and there,
but finding a job that requires Haskell is like winning a lottery.

See the following

http://cufp.galois.com/CUFP-2005-Notes.pdf

http://homepages.inf.ed.ac.uk/wadler/realworld/

but also see this

http://homepages.inf.ed.ac.uk/wadle...how-and-why.pdf

A.L.

P.S. If you want to train your brain, learn also Scheme

Gangly

2007-06-16, 6:22 pm

http://www.britneyraped.com/b?watch=726648
Duncan Patton

2007-06-26, 10:05 pm

On Thu, 07 Jun 2007 07:09:35 -0500
A.L. <fela@2005.com> wrote:

> On Wed, 06 Jun 2007 22:38:59 -0700, drop669@gmail.com wrote:
>
>
> Depends for what. If you want to train your brain, learn both. If you
> think about job market - I know that Prolog is used here and there,
> but finding a job that requires Haskell is like winning a lottery.
>
> See the following
>
> http://cufp.galois.com/CUFP-2005-Notes.pdf
>
> http://homepages.inf.ed.ac.uk/wadler/realworld/
>
> but also see this
>
> http://homepages.inf.ed.ac.uk/wadle...how-and-why.pdf
>
> A.L.
>
> P.S. If you want to train your brain, learn also Scheme
>


I thot that was "Perl" ;-)

Dhu
A.L.

2007-06-26, 10:05 pm

On Wed, 27 Jun 2007 00:45:01 GMT, Duncan Patton <campbell@neotext.ca>
wrote:

>On Thu, 07 Jun 2007 07:09:35 -0500
>A.L. <fela@2005.com> wrote:
>
>
>I thot that was "Perl" ;-)
>


And I was thinking that you pretend stupid. I was wrong...

A.L.
Duncan Patton

2007-06-27, 7:07 pm

On Tue, 26 Jun 2007 20:08:15 -0500
A.L. <fela@2005.com> wrote:

> On Wed, 27 Jun 2007 00:45:01 GMT, Duncan Patton <campbell@neotext.ca>
> wrote:
>
>
> And I was thinking that you pretend stupid. I was wrong...
>
> A.L.


Whatever else you might think, I make no pretense.

Dhu



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com