Quote:

> I am free to ask for help in Prolog programming...

> I need a prolog program which in given sorted list search for element of

> that list, using binary search method ...

> Can somebody help me?

> Thank you in advance...

/*

Prolog is language and language is a vehicle of the imagination, so I

suggest you use your imagination.

What you do when you look up an author's name in the card catalog at

the library?

Suppose L is a stricty ordered list and suppose

divide(L,FrontHalf,BackHalf)

is true if and only if FrontHalf is the front half of list L and

BackHalf is the back half of L, where for the sake of specificity we

will arbitrarily stipulate that FrontHalf and BackHalf either have equal

lengths or else the length of BackHalf is one greater than the length of

FrontHalf.

Then

*/

lookup(X,L) :-

write('L='),write(L),nl,

divide(L,FrontHalf,BackHalf),

check_against(X,FrontHalf,BackHalf).

/*

where

*/

check_against(X,FrontHalf,[Y|RestOfBackHalf]) :-

X < Y ...

check_against(X,FrontHalf,[Y|RestOfBackHalf]) :-

X = Y ...

check_against(X,FrontHalf,[Y|RestOfBackHalf]) :-

X > Y ...

etc.

It's really quite extraordinary how this works,

but the power of Prolog comes from the power of language,

not the other way around.

--

"You do know how to whistle, don't you, Steve?"