ENHANCED: use newly available must_be(chars, ...), which is very fast
This commit is contained in:
@@ -66,51 +66,47 @@
|
|||||||
:- use_module(library(lists)).
|
:- use_module(library(lists)).
|
||||||
:- use_module(library(charsio)).
|
:- use_module(library(charsio)).
|
||||||
|
|
||||||
list_of_chars(Cs) :-
|
|
||||||
must_be(list, Cs),
|
|
||||||
maplist(must_be(character), Cs).
|
|
||||||
|
|
||||||
directory_files(Directory, Files) :-
|
directory_files(Directory, Files) :-
|
||||||
list_of_chars(Directory),
|
must_be(chars, Directory),
|
||||||
can_be(list, Files),
|
can_be(list, Files),
|
||||||
'$directory_files'(Directory, Files).
|
'$directory_files'(Directory, Files).
|
||||||
|
|
||||||
file_size(File, Size) :-
|
file_size(File, Size) :-
|
||||||
file_must_exist(File, file_size/2),
|
file_must_exist(File, file_size/2),
|
||||||
list_of_chars(File),
|
must_be(chars, File),
|
||||||
can_be(integer, Size),
|
can_be(integer, Size),
|
||||||
'$file_size'(File, Size).
|
'$file_size'(File, Size).
|
||||||
|
|
||||||
file_exists(File) :-
|
file_exists(File) :-
|
||||||
list_of_chars(File),
|
must_be(chars, File),
|
||||||
'$file_exists'(File).
|
'$file_exists'(File).
|
||||||
|
|
||||||
directory_exists(Directory) :-
|
directory_exists(Directory) :-
|
||||||
list_of_chars(Directory),
|
must_be(chars, Directory),
|
||||||
'$directory_exists'(Directory).
|
'$directory_exists'(Directory).
|
||||||
|
|
||||||
make_directory(Directory) :-
|
make_directory(Directory) :-
|
||||||
list_of_chars(Directory),
|
must_be(chars, Directory),
|
||||||
'$make_directory'(Directory).
|
'$make_directory'(Directory).
|
||||||
|
|
||||||
make_directory_path(Directory) :-
|
make_directory_path(Directory) :-
|
||||||
list_of_chars(Directory),
|
must_be(chars, Directory),
|
||||||
'$make_directory_path'(Directory).
|
'$make_directory_path'(Directory).
|
||||||
|
|
||||||
delete_file(File) :-
|
delete_file(File) :-
|
||||||
file_must_exist(File, delete_file/1),
|
file_must_exist(File, delete_file/1),
|
||||||
list_of_chars(File),
|
must_be(chars, File),
|
||||||
'$delete_file'(File).
|
'$delete_file'(File).
|
||||||
|
|
||||||
rename_file(File, Renamed) :-
|
rename_file(File, Renamed) :-
|
||||||
file_must_exist(File, rename_file/2),
|
file_must_exist(File, rename_file/2),
|
||||||
list_of_chars(File),
|
must_be(chars, File),
|
||||||
list_of_chars(Renamed),
|
must_be(chars, Renamed),
|
||||||
'$rename_file'(File, Renamed).
|
'$rename_file'(File, Renamed).
|
||||||
|
|
||||||
delete_directory(Directory) :-
|
delete_directory(Directory) :-
|
||||||
directory_must_exist(Directory, delete_directory/1),
|
directory_must_exist(Directory, delete_directory/1),
|
||||||
list_of_chars(Directory),
|
must_be(chars, Directory),
|
||||||
'$delete_directory'(Directory).
|
'$delete_directory'(Directory).
|
||||||
|
|
||||||
file_must_exist(File, Context) :-
|
file_must_exist(File, Context) :-
|
||||||
@@ -150,8 +146,7 @@ working_directory(Dir0, Dir) :-
|
|||||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|
||||||
path_canonical(Ps, Cs) :-
|
path_canonical(Ps, Cs) :-
|
||||||
must_be(list, Ps),
|
must_be(chars, Ps),
|
||||||
maplist(must_be(character), Ps),
|
|
||||||
can_be(list, Cs),
|
can_be(list, Cs),
|
||||||
'$path_canonical'(Ps, Cs).
|
'$path_canonical'(Ps, Cs).
|
||||||
|
|
||||||
@@ -205,9 +200,9 @@ path_segments(Path, Segments) :-
|
|||||||
'$directory_separator'(Sep),
|
'$directory_separator'(Sep),
|
||||||
( var(Path) ->
|
( var(Path) ->
|
||||||
must_be(list, Segments),
|
must_be(list, Segments),
|
||||||
maplist(list_of_chars, Segments),
|
maplist(must_be(chars), Segments),
|
||||||
append_with_separator(Segments, Sep, Path)
|
append_with_separator(Segments, Sep, Path)
|
||||||
; list_of_chars(Path),
|
; must_be(chars, Path),
|
||||||
path_to_segments(Path, Sep, Segments)
|
path_to_segments(Path, Sep, Segments)
|
||||||
).
|
).
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user