[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

prolog, pure guile scheme

From: stefan
Subject: prolog, pure guile scheme
Date: Tue, 6 Jul 2010 23:52:47 +0200
User-agent: KMail/1.12.4 (Linux/; KDE/4.3.5; x86_64; ; )


I made a pure guile scheme directory under

at address@hidden:guile-unify/guile-unify.git, unify-iso branch!

load the prolog-parser.scm in that directory and then
use for example (prolog-it <str>) e.g. 

(prolog-it "
queens(N,Qs) :- g_pk(N), rangeList(1,N,Ns),g_pk(Ns),queens3(Ns,[],Qs).

queens3(UnplacedQs, SafeQs, Qs) :-
        selectq(Q, UnplacedQs, UnplacedQs1),
        \\+ attack(Q,SafeQs),

attack(X,Xs) :- attack3(X, 1, Xs).

attack3(X,N,[Y|_])  :- X =:= Y+N ; X =:= Y-N.
attack3(X,N,[_|Ys]) :- N1 is N+1, attack3(X,N1,Ys).

rangeList(M,N,[M])      :- M >= N, !.
rangeList(M,N,[M|Tail]) :- M1 is M+1, rangeList(M1,N,Tail).

selectq(X,[Y|Ys],[Y|Zs]) :- selectq(X,Ys,Zs). 

you could run a query like

(run "queens(10,X)" #f)

Now this works but is slow as molasses. Not enteirly intentional. Part of the
slowness is due to the match algorithm mimicking the fast one in the master 
repo. Now the main reason is due to a problem with prompts that I did not 

So here is what I would like to use

(match #:tag pr
       ((a X)  (begin (do-something X pr)
                       (abort-to-prompt pr)))
       ((b X)  (b-it X)))

And this translate to something like

   (lambda () 
     (let ((pr *prompt*))
       (ma-it Z (a X) 
              (begin (do-something X pr) ...) 
              (abort-to-prompt pr))))
   (lambda (s) ...))

Now this works if we stay in the function, but if do-something contains
again a match constructed from the *prompt* prompt, then it get confused
so I was thinking like *prompt* beeing like a fluid let but it's not as it 
seams. At the repo unify-iso I instead construct a fresh new prompt at each 
match invocation which of cause is very costly but correct. I suspect that 
there is a quick hack to fix this and therefore I ask if anyone can help?

Interestingly in the master repo I hacked a prompt like feature that 
is not a delimited continuation but just keeps information of state to 
do a jump later on. 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]