Racket博士对MiniKanren的支持 [英] MiniKanren support by Dr Racket
问题描述
我从"The Reasoned Schemer-第二版"和DrRacket方案环境一书开始研究miniKanren.
I started studying miniKanren with the book "The Reasoned Schemer - second edition" and the DrRacket scheme environment.
我安装了"faster-minikanren"软件包,但是该书的第一个示例使用命令run*
(例如,(run* q #f)
)会产生错误消息,例如run*: bad syntax in: (run* q #f)
.
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)
.
这是否意味着"faster-minikanren"软件包没有提供正确的minikanren定义?还是我犯错了?
Does this mean that the "faster-minikanren" package does not provide the right definition of minikanren? Or am I making a mistake?
推荐答案
如自述文件所述, ,您需要将(require minikanren)
放在Racket源文件中.
As the readme says, you need to put (require minikanren)
in your Racket source file.
在第二行中,在#lang racket
之后,复制了appendo
定义
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...:
但是这样做:
> (run* (q) (lambda (_) #f))
'()
>
这篇关于Racket博士对MiniKanren的支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!