1:- module(swi_streams, [close_streams/2]).
 close_streams(+Streams:list, -Catchers:list) is det
Closes zero or more Streams while accumulating any exceptions at Catchers.
    8close_streams(Streams, Catchers) :-
    9    phrase(close_streams(Streams), Catchers).
   10
   11close_streams([]) -->
   12    [].
   13close_streams([Stream|Streams]) -->
   14    {   catch(close(Stream), Catcher, true)
   15    },
   16    (   {   var(Catcher)
   17        }
   18    ->  []
   19    ;   [Catcher]
   20    ),
   21    close_streams(Streams)