miniKanren / miniKanren

Canonical miniKanren implementation
MIT License
349 stars 31 forks source link

Broken with Guile Scheme 2.0.7 #2

Open zilti opened 11 years ago

zilti commented 11 years ago

Output from REPL:

scheme@(guile-user) [1]> (load "projects/logic/mk.scm")
scheme@(guile-user) [1]> (define f# fail)
scheme@(guile-user) [1]> (define s# succeed)
scheme@(guile-user) [1]> (run* (q) (== 1 q))
/home/zilti/projects/logic/mk.scm:216:2: In procedure subsume:
/home/zilti/projects/logic/mk.scm:216:2: In procedure module-lookup: Unbound variable: remp

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [2]> ,bt
In /home/zilti/projects/logic/mk.scm:
     69:7  4 (take #f #<procedure 2669f20 at <current input>:15:0 ()>)
In current input:
     15:0  3 (#<procedure 2669f20 at <current input>:15:0 ()>)
In /home/zilti/projects/logic/mk.scm:
   252:11  2 (#<procedure 2657ac0 at /home/zilti/projects/logic/mk.scm:247:4 (S+)> ((#(q) . 1)))
    305:6  1 (#<procedure 2668600 at /home/zilti/projects/logic/mk.scm:304:4 (A)> ())
    216:2  0 (subsume () ())
webyrd commented 11 years ago

Hi! Looks like remp isn't built into Guile.

(remp even? '(1 2 3 4 5)) => (1 3 5)

If you add this defn, do you get any other errors?

(define remp (lambda (p ls) (cond ((null? ls) '()) ((p (car ls)) (remp p (cdr ls))) (else (cons (car ls) (remp p (cdr ls)))))))

Thanks.

--Will

drcz commented 10 years ago

Hi! It seems that guile2.0 lacks remp, exists and call-with-string-output-port, and sort takes arguments in opposite order -- appending the following [re]definitions to mk should do the job:

(define (remp p ls) (cond ((null? ls) '()) ((p (car ls)) (remp p (cdr ls))) (else (cons (car ls) (remp p (cdr ls))))))

(define (exists p ls) (cond ((null? ls) #f) ((p (car ls)) #t) (else (exists p (cdr ls)))))

(define sorter (lambda (ls) (sort ls lex<=?)))

(define datum->string (lambda (x) (with-output-to-string (lambda () (display x)))))

Cheers, d.

enn commented 10 years ago

This is still broken in chicken scheme.

The fix provided works as long as you delete the original sorter (which uses those args backwards).

webyrd commented 10 years ago

Hmm. The version of Vicare Scheme I'm using doesn't even define 'sort', although the code works if 'sort' is defined to be 'list-sort'.

I wonder if implementation-specific preludes are a better way to handle these incompatibilities, as was done with earlier versions of full Kanren. Any thoughts?

RubyTuesdayDONO commented 8 years ago

+1 for preludes if they can reliably adapt miniKanren to specific implementations … so many fun things to do with guile!

RubyTuesdayDONO commented 8 years ago

better yet: can miniKanren somehow generate the translations needed to implement it for a given scheme engine, provided abstract definitions of the external functions it requires? for example, "i need a procedure remp such that (equal? (remp 'b '(a b c)) '(a c))