unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: stefan <stefan.tampe@spray.se>
To: guile-devel@gnu.org
Subject: prolog, pure guile scheme
Date: Tue, 6 Jul 2010 23:52:47 +0200	[thread overview]
Message-ID: <201007062352.47878.stefan.tampe@spray.se> (raw)

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













             reply	other threads:[~2010-07-06 21:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-06 21:52 stefan [this message]
2010-07-08 18:21 ` prolog, pure guile scheme Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201007062352.47878.stefan.tampe@spray.se \
    --to=stefan.tampe@spray.se \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).