On Thursday, 16 January 2020 at 10:10:02 UTC, dwdv wrote:
On 2020-01-16 04:54, Jesse Phillips via Digitalmars-d-learn
wrote:
[...]
[...]
isn't far off, but could also be (sans imports):
return File(filename).byLine
.map!(line => line.until!(not!isAlpha))
.filter!(word => word.count ==
On 2020-01-16 04:54, Jesse Phillips via Digitalmars-d-learn wrote:
[...]
.map!(word => word.to!string.toUpper)
.array
.sort
.uniq
.map!(x => tuple (x, 0))
.assocArray ;
.each!(word => words[word.to!string.toUpper] = 0);
isn't far off, but could also be (sans imports):
return File(filename).b
On Wednesday, 15 January 2020 at 19:50:31 UTC, mark wrote:
I really do need a set for the next part of the program, but
taking your code and ideas I have now reduced the function to
this:
WordSet getWords(string filename, int wordsize) {
WordSet words;
File(filename).byLine
.ma
On Wed, Jan 15, 2020 at 07:50:31PM +, mark via Digitalmars-d-learn wrote:
[...]
> Why did you use string.count rather than string.length?
The .length of a `string` type is the number of bytes that it occupies,
which is not necessarily the same thing as the number of characters in
the string. E
I really do need a set for the next part of the program, but
taking your code and ideas I have now reduced the function to
this:
WordSet getWords(string filename, int wordsize) {
WordSet words;
File(filename).byLine
.map!(line => line.until!(not!isAlpha))
.filter!(word =
On 2020-01-15 16:34, mark via Digitalmars-d-learn wrote:
Is this as compact as it _reasonably_ can be?
How about this?
auto uniqueWords(string filename, uint wordsize) {
import std.algorithm, std.array, std.conv, std.functional, std.uni;
return File(filename).byLine
.map!(line
Thanks for the ideas, I've now reduced the size of the getWords()
function (even allowing for moving the imports to the top of the
file) to this:
WordSet getWords(string filename, int wordsize) {
string bareWord(string line) {
auto rx = ctRegex!(r"^([a-z]+)", "i");
auto matc
On Tuesday, 14 January 2020 at 16:39:16 UTC, mark wrote:
I can't help feeling that the foreach loop's block is rather
more verbose than it could be?
WordSet words;
auto rx = ctRegex!(r"^[a-z]+", "i");
auto file = File(filename);
foreach (line; file.byLine) {
auto matc
Should I have closed the file, i.e.,:
auto file = File(filename);
scope(exit) file.close(); // Add this?