]> Repositorios git - scryer-prolog.git/commitdiff
allow toplevel answers to be passed back as queries
authorMark Thom <[email protected]>
Fri, 22 Mar 2019 16:00:07 +0000 (10:00 -0600)
committerMark Thom <[email protected]>
Fri, 22 Mar 2019 16:00:07 +0000 (10:00 -0600)
Cargo.toml
src/prolog/write.rs

index 88a1df3e7488037586830f4bacaf46937eb94789..b4805eff74d0827772f3fb40335394b5d8ec949c 100644 (file)
@@ -1,6 +1,6 @@
 [package]
 name = "scryer-prolog"
-version = "0.8.12"
+version = "0.8.13"
 authors = ["Mark Thom <[email protected]>"]
 repository = "https://github.com/mthom/scryer-prolog"
 description = "A modern Prolog implementation written mostly in Rust."
index a036240f9b8bae8ee8bbd9dba43d6f721e84bd21..59c82ac2eafba4a7878e7d4fa9b57b1b65ef99b1 100644 (file)
@@ -371,35 +371,29 @@ fn next_step(mut stdout: RawTerminal<std::io::Stdout>) -> ContinueResult
 
 pub fn print(wam: &mut Machine, result: EvalSession) {
     match result {
-        EvalSession::InitialQuerySuccess(alloc_locs, mut heap_locs) => {
-            if wam.or_stack_is_empty() {
-                println!("true.");
-
-                if heap_locs.is_empty() {
-                    return;
-                }
-            }
-
-            if !wam.or_stack_is_empty() {
-                print!("true .");
-
-                if !heap_locs.is_empty() {
-                    println!("\r");
-                }
-            }
-
+        EvalSession::InitialQuerySuccess(alloc_locs, mut heap_locs) => {            
             loop {
-                let mut output = PrinterOutputter::new();
-
-                let bindings = wam.heap_view(&heap_locs, output).result();
+                if wam.or_stack_is_empty() {
+                    if heap_locs.is_empty() {
+                        println!("true.");
+                        return;
+                    }
+                } else if heap_locs.is_empty() {
+                    print!("true");
+                    stdout().flush().unwrap();
+                }
+                
                 let mut raw_stdout = stdout().into_raw_mode().unwrap();
 
                 if !heap_locs.is_empty() {
+                    let mut output = PrinterOutputter::new();                    
+                    let bindings = wam.heap_view(&heap_locs, output).result();
+                    
                     write!(raw_stdout, "{}", bindings).unwrap();
                     raw_stdout.flush().unwrap();
-                    
+
                     let attr_goals = wam.attribute_goals(&heap_locs);
-                    
+
                     if !attr_goals.is_empty() {
                         write!(raw_stdout, "\r\n{}\r\n", attr_goals).unwrap();
                     }
@@ -429,14 +423,14 @@ pub fn print(wam: &mut Machine, result: EvalSession) {
                         write!(raw_stdout, "{}\r\n", error_string(e)).unwrap();
                         raw_stdout.flush().unwrap();
                         return;
-                    }
+                    }                    
                 } else {
                     if heap_locs.is_empty() {
                         write!(raw_stdout, "true.\r\n").unwrap();
                     } else {
                         write!(raw_stdout, ".\r\n").unwrap();
                     }
-                    
+
                     break;
                 }
             }