Where to find the correct syntax for #lang racklog?

It appears that either I'm doing something blatantly stupid or #lang racklog documentation misses some points.

Here the question.

According to the documentation

This module language accepts the syntax of Datalog (except clauses need not be safe) and compiles each predicate to a relation.

The accepted syntax is available in the Datalog Module Language documentation.

Then, trying to run the example given in datalog, simply swapping "racklog" in place of "datalog"

#lang racklog

(racket/base). % here the parenthesis are not required, correct is racket/base. I remove those but then...

fib(0, 0). % from here onward, numbers are not recognized

fib(1, 1).

fib(N, F) :- N != 1,

N != 0,

N1 :- -(N, 1),

N2 :- -(N, 2),

fib(N1, F1),

fib(N2, F2),

F :- +(F1, F2).

fib(30, F)?

Specifically, the message of error regarding the first number is
match-lambda: no matching clause for '#s(constant (14-unsaved-editor 6 4 39 1) 0)

The example works in #lang datalog (which should be a subset of #lang racklog)

Although I'm not sure how actively the racklog package is maintained, it looks like its repo's issues page is here, if you wanted to ask there.

Thanks, but I think that, yes, the problem is that the package is bugged, at least for the parser for the pure #lang racklog (maybe the module to use inside #lang racket works, instead).

Thanks for your time. :slight_smile:

I wrote a comment on reddit, just now, I copy it here, to close the question.

Eventually I think that simply the part of the code which should read the pure #lang racklog has been neglected and doesn't work.

For example, going on I discovered that while

fib(0, 0).

fib(1, 1).

gave errors, nstead this

fib(+0, +0).

fib(+1, +1).

didn't.

But then, again, for the rest of the code this trick doesn't work.

Probably the mantainer was more interested to have it to work inside #lang racket and not as a language in itself (which after all makes sense, since Prolog is a thing).

The syntax is the same. The semantics are different.
The problem is that bindings from racket/base overrides what racklog expects.
This leads to the curious errors you see.

It may or may not have been an oversight.
The examples in the repo uses:

#lang racket
(require racklog)
<normal s-expression syntax here>

Having the imports this way, the racklog definitions override the ones from #lang racket.

See for example:

But if you want to use the Datalog syntax, make a helper file, say, "helper.rkt"
that only exports + and - from racket/base and import that.

1 Like