×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

a problem in strawberry Prolog enviroment

a problem in strawberry Prolog enviroment

a problem in strawberry Prolog enviroment

(OP)
every time i run the following code :

:- 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,’*’).


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


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 :

RE: a problem in strawberry Prolog enviroment

(OP)
what do you think the problem is that it doesn't run ?

RE: a problem in strawberry Prolog enviroment

In SWI-Prolog, the code est correct, I wrote writeN/2 in this way :

CODE --> Prolog

writeN(N, X) :-
	forall(between(1, N, _I), write(X)). 
I think there is a bug in your writeN.

RE: a problem in strawberry Prolog enviroment

(OP)
which lines should i replace this with ?

RE: a problem in strawberry Prolog enviroment

Remove :- use_module(contestlib, [writeN/2]). and add the code above.

RE: a problem in strawberry Prolog enviroment

(OP)
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 ?

RE: a problem in strawberry Prolog enviroment

My code works with SWI-Prolog, that's all I can say !

RE: a problem in strawberry Prolog enviroment

(OP)
and your code is exactly what i mentioned in my last post ???

RE: a problem in strawberry Prolog enviroment

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 ?

RE: a problem in strawberry Prolog enviroment

(OP)
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 .

RE: a problem in strawberry Prolog enviroment

Have you to use Strawberry Prolog ? I have to define forall and between so that it can run writeN !!!

RE: a problem in strawberry Prolog enviroment

(OP)
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....

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close