For Programmers: Free Programming Magazines  


Home > Archive > Prolog > September 2007 > Newbie - trouble w/ example









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 Newbie - trouble w/ example
gad

2007-09-08, 7:06 pm

Hello. I found the following example program on Wikipedia, and I've been
trying to get it to work under GNU Prolog with no success. The first
problem was the "Digits :: [0..9]" statement; I got around that by using
"Digits#<10" instead, but I'm not sure that's right.

The next total-newbie question is "how do I run this thing"? Attempts to
call it either result in "no" answers or the equivalent of "undefined
identifier".

I'm going to try it under SWI instead, since others here seem to like that
system, but I'm really curious as to how to make this work under GNU.

Thanks!
Glenn

sendmore(Digits) :-
Digits = [S,E,N,D,M,O,R,Y], % Create variables
Digits :: [0..9], % Associate domains to variables
S #\= 0, % Constraint: S must be different from 0
M #\= 0,
alldifferent(Digits), % all the elements must take different
values
1000*S + 100*E + 10*N + D % Other constraints
+ 1000*M + 100*O + 10*R + E
#= 10000*M + 1000*O + 100*N + 10*E + Y,
labeling(Digits). % Start the search


gad

2007-09-08, 7:06 pm


"gad" <nospam@spamless.com> wrote in message
news:46e2e5b2$0$17119$4c368faf@roadrunne
r.com...
> Hello. I found the following example program on Wikipedia, and I've been
> trying to get it to work under GNU Prolog with no success. The first
> problem was the "Digits :: [0..9]" statement; I got around that by using
> "Digits#<10" instead, but I'm not sure that's right.
>
> The next total-newbie question is "how do I run this thing"? Attempts to
> call it either result in "no" answers or the equivalent of "undefined
> identifier".
>
> I'm going to try it under SWI instead, since others here seem to like that
> system, but I'm really curious as to how to make this work under GNU.
>
> Thanks!
> Glenn
>
> sendmore(Digits) :-
> Digits = [S,E,N,D,M,O,R,Y], % Create variables
> Digits :: [0..9], % Associate domains to variables
> S #\= 0, % Constraint: S must be different from 0
> M #\= 0,
> alldifferent(Digits), % all the elements must take different
> values
> 1000*S + 100*E + 10*N + D % Other constraints
> + 1000*M + 100*O + 10*R + E
> #= 10000*M + 1000*O + 100*N + 10*E + Y,
> labeling(Digits). % Start the search
>
>

Update...I tried SWI and it chokes on the same statement. I have no idea
which compiler this example is supposed to work with - Visual Prolog chokes
as well.

ERROR: c:/documents and settings/glenn/my documents/prolog/sendmore.pl:3:10:
Syntax error: Operator expected


Cesar Rabak

2007-09-08, 7:06 pm

gad escreveu:
> Hello. I found the following example program on Wikipedia, and I've been
> trying to get it to work under GNU Prolog with no success.


Two things:

1) Read carefully the remark in the wikipedia page: "The syntax for
expressing constraints over finite domains depends on the host language."

2) Look at the example "send.pl' in the ExamplesFD directory of your GNU
Prolog installation in order to see the specifics of syntax for the FD
solver.

HTH

--
Cesar Rabak
gad

2007-09-08, 10:09 pm


"Cesar Rabak" <csrabak@yahoo.com.br> wrote in message
news:fbvci5$qsq$1@aioe.org...
> gad escreveu:
>
> Two things:
>
> 1) Read carefully the remark in the wikipedia page: "The syntax for
> expressing constraints over finite domains depends on the host language."
>
> 2) Look at the example "send.pl' in the ExamplesFD directory of your GNU
> Prolog installation in order to see the specifics of syntax for the FD
> solver.
>
> HTH
>
> --
> Cesar Rabak


Very good - thank you.

Just a point of curiosity - any idea what Prolog implementation the example
would work under, unmodified? I did see the comment you mention above but
after trying three popular implementations with no luck I decided I'd better
ask someone.


pineapple.link@yahoo.com

2007-09-09, 8:05 am

You know that this is not "pure" prolog, right? This is CLP stuff
(constraint logic programming) - a non-standardized sort of "add-on"
to prolog.

If you already know this and just wanted to try the CLP example -
great. But if you didn't know this and just wanted to try out prolog,
I'd suggest a non-CLP program. For one thing, it will actually be
prolog. For another thing, you should have less problems getting it
to work.

Chip Eastham

2007-09-09, 7:09 pm

On Sep 8, 8:52 pm, "gad" <nos...@spamless.com> wrote:
> "Cesar Rabak" <csra...@yahoo.com.br> wrote in message
>
> news:fbvci5$qsq$1@aioe.org...
>
>
>
>
>
>
>
>
>
> Very good - thank you.
>
> Just a point of curiosity - any idea what Prolog implementation the example
> would work under, unmodified? I did see the comment you mention above but
> after trying three popular implementations with no luck I decided I'd better
> ask someone.


You did not provide the subject/title of the Wikipedia
article or a URL. At a glance it appears you read
the article, not on Prolog per se, but on Constraint
Programming.

See here for a pure Prolog solution and three more, of
which the last (in ECLiPSe) most closely resembles the
code you quoted:

[An Example: SEND + MORE = MONEY]
http://www.clip.dia.fi.upm.es/~voca...tes/node13.html

The SEND + MORE = MONEY problem is also used as illustration
in these articles:

[The Ciao Prolog System -- Constraint Programming over Finite Domains]
http://www.clip.dia.fi.upm.es/Softw...l/ciao_189.html

[SICStus Prolog -- Constraint Logic Programming over Finite Domains]
http://www.sics.se/sicstus/docs/3.7...sicstus_33.html

regards, chip

Joachim Schimpf

2007-09-09, 7:09 pm

gad wrote:
> ...
> Just a point of curiosity - any idea what Prolog implementation the example
> would work under, unmodified?


It is lacking a :-lib(fd) or :-lib(ic) directive to load the
necessary constraint solver, but otherwise it runs under ECLiPSe
(www.eclipse-clp.org). The syntax was first used in CHIP.

-- Joachim
gad

2007-09-09, 10:06 pm


"Joachim Schimpf" <jschimpf@cisco.com> wrote in message
news:1189356776.512733@sj-nntpcache-2.cisco.com...
> gad wrote:
>
> It is lacking a :-lib(fd) or :-lib(ic) directive to load the
> necessary constraint solver, but otherwise it runs under ECLiPSe
> (www.eclipse-clp.org). The syntax was first used in CHIP.
>
> -- Joachim


Thanks very much to everyone for all the kind responses.

It has been many years since I played with Turbo Prolog, but I found the new
(to me) constraint logic programming ideas very interesting, so I attempted
to dust off my old knowledge and give this a try. As always, more of a
learning experience than I originally anticpated, but that's a good thing.

Chip, the article I started with is:
http://en.wikipedia.org/wiki/Constraint_programming


Sponsored Links







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

Copyright 2008 codecomments.com