basic I/O

basic I/O

Post by rrodit » Fri, 09 Apr 2004 03:05:24


Hello!
I start to learn I/O in prolog.
I have SWI prolog compiler.
I try the following program to get number from user and output cube:
cube :-
write('next item: '),
read(X),
process(X).

process(stop) :- !.

process(N) :-
C is N * N * N,
write('cube of '),write(N),write(' is '),
write(C),nl,
cube.

but when i try it i can't accept result. every time i'am in first 'read'.
?- cube.
next item: 2
|: 3
|: 3

thanks
 
 
 

basic I/O

Post by bart demoe » Fri, 09 Apr 2004 03:34:54


read/1 reads a term which is followed by a dot . and a character like a
newline, a space, a tab ...
The newline might be necessary in any case, depending on whether you are
reading buffered or raw.
So, in response to next item:
type

2.<CR>

Cheers

Bart Demoen

 
 
 

basic I/O

Post by Matthew Pu » Fri, 09 Apr 2004 03:35:55


read/1 expects a Prolog term as input, with a '.' character at the end. Try
'2.' as input, rather than just '2'

--
Matthew Purver - matt at purver dot org
 
 
 

basic I/O

Post by Lura » Fri, 09 Apr 2004 06:00:56

thanks a lot
 
 
 

basic I/O

Post by Lura » Fri, 09 Apr 2004 06:01:21

thanks a lot