Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a problem in strawberry Prolog enviroment

Status
Not open for further replies.

babakdeghat

Technical User
Dec 23, 2012
7
every time i run the following code :
[italic]
:- use_module(contestlib, [writeN/2]).
cross(N) :-
hor_line(N),
N1 is N - 1,
B1 is N1 // 2,
Middle is N1 + B1,
down(N,’*’,0,N1),
down(N,’.’,N1,B1),
blanks(1), blanks(Middle), stars(1), nl,
up(N,’.’,Middle,B1),
up(N,’*’,N1,N1),
hor_line(N).
hor_line(N) :- stars(N), blanks(N), stars(N), nl.
down(_,_,_,0) :- !.
down(N,Delimiter,Outer,Lines) :-
write_line(Delimiter,Outer,N),
Outer1 is Outer + 1,
Lines1 is Lines - 1,
down(N,Delimiter,Outer1,Lines1).
up(_,_,_,0) :- !.
up(N,Delimiter,Outer,Lines) :-
Outer1 is Outer - 1,
write_line(Delimiter,Outer1,N),
Lines1 is Lines - 1,
up(N,Delimiter,Outer1,Lines1).
write_line(Delimiter,OuterSpace,N) :-
write(Delimiter),
blanks(OuterSpace),
stars(1),
InnerSpace is 3*N - 4 - 2*OuterSpace,
blanks(InnerSpace),
stars(1),
blanks(OuterSpace),
write(Delimiter),
nl.
blanks(N) :- writeN(N,’.’).
stars(N) :- writeN(N,’*’).[/italic]

strawberry prolog just says :
[italic]Compiling the file:
C:\Users\Babak\Desktop\111111.pro
0 errors, 0 warnings.
No.[/italic]

the aim of this code :

Write a predicate cross/1, for which cross(N) draws a cross figurer.
* * * * *
* * * * *
* *
* *
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
* *
* *
* * * * *
* * * * *
3 × N
N N N
(a) N = 5
* * *
* * *
* *
* *
*
*
*
*
*
*
*
*
*
*
*
*
*
* *
* *
* * *
* * *
(b) N = 3


here is a picture of what it should look like :
13562683641.png
 
what do you think the problem is that it doesn't run ?
 
In SWI-Prolog, the code est correct, I wrote writeN/2 in this way :
Code:
writeN(N, X) :-
	forall(between(1, N, _I), write(X)).
I think there is a bug in your writeN.
 
Remove :- use_module(contestlib, [writeN/2]). and add the code above.
 
still didn't make any difference :
have i done it write ?
writeN(N, X) :-
forall(between(1, N, _I), write(X)).
cross(N) :-
hor_line(N),
N1 is N - 1,
B1 is N1 // 2,
Middle is N1 + B1,
down(N,’*’,0,N1),
down(N,’.’,N1,B1),
blanks(1), blanks(Middle), stars(1), nl,
up(N,’.’,Middle,B1),
up(N,’*’,N1,N1),
hor_line(N).
hor_line(N) :- stars(N), blanks(N), stars(N), nl.
down(_,_,_,0) :- !.
down(N,Delimiter,Outer,Lines) :-
write_line(Delimiter,Outer,N),
Outer1 is Outer + 1,
Lines1 is Lines - 1,
down(N,Delimiter,Outer1,Lines1).
up(_,_,_,0) :- !.
up(N,Delimiter,Outer,Lines) :-
Outer1 is Outer - 1,
write_line(Delimiter,Outer1,N),
Lines1 is Lines - 1,
up(N,Delimiter,Outer1,Lines1).
write_line(Delimiter,OuterSpace,N) :-
write(Delimiter),
blanks(OuterSpace),
stars(1),
InnerSpace is 3*N - 4 - 2*OuterSpace,
blanks(InnerSpace),
stars(1),
blanks(OuterSpace),
write(Delimiter),
nl.
blanks(N) :- writeN(N,’.’).
stars(N) :- writeN(N,’*’).

don't i need to write a query or something else ?
 
My code works with SWI-Prolog, that's all I can say !
 
and your code is exactly what i mentioned in my last post ???
 
No I test only the first code with my version of writeN/2.
I download StrawberryProlog, but I can't get the console. What I have to do to test the code ?
 
after downloading strawberry prolog compiler , extract the downloaded file and run prolog.exe , create a new file and paste code , then press F5 to run .
 
Have you to use Strawberry Prolog ? I have to define forall and between so that it can run writeN !!!
 
i am using strawberry compiler. i have even tried it on several other PCs , same result....
the error number i receive is error 16 which according to strawberry's official website it is because of a prefix notation which i have none....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top