MiniKanren support by Dr Racket

721 views Asked by At

I started studying miniKanren with the book "The Reasoned Schemer - second edition" and the DrRacket scheme environment.

I installed the "faster-minikanren" package, but the first examples of the book with the command run* (for example, (run* q #f)) produce error messages such as run*: bad syntax in: (run* q #f).

Does this mean that the "faster-minikanren" package does not provide the right definition of minikanren? Or am I making a mistake?

4

There are 4 answers

4
John Clements On

Okay, everything Will Ness says is correct. Let me add another high-level comment: it looks like there's a combination of further development and a certain lack of support that's contributing to your situation.

1) It looks like the minikanren language has continued to evolve since the book was published.

2) It looks like certain changes (e.g. the #u success goal) weren't easy fits for Racket (though they'd certainly be possible with a Reader extension), and the authors of the libraries you're using elected to change the language instead.

One thing that may help are the docs for the original minikanren package (online at https://docs.racket-lang.org/minikanren/index.html ), which are nicely formatted and readable, and provide references for further reading.

9
Will Ness On

As the readme says, you need to put (require minikanren) in your Racket source file.

I've put in on the second line, after #lang racket, copied the appendo definition,

#lang racket
(require minikanren)

(define (appendo l s out)
  (conde
    [(== l '()) (== s out)]
    [(fresh (a d res)
       (== `(,a . ,d) l)
       (== `(,a . ,res) out)
       (appendo d s res))]))

then clicked on "Run", and tried this at the prompt:

> (run* (q r) (appendo q r '(1 2 3 4 5)))
'((() (1 2 3 4 5))
  ((1) (2 3 4 5))
  ((1 2) (3 4 5))
  ((1 2 3) (4 5))
  ((1 2 3 4) (5))
  ((1 2 3 4 5) ()))
> 

Seems to be working. This didn't:

> (run* q #f)
. run*: bad syntax in: (run* q #f)

> (run* (q) #f)
application: not a procedure;
 expected a procedure that can be applied to arguments
  given: #f
  arguments...:

but this did:

> (run* (q) (lambda (_) #f))
'()
> 
0
William E. Byrd On

You may find the code from the second edition we just released helpful:

https://github.com/TheReasonedSchemer2ndEd/CodeFromTheReasonedSchemer2ndEd

Hope this helps!

Cheers,

--Will

0
arsdragonfly On

After installing faster-minikanren (through the package manager or raco), put the following snippet at the beginning of your file:

#lang racket
(require minikanren)
(define succeed (== #t #t)) ;; suggested as per the footnote in frame 6 of Chapter 1, #s is written "succeed"
(define fail (== #f #t)) ;; and #u is written fail
(run* (q) succeed) ;; evaluates to '(_.0)