I noticed (great) code that counts lines of a file – so i could use this to load a files in a folder and count their lines.
However, i am curious as to how many lines of code a loaded program has. Can this be counted?
There is listing but i am unsure – from the documentation – if it goes into modules – and it does also list things that aren’t part of the consulted files, but predefined.
Can one identify in a line a valid prolog term, without enumerating all possible terms it could be?
Using the file read approach, i am now wondering if i can identify in a given line a valid prolog term – if such a term can be identified, then its a valid prolog line and not something else --i.e. comment or blank line
That’s the code i currently have:
%------------------------- % all, and only, *.pl files are in a folder in path % path atom must end with '\\' %------------------------- count_lines(Path, Count) :- dir_files(Entries), aux_count_file(Path, Entries, Count). aux_count_file(, 0). aux_count_file(Path, [First | Rest], New_Count) :- First \= '.', First \= '..', file_nl_count(First, Count), aux_count_file(Path, Rest, Count_Rest), New_Count is Count + Count_Rest. aux_count_file(Path, [_First | Rest], New_Count) :- aux_count_file(Path, Rest, New_Count). dir_files(Path, Entries) :- directory_files(Path, Entries). file_nl_count(Path, File0, Count) :- atomic_concat(Path, File0, File), format('~w~n', [File]), setup_call_cleanup( open(File, read, In), stream_nl_count(In, Count), close(In)). stream_nl_count(In, Count) :- stream_to_lazy_list(In, List), aggregate_all(count, member(0'\n, List), Count).