MiniKanren support by Dr Racket
Asked Answered
G

4

9

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?

Groomsman answered 28/5, 2018 at 14:51 Comment(4)
Racket has a lot of resources and tutorials available. This site isn't really a great place for tutorials, so you aren't going to get much traction here.Lenes
Can you include the full text of the definitions window program that you're using, including the #lang line and any requires?Yorkshire
Editor Window : #lang racket (require minikanren) (run* q #f) Welcome to DrRacket, version 6.12 [3m]. Language: racket, with debugging; memory limit: 128 MB. . run*: bad syntax in: (run* q #f)Groomsman
there's a close vote on this question as "off-topic" for "asking for recommendation for a book or a tool". I don't think this is right. The OP has already chosen the book and the package.Byars
B
7

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))
'()
> 
Byars answered 28/5, 2018 at 16:42 Comment(9)
Hmm... the call (run* q #f) doesn't seem to be working, though... is that one working for you?Yorkshire
should it, though? I only have 1st ed. I'd expect at least q must be in parens: (run* (q) ...). @JohnClementsByars
I think I have a copy somewhere, but it's not here... I tried a bunch of variants, and couldn't get anything similar to work. The #f seems to break things, and it's hard to imagine the OP would have made that up.Yorkshire
Yeah, I just looked at the first few pages of the 2nd ed on Amazon, and in fact, it looks like the given example uses (run* q #u) ... which also doesn't work. The #u syntax would require a reader extension, so I'm guessing a bunch of adapting is required. It would be great if there was a companion for the pkg that helps users of the book.Yorkshire
Your example works fine but it is not the case for the examples of the book "The Reasoned Schemer - second edition".Groomsman
In the book q is not in parenthesis.Groomsman
Right I changed #u for #f but it did not help.Groomsman
@Groomsman you can use the code that works, it should be easy to change the new (apparently, unsupported by this package) code to the old ways. this little snag shouldn't stop you. :) if you have trouble translating the examples, don't hesitate to ask on SO, with the specifics included (like you did here, so, kudos for that!).Byars
@WillNess I will do so ! Thank YouGroomsman
Y
6

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.

Yorkshire answered 28/5, 2018 at 17:16 Comment(4)
The new book explains that it covers 5 categories of changes . language, implementation, Laws, Commmandments and Translation.Groomsman
I'm confused. Is there a new edition of the book? I can't quite make sense of your comment.Yorkshire
Yes, there is now a Second Edition of "The Reasoned Schemer" based on an evolutpion of MiniKanren as a relational langage implemented in Scheme.Groomsman
Hmm... I think I was looking at the second edition, using Amazon's "look inside", and it appeared to me that the first example in the book was still (run q #u)... but, full disclaimer, I probably didn't read the front material carefully enough. Is there mention of this problem in the front matter of the book?Yorkshire
K
4

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

https://github.com/TheReasonedSchemer2ndEd/CodeFromTheReasonedSchemer2ndEd

Hope this helps!

Cheers,

--Will

Kurman answered 25/6, 2018 at 21:54 Comment(0)
S
1

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)

Spodumene answered 21/12, 2020 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.