/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Part of Scryer Prolog.
Predicates for reasoning about files and directories.
:- use_module(library(error)).
:- use_module(library(lists)).
:- use_module(library(charsio)).
+:- use_module(library(dcgs)).
directory_files(Directory, Files) :-
must_be(chars, Directory),
( var(Path) ->
must_be(list, Segments),
maplist(must_be(chars), Segments),
- append_with_separator(Segments, Sep, Path)
+ phrase(append_with_separator(Segments, Sep), Path)
; must_be(chars, Path),
path_to_segments(Path, Sep, Segments)
).
-append_with_separator([], _, []).
-append_with_separator([Segment|Segments], Sep, Path) :-
- append_with_separator_(Segments, Segment, Sep, Path).
+append_with_separator([], _) --> [].
+append_with_separator([Segment|Segments], Sep) -->
+ append_with_separator_(Segments, Segment, Sep).
-append_with_separator_([], Segment, _, Segment).
-append_with_separator_([Segment|Segments], Prev, Sep, Path) :-
- append(Prev, [Sep|Rest], Path),
- append_with_separator_(Segments, Segment, Sep, Rest).
+append_with_separator_([], Segment, _) --> seq(Segment).
+append_with_separator_([Segment|Segments], Prev, Sep) -->
+ seq(Prev), [Sep],
+ append_with_separator_(Segments, Segment, Sep).
path_to_segments(Path, Sep, Segments) :-
( append(Front, [Sep|Ps], Path) ->