1. Prolog

There are a number of PD DOS versions of Prolog floating around, but
Turbo-Prolog is not one of them. The product was purchased from Borland, and
last I checked (about 3 years ago) was still a commerical product.

Amzi has a PD version of Prolog that runs under windows at:

    www.amzi.com

I did quite a bit of hacking in Prolog - it's a very cool language. I've
been tempted to write a Prolog-style unification engine, but never had a
project that needed it. Euphoria would be ideal an ideal language to code it
in.

-- David Cuny

new topic     » topic index » view message » categorize

2. Re: Prolog

OK -- dumb question... What is a "unification engine" ?

>I did quite a bit of hacking in Prolog - it's a very cool language. I've
>been tempted to write a Prolog-style unification engine, but never had a
>project that needed it. Euphoria would be ideal an ideal language to code
it
>in.
>
>-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

3. Re: Prolog

Irv wrote:

>Maybe, but first look at the code to reverse a list
> ...
>reverse([],[]).
>reverse([X|Y],Z):-
>        reverse(Y,Y1), append(Y1,[X],Z),
>append([],X,X).
>append([X|Y],Z,[X|W]):-
>        append(Y,Z,W).

I agree that the inner working of Euphoria are a bit off-topic, and I don't
intend to carry this on past this post. But I'd like to encourage someone
into considering building a Prolog engine in Euphoria - and the only way
they will do that is to look at Prolog first.

Like any other programming tool, there are some things that you can easily
do in Prolog that are difficult in any other language. If you don't need a
particular tool, you often look at it and say "why would you use something
that funky?" But when it's *just* the tool you need, you're glad you've got
it.

Typically, you don't get "pure" Prolog applications. Instead, the AI portion
(say, and expert system) is coded in Prolog, and the user interface is in
C++.  So I don't see any problem with suggesting that a Prolog module
(written in Euphoria) attached to Euphoria code might be extremely useful
for some kinds of problems.

Once you've removed all the compiler directives that Broland introduced (and
aren't part of any other Prolog I've ever used) from Irv's example, you are
left with some very elegant (and recursive) definitions of reverse and
append.

I need to mention unification before proceeding. Prolog attempts to "unify"
clauses. The result of "unification" is a set of "bindings". For example,
here is a request for Prolog to unify these two statments:

    [1,2,3,4], [X|Y].

Prolog would return with the bindings that make the clause true:

    X = 1
    Y = [2,3,4]

You can see that the syntax [X|Y] binds X to the first element of a list,
and Y to the remaining elements. A Prolog statment is basically a proof that
says: if you can successfully unify (find legal bindings) for all the
clauses on the right hand side of a statement, then the bindings on the
right hand are true. So:

    reverse( [], [] ).

is always true (since it has no right hand bindings), and roughly translates
into:

    "reversing an empty list yields and empty list."

Rather than explain in great detail how reverse works (it's elegant, but not
trivial), I'll present what is essentially the same code in Euphoria:

    function reverse( sequence s )
        sequence x, y, y1
        if compare( s, {} ) = 0 then
            return {}
        else
            x = s[1]
            y = s[2..length(s)]
            y1 = reverse( y )
            return append( y1, x )
        end if
    end function

This may look very inefficient, but the Prolog engine is optimized for tail
recursion. But there is a more fundamental difference between the Prolog
code and the Euphoria code: the Prolog code is a "proof" or "definition" or
what a reversed list is. So you can not only ask Prolog to solve:

    reverse( [1,2,3,4,5], L ).

which yields the bindings:

    L = [5,4,3,2,1]

But you could also ask it to prove:

    reverse( L, [5,4,3,2,1]).

and it would give:

    L = [1,2,3,4,5]

You can even ask:

    reverse( [A,2,3], [3,2,1] ).

and get:

    A = 1

which is pretty darned slick, and only the tip of the iceberg of cool stuff
Prolog can do.

The other *very* cool thing is that you can ask Prolog to generate another
solution, and it will backtrack and see if there is another set of binding
that is also true until it has exhausted every permutation (or your fingers
get tired of pressing the Enter key).

Prolog certainly isn't a cure-all - just ask the the Fifth Generation
Project (remember them?). Prolog is very, very bad at linear stuff - the
kind of things that traditional programming languages excel in. But there
are times when inference, backtracking and unification is *exactly* the kind
of tool that you need.

And there's certainly no reason it (or a similar inference engine) can't be
added to the Euphoria toolkit.

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

4. Re: Prolog

>There are a number of PD DOS versions of Prolog floating around, but
>Turbo-Prolog is not one of them. The product was purchased from Borland,
and
>last I checked (about 3 years ago) was still a commerical product.


I never said it was free/shareware ;)
>I did quite a bit of hacking in Prolog - it's a very cool language. I've
>been tempted to write a Prolog-style unification engine, but never had a
>project that needed it. Euphoria would be ideal an ideal language to code
it
>in.


I've only "review" prolog. It requires a complete brain wash ;)

I spend some few weeks with SCHEME (LISP based), and really hated (compared
with Euphoria). All those CAR and CDR!!! I love Euphoria slices!

Regards,
    Daniel   Berstein
    daber at pair.com

new topic     » goto parent     » topic index » view message » categorize

5. Re: Prolog

I wrote:

>I agree that the inner working of Euphoria are a bit off-topic

I meant the inner working of Prolog.

I'm *very* interested in the inner workings of Euphoria. blink

-- David Cuny

new topic     » goto parent     » topic index » view message » categorize

6. Re: Prolog

David Cuny wrote:
> I'm *very* interested in the inner workings of Euphoria. blink
if i wasn't nice, i'd havta say... something... at this point...
=>
but, i'll be good Osmile  <--halo

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu