On Friday, 12 May 2017 at 15:24:52 UTC, k-five wrote:
On Friday, 12 May 2017 at 11:10:01 UTC, k-five wrote:
I was waiting for a stable version of C++17 ( standard library
) to add some features of fileSystem in C++17 to my program
that wants to iterate through all files in a directory
recursively.
I was thinking how could I do for implementing that and add it
to my program.
Now after starting to learn D ( nearby 2 weeks so far ). I can
do it in 6 lines!
void main( string[] args ){
string[] all_file_name = dirEntries( ".", SpanMode.depth,
false )
.filter!( file => !file.name.matchFirst( regex( args[
1 ] ) ).empty() )
.filter!( file => ( args[ 2 ] == "-f" || args[ 2 ] ==
"-d" ? ( args[ 2 ] == "-f" ? !file.isDir : !file.isFile ) : (
!file.isSymlink ) ) )
.map!( file => file.name )
.array;
foreach( string item; all_file_name ) writeln( item );
}
./bin-file '[A-Z]$' -f ---> print all files that are matched
against [A-Z]$
./bin-file '[A-Z]$' -d ---> print all directory that are
matched against [A-Z]$
./bin-file '[A-Z]$' "anything-else" ---> print both files and
directory that are matched against [A-Z]$
I am so happy since after more than one year practicing in C++
and putting a collection more than 2000 examples of C++ on my
github, I was not sure I could do it in 6 lines.
May it is a Spam but I think it is worth it.
------------------------------------------------------------------
May it has worth it to be an example on how great D is, in
somewhere like, in the tour section or std.file or std.regex to
attract others.
A full version that I just added to my gitgub:
https://github.com/k-five/dren
Is it safe to say that these 40 lines of D do the same as your
324 lines of C++ [1]? This, and your comments on the difficulties
of building renrem [2] versus doing "rdmd", and the steepness of
the learning curve (1 year C++ vs 2 weeks D), and the
productivity (2 hours D vs ?? C++) I think are plenty material
for a nice little blog.
Mike Parker runs the D blog, and I think he might be interested.
No need to worry about the english language, you are safe with
Mike. I'll see if I can get you his attention.
[1] https://github.com/k-five/renrem
[2] https://github.com/k-five/renrem/blob/master/src/README.md
[3] https://dlang.org/blog/