7

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?

Flux
  • 5,866
  • 4
  • 24
  • 62
Schemer
  • 107
  • 6
  • 1
    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. –  May 28 '18 at 15:00
  • Can you include the full text of the definitions window program that you're using, including the #lang line and any requires? – John Clements May 28 '18 at 16:37
  • 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) – Schemer May 28 '18 at 16:50
  • 2
    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. – Will Ness May 29 '18 at 07:16

4 Answers4

6

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))
'()
> 
Will Ness
  • 62,652
  • 8
  • 86
  • 167
  • Hmm... the call (run* q #f) doesn't seem to be working, though... is that one working for you? – John Clements May 28 '18 at 16:48
  • should it, though? I only have 1st ed. I'd expect at least `q` must be in parens: `(run* (q) ...)`. @JohnClements – Will Ness May 28 '18 at 16:51
  • 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. – John Clements May 28 '18 at 17:06
  • 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. – John Clements May 28 '18 at 17:10
  • Your example works fine but it is not the case for the examples of the book "The Reasoned Schemer - second edition". – Schemer May 28 '18 at 17:12
  • In the book q is not in parenthesis. – Schemer May 28 '18 at 17:14
  • Right I changed #u for #f but it did not help. – Schemer May 28 '18 at 17:16
  • @Schemer 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!). – Will Ness May 29 '18 at 07:13
  • @WillNess I will do so ! Thank You – Schemer May 30 '18 at 19:13
5

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.

John Clements
  • 15,850
  • 3
  • 28
  • 44
  • The new book explains that it covers 5 categories of changes . language, implementation, Laws, Commmandments and Translation. – Schemer May 28 '18 at 17:30
  • I'm confused. Is there a new edition of the book? I can't quite make sense of your comment. – John Clements May 29 '18 at 18:33
  • Yes, there is now a Second Edition of "The Reasoned Schemer" based on an evolutpion of MiniKanren as a relational langage implemented in Scheme. – Schemer May 30 '18 at 19:19
  • 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? – John Clements May 31 '18 at 16:07
3

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

https://github.com/TheReasonedSchemer2ndEd/CodeFromTheReasonedSchemer2ndEd

Hope this helps!

Cheers,

--Will

William E. Byrd
  • 2,880
  • 1
  • 8
  • 6
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)