Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MiniKanren support by Dr Racket

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?

like image 762
Schemer Avatar asked May 28 '18 14:05

Schemer


2 Answers

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))
'()
> 
like image 93
Will Ness Avatar answered Sep 19 '22 05:09

Will Ness


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.

like image 34
John Clements Avatar answered Sep 21 '22 05:09

John Clements