Hi, I'm very new in prolog, but this language give me a good feeling I'm interesting to use the tcltk interface So I have read and run the queens.pl example in tcltk/examples
I want a few explanations : why begin the file with a :-module (I'm sure I'm idiot but....) What is a regtype, I have read the html doc but don't understand at all Why :-export(queens/2) ?
I see in test prédicate, it begin with tk_new([name('Ciao+TclTk - Queens')],I), is I a regtypes ? For the tclinterpreter
I swim in océan and perharps you think I'm silly But I ask even.
Thanks David
The queens.pl
:- module(queens,[main/0, test/0],[assertions,isomodes,regtypes]).
:- use_module(library(tcltk)). :- use_module(library(lists)). :- use_module(library(format)).
:-export(queens/2).
queens(N,Qs) :- range(1,N,Ns), queens(Ns,[],Qs).
queens(UnplacedQs, SafeQs, Qs) :- select(Q,UnplacedQs, UnplacedQs1), + attack(Q,SafeQs), queens(UnplacedQs1,[Q|SafeQs],Qs). queens([], Qs, Qs).
attack(X,Xs) :- attack(X, 1, Xs).
attack(X,N,[Y|_Ys]) :- X is Y + N. attack(X,N,[Y|_Ys]) :- X is Y - N. attack(X,N,[_Y|Ys]) :- N1 is N + 1, attack(X,N1,Ys).
range(M,N,[M|Ns]) :- M < N, M1 is M + 1, range(M1,N,Ns).
range(N, N,[N]).
main:- test.
test :- tk_new([name('Ciao+TclTk - Queens')],I), % tcl_new(I), tcl_eval(I,'source 8-queens.tcl',_), % tcl_event(I,[prolog_event,dq(write(next))],_), % tcl_event(I,[prolog_event,dq(write(next))],_), % tcl_event(I,[prolog_event,dq(write(next))],_), % tcl_event(I,[prolog_event,dq(write(quit))],H), % display(H), tk_next_event(I,Event), % display(Event), % display('En el primero*****'),nl, % display(Event),nl, ( Event = next -> go(I) ; closedown(I) ).
closedown(X) :- tcl_delete(X).
go(I) :- % display('Queens'),nl, tcl_eval(I,'clear_board',_), queens(8,Qs), display(Qs),nl, show_solution(I,Qs), tk_next_event(I,Event), % display('En el segundo*****'),display(Event),nl, ( Event = next -> fail ; closedown(I) ). go(I) :- tcl_eval(I,'disable_next',_), tcl_eval(I,'clear_board',_), tk_next_event(I,_Event), closedown(I).
show_solution(I,L) :- reverse(L,LR), tcl_eval(I,[show_solution,br(LR)],_).
============================================================================== Message: Address: Action: help majordomo(a)clip.dia.fi.upm.es Info. on useful commands subscribe ciao-users-request(a)clip.dia.fi.upm.es Subscribe to this list unsubscribe ciao-users-request(a)clip.dia.fi.upm.es Unsubscribe from this list <whatever> ciao-users(a)clip.dia.fi.upm.es Send message to list ----------------------------------------------------------------------------- Archived messages: http://www.clip.dia.fi.upm.es/Mail/ciao-users/ -----------------------------------------------------------------------------