shithub: pprolog

ref: 347e5bc533070a5e988d82e7588a4e905c7096f3
dir: pprolog/repl.c

View raw version
#include <u.h>
#include <libc.h>

#include "dat.h"
#include "fns.h"

void
repl(Term *database)
{
	int fd = 0; /* Standard input */
	while(1){
		print("?- ");
		Term *query = parse(fd, 1);
		Binding *bindings = nil;
		int success = evalquery(database, query, &bindings);
		if(success == 0)
			print("false.\n");
		else{
			if(bindings == nil)
				print("true.\n");
			else{
				while(bindings){
					print("%S = %S\n", bindings->name, prettyprint(bindings->value));
					bindings = bindings->next;
				}
			}
		}
	}
}