OSDN Git Service

minor cleanup
authorSimon Forman <sforman@hushmail.com>
Sun, 18 Aug 2019 19:17:37 +0000 (12:17 -0700)
committerSimon Forman <sforman@hushmail.com>
Sun, 18 Aug 2019 19:17:37 +0000 (12:17 -0700)
thun/gnu-prolog/fork.pl

index 767b145..6152492 100644 (file)
@@ -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),