unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* prolog, pure guile scheme
@ 2010-07-06 21:52 stefan
  2010-07-08 18:21 ` Andy Wingo
  0 siblings, 1 reply; 2+ messages in thread
From: stefan @ 2010-07-06 21:52 UTC (permalink / raw)
  To: guile-devel

Hi,

I made a pure guile scheme directory under
language/prolog

at git@gitorious.org: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),
	queens3(UnplacedQs1,[Q|SafeQs],Qs).
queens3([],Qs,Qs).

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,[X|Xs],Xs).  
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 
solve.

So here is what I would like to use


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

And this translate to something like

(call-with-prompt
   *prompt*
   (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. 

Regards
Stefan













^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-07-08 18:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-06 21:52 prolog, pure guile scheme stefan
2010-07-08 18:21 ` Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).