cKanren
cKanren copied to clipboard
Fix some bugs
Bug 1:
> (run* (q) (== q #f))
'()
In the definition of case-inf, the cond's first branch:
[(not a-inf) e0]
When q was bound to #f, however, #f was regard as a kind of failure, then it was ignored.
So instead of putting the result directly into stream, it's better to encapsulate it with a list first.
Bug 2:
> (run 1.2 (q) (== q #t))
'(#t)
> (run -3 (q) (== q #t))
'(#t)
take should not accept negative number or float number.
Bug 3:
> (define teacupo
(λ (x)
(conde [(== 'tea x) succeed]
[(== 'cup x) succeed]
[fail])))
> (run* (r)
(conde [(teacupo r) succeed]
[(== 'f r) succeed]
[fail]))
'(f tea cup)
It should return '(tea cup #f) .
On the Appendix A of The Reasoned Schemer, mplus and mplusi are defined like this:
(define mplus
(λ (a-inf f)
(case-inf a-inf
(f)
[(a) (choice a f)]
[(a f0) (choice a (λf@ () (mplus (f0) f)))])))
(define mplusi
(λ (a-inf f)
(case-inf a-inf
(f)
[(a) (choice a f)]
[(a f0) (choice a (λf@ () (mplusi (f) f0)))])))
We can see that mplusm is defined as mplusi instead of mplus in the old code.