Reputation: 21
ive came this far. im new to prolog and i want to make simple figures. i want to make the input like this:
line(X,Y):-
read(Y), print(Y).
print(Y) :- write(Y).
this should be the result.
?- line(8, X).
XXXXXXXX
Upvotes: 2
Views: 94
Reputation: 117064
You're not doing anything in your code to count down on the X
argument that your pass to line
predicate.
Try this code:
line(X,Y):-
read(Y),
print(X,Y).
print(0,_).
print(X,Y) :-
X>0,
write(Y),
X2 is X - 1,
print(X2,Y).
When I run that I get this:
?- line(8,X). |: 3. 33333333 X = 3 .
Upvotes: 0
Reputation: 211
Not sure I've understood your question properly but how about:
line(Length,Char) :-
length(List,Length),
maplist(=(Char),List),
atomic_list_concat(List,Atom),
write(Atom).
So line(8,'X')
would print XXXXXXXX
and line(3,q)
would print qqq
.
Uses:
Upvotes: 1