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/ -----------------------------------------------------------------------------
I want a few explanations : why begin the file with a :-module (I'm sure I'm idiot but....)
That is the way to define that a file is a module, i.e., it has a well-defined interface which should not be violated. Using modules bring other good things, such as support for safer incremental compilation and compile-time cathing of more errors. There is more information on this matter in the paper
D. Cabeza, M. Hermenegildo. A New Module System for Prolog. International Conference on Computational Logic, CL2000, LNAI, Num. 1861, pages 131-148, Springer-Verlag, July 2000.
available from
http://www.clip.dia.fi.upm.es/clippubsbyyear/clippubsbyyear.html
What is a regtype, I have read the html doc but don't understand at all
It stands for "regular type", a class of data types. If you search "regular type" (quotes included) you will surely get a lot of answers. In short, regular types are those based on regular expressions.
Why :-export(queens/2) ?
Because you want it to be visible outside the module.
I see in test prédicate, it begin with tk_new([name('Ciao+TclTk - Queens')],I), is I a regtypes ? For the tclinterpreter
No, I *is* the Tcl/Tk interpreter (or, rather, a representation thereof which has information enough as to access to the "real thing" --- the process running the interpreter).
MCL
________________________________________________________________________ This is a signature virus. Add me to your signature and help me to live ============================================================================== 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/ -----------------------------------------------------------------------------