From 26c2730273e57ef2d753e1c3ef9459588acd9f23 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Sun, 18 Aug 2019 12:17:37 -0700 Subject: [PATCH] minor cleanup --- thun/gnu-prolog/fork.pl | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/thun/gnu-prolog/fork.pl b/thun/gnu-prolog/fork.pl index 767b145..6152492 100644 --- a/thun/gnu-prolog/fork.pl +++ b/thun/gnu-prolog/fork.pl @@ -11,27 +11,23 @@ fork(Expr, Stack, In, ChildPID) :- fork_prolog(ChildPID), bar(ChildPID, In, Out, Expr, Stack). -bar(0, In, Out, Expr, Stack) :- - close(In), +bar(0, In, Out, Expr, Stack) :- close(In), thun(Expr, Stack, [Result|_]), - w(Out, Result), - close(Out), + w(Out, Result), close(Out), halt. bar(PID, _, Out, _, _) :- - integer(PID), - PID =\= 0, + integer(PID), PID =\= 0, close(Out). read_pipe(In, Result) :- select([In], R, [], _, 1500), - (R=[In] -> - read(In, Result) - ; - Result=timeout - ), + read_pipe_(R, In, Result), close(In). +read_pipe_([In], In, Result) :- read(In, Result). +read_pipe_( [], _, timeout). + mkpipe(In, Out) :- create_pipe(In, Out), set_stream_buffering(Out, none),