我只想将处理 lisp 查询的功能添加到 OnLisp 文本中的初始 Prolog 实现中。由于此功能在以下章节(新实现)中介绍,因此我只是从新实现中复制并进行了一些修改。
这是我修改/添加的函数/宏。
(=defun prove-query (expr binds)
(case (car expr)
(and (prove-and (cdr expr) binds))
(or (prove-or (cdr expr) binds))
(not (prove-not (cadr expr) binds))
(lisp (gen-lisp (cadr expr) binds)) ;;; added
(t (prove-simple expr binds))))
(defmacro with-binds (binds expr)
`(let ,(mapcar #'(lambda (v) `(,v (fullbind ,v ,binds)))
(vars-in expr))
(eval ,expr))) ;;; copied the whole macro from new implementaion and modified this line.
(=defun gen-lisp (expr binds) ;;; copied from new implementation but modified
(if (with-binds binds expr)
(=values binds)
(fail)))
但是当我运行下面的代码时,它抱怨没有定义一个变量。
(<- (ordered (?x)))
(<- (ordered (?x ?y . ?ys))
(lisp (<= ?x ?y))
(ordered (?y . ?ys)))
(with-inference (ordered (1 3 6))
(print t))
*** - EVAL: variable ?G3159 has no value
The following restarts are available:
USE-VALUE :R1 Input a value to be used instead of ?G3159.
STORE-VALUE :R2 Input a new value for ?G3159.
ABORT :R3 Abort main loop
我跟踪了 =gen-lisp 并扩展了宏“with-binds”,但没有发现任何有趣的东西。
(macroexpand '(with-binds '((?G3161 6) (?G3160 . 3) (?G3159 . 1)) '(<= ?G3160 ?G3159)))
(LET
((?G3160 (FULLBIND ?G3160 '((?G3161 6) (?G3160 . 3) (?G3159 . 1))))
(?G3159 (FULLBIND ?G3159 '((?G3161 6) (?G3160 . 3) (?G3159 . 1)))))
(EVAL '(<= ?G3160 ?G3159))) ;
有什么想法吗?
顺便说一下,这是完整的代码
https://drive.google.com/file/d/0B7t_DLbSmjMNRVh5SDBXdUVheDg/view?usp=sharing
提前致谢。