I am writing a wrapper for the Prolog interpreter used in another programming language. I do not go into details, but basically generates the corresponding Prolog program and passes the program to the interpreter from standard input. I am relatively new to Prolog.
The problem is that I could not find the specification for the term [user]. that reads the rules from standard input. In particular, how it determines the end of input.
The most intuitive way to achieve this is to send an EOT character (Ctrl-D), but it doesn't seem to work. Below is an illustrative example, replace ^ D with the actual EOT character. Suppose this file is saved in input.pl . I intend to generate such code programmatically and pass it to the background prolog via standard input.
[user]. factorial(0,1). factorial(N,F) :- (>(N,0),is(N1,-(N,1)),factorial(N1,F1),is(F,*(N,F1))). ^D factorial(3,W).
When I run cat input.pl | <prolog> cat input.pl | <prolog> , where <prolog> is any Prolog interpreter (swipl, yap, etc.), it does not seem to recognize ^ D. Why is this and how can I solve it? On terminal ^ D is working fine.
The above example should return "W = 6". SWI complains about Syntax error: illegal_character . Yap seems to ignore ^ D, just parse everything and return yes .
Of course, I can write the program to a temporary file and tell the interpreter to consult the file, but it is slow.