[racket] [racket-users]Is Racklog suitable to learn Prolog? A simple example just fails.

238 views
Skip to first unread message

WarGrey Gyoudmon Ju

unread,
Jul 3, 2014, 12:49:57 AM7/3/14
to Racket Users
This example is rewritten from the datalog version.

#lang racket

(require racklog)

(define %edge
  (%rel ()
    [('a 'b)]
    [('b 'c)]
    [('c 'd)]
    [('d 'a)]))

(define %path
  (%rel (X Y)
    [(X Y) (%edge X Y)]
    [(X Y) (%edge X 'Z)
             (%path 'Z Y)]))

(%find-all (X Y) (%path X Y))

It only gives four results.

#lang racklog

edge(a, b). 
edge(b, c).
edge(c, d).
edge(d, a).

path(X, Y) :- edge(X, Y).
path(X, Y) :- edge(X, Z), path(Z, Y).

path(X, Y)?

and this version will not terminate.

Thanks in advance.

Matthias Felleisen

unread,
Jul 3, 2014, 9:06:56 AM7/3/14
to WarGrey Gyoudmon Ju, Racket Users

If you want to learn Prolog, why not use a free Prolog implementation?

If you want to learn about relational programming, use miniKanren, which is available of cKanren. Then you can also get to constraints. Maintainer cc-ed.

-- Matthias
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users


____________________
Racket Users list:
http://lists.racket-lang.org/users

WarGrey Gyoudmon Ju

unread,
Jul 3, 2014, 10:55:40 AM7/3/14
to Matthias Felleisen, Racket Users
Sorry, my example is not correct.
But this one still does not work:

#lang at-exp racket

(require racklog)

(define %edge
  (%rel ()
    [('a 'b)]
    [('b 'c)]
    [('c 'd)]
    [('d 'a)]))

(define %path
  (%rel (X Y Z)
    [(X Y) (%edge X Y)]
    [(X Y) (%edge X Z) (%path Z Y)]))

(let answer ([r (%which (X Y) (%path X Y))])
  (printf "~a --> ~a~n" (cdar r) (cdadr r))
  (answer (%more)))

This version also will not terminate.

On Thu, Jul 3, 2014 at 9:04 PM, Matthias Felleisen <matt...@ccs.neu.edu> wrote:

If you want to learn Prolog, why not use a free Prolog implementation?

Simply speaking, Modern Prolog seems to cut the illumos-based SunOS off, I cannot build it without headache and they does not answer me about this issue.
So I wander if Racklog is a legacy package?

Matthias Felleisen

unread,
Jul 3, 2014, 1:24:16 PM7/3/14
to WarGrey Gyoudmon Ju, Racket Users

Yes, I corrected your program and ran into this bug. 

Try to use Kanren instead of Racklog. It isn't completely a legacy package but I doubt we can get a quick fix here. 

-- Matthias

WarGrey Gyoudmon Ju

unread,
Jul 3, 2014, 7:47:35 PM7/3/14
to Matthias Felleisen, Racket Users
Okay, Thank you.

Scott Moore

unread,
Jul 3, 2014, 11:39:50 PM7/3/14
to WarGrey Gyoudmon Ju, Racket Users, Matthias Felleisen
I'm not sure what behavior you were expecting for this program. Under standard prolog semantics (goal-directed) this program will yield infinitely many solutions, so this may not be a bug in racklog but rather in the program.

That said, Matthias is probably right that using a currently maintained package is probably a good idea.

Cheers,
Scott

Matthias Felleisen

unread,
Jul 4, 2014, 2:49:27 AM7/4/14
to Scott Moore, Racket Users

Racklog should have generated a stream of solutions here. That's my problem with it. -- Matthias

WarGrey Gyoudmon Ju

unread,
Jul 4, 2014, 7:51:36 AM7/4/14
to Scott Moore, Racket Users, Matthias Felleisen
Under standard prolog semantics Racklog is right.
The semantics between prolog and datalog is different.
Okay, thank you for pointing me.

Jay McCarthy

unread,
Jul 17, 2014, 3:33:09 PM7/17/14
to Matthias Felleisen, Racket Users
Matthias,

Racklog did generate a stream of solutions, but WarGrey's program
iterates through them all by calling (answer (%more)).

I also recommend kanren, though.

Jay
--
Jay McCarthy
http://jeapostrophe.github.io

"Wherefore, be not weary in well-doing,
for ye are laying the foundation of a great work.
And out of small things proceedeth that which is great."
- D&C 64:33

Matthias Felleisen

unread,
Jul 17, 2014, 4:40:47 PM7/17/14
to Jay McCarthy, Racket Users

Mea cupla.
Reply all
Reply to author
Forward
0 new messages