3
votes

I want a specific rule for reading user input data in SWI-Prolog, something like:

process( ... ) :-
    % do_stuff
    read_values( ... ),
    % do_more_stuff with X and Y here.

read_values( ... ) :-
    write('Please enter X: '),        
    read(X),
    write('Please enter Y: '),        
    read(Y).

Is that possible?

1

1 Answers

3
votes

Well you kinda already had the solution:

process :-
    % do_stuff
    read_values(A, B),
    % do_more_stuff with X and Y here
    atom_concat(A, B, C),
    writeln(C).

read_values(X, Y) :-
    write('Please enter X: '),        
    read(X),
    write('Please enter Y: '),        
    read(Y).

Example run:

?- process.
Please enter X: a.
Please enter Y: b.
ab
true.