February 26, 2013
>> But I couldn't figure out how to expand the boolean array to
>> an argument list.

With functions like this my last version will become simpler, and it's equally statically type safe:

bool xor(in bool[2] args) pure nothrow {
    return b[0] != b[1];
}


Bye,
bearophile
February 26, 2013
> With functions like this my last version will become simpler, and it's equally statically type safe:
>
> bool xor(in bool[2] args) pure nothrow {
>     return b[0] != b[1];
> }

This third version is much simpler and it seems good enough for
Rosettacode:

http://codepad.org/YJjb1t91

Bye,
bearophile
February 26, 2013
On Tuesday, 26 February 2013 at 14:10:04 UTC, bearophile wrote:
>> With functions like this my last version will become simpler, and it's equally statically type safe:
>>
>> bool xor(in bool[2] args) pure nothrow {
>>    return b[0] != b[1];
>> }
>
> This third version is much simpler and it seems good enough for
> Rosettacode:
>
> http://codepad.org/YJjb1t91

Yes, it's much nicer than the heavily templated one. We may be able to update it if/when std.reflection comes through.

I'd prefer the more conventional notation (i & (1 << j)) != 0, rather than the double negative.
February 27, 2013
On 2013-02-26 15:10, bearophile wrote:
> This third version is much simpler and it seems good enough for
> Rosettacode:
>
> http://codepad.org/YJjb1t91

Nice. Myself I'd add bits.reverse; after the N.iota.map..., because I'm more used to a truth table where the left-most operands iterate the slowest.

February 27, 2013
On 2013-02-27 12:47, FG wrote:
> On 2013-02-26 15:10, bearophile wrote:
>> This third version is much simpler and it seems good enough for
>> Rosettacode:
>>
>> http://codepad.org/YJjb1t91
>
> Nice. Myself I'd add bits.reverse; after the N.iota.map..., because I'm more
> used to a truth table where the left-most operands iterate the slowest.

or, without reverse, but perhaps not very clear:
N.iota.map!(j => !!(i & (1 << (N - j - 1)))).copy(bits[]);

February 27, 2013
FG:

> or, without reverse, but perhaps not very clear:
> N.iota.map!(j => !!(i & (1 << (N - j - 1)))).copy(bits[]);

OK, improved in Rosettacode.

Bye,
bearophile
February 28, 2013
A possible idea is to translate this last Python version to D:

http://rosettacode.org/wiki/Hamming_numbers#Cyclic_generator_method_.232.

- - - - - - - - - - - -

Another idea is to add a D version of Merge Sort that works with just a Input Range (like a single linked list, as a SList):
http://rosettacode.org/wiki/Merge_sort

Slicing the input range in two is probably possible. But what's the result of such function? Just an array created with an Appender? It can't be the same type of the input, because it is just a input range, so it doesn't need to have a put(). Maybe a given sink that is an output range? Or maybe a sink created inside given its type as template argument?

Bye,
bearophile
March 04, 2013
Now and then this thread becomes very useful for some coordination and discussion.

Regarding this Task:
http://rosettacode.org/wiki/Take_notes_on_the_command_line#D

Fwend has recently modified it with this note:

>the file only needs to be created before append; filename can be written as one word in English, no need for camel case)<

Sorry, I didn't know "filename" a single English word :-)
http://dictionary.cambridge.org/dictionary/business-english/filename?q=filename


Regarding the other problem, the last part of the Task says:

>If NOTES.TXT doesn't already exist in the current directory then a new NOTES.TXT file should be created.<

If no text file exists in the directory and I run the current program with no arguments, it generates no file to me. So I think the current program is wrong. That's why I added a File(fileName, "w");. What do you think?

Bye,
bearophile
March 04, 2013
On 4-3-2013 23:04, bearophile wrote:
> Now and then this thread becomes very useful for some coordination and discussion.
>
> Regarding this Task:
> http://rosettacode.org/wiki/Take_notes_on_the_command_line#D
>
> Fwend has recently modified it with this note:
>
>> the file only needs to be created before append; filename can be written as one word in English, no need for camel case)<
>
> Sorry, I didn't know "filename" a single English word :-)
> http://dictionary.cambridge.org/dictionary/business-english/filename?q=filename
>
>
> Regarding the other problem, the last part of the Task says:
>
>> If NOTES.TXT doesn't already exist in the current directory then a new NOTES.TXT file should be created.<
>
> If no text file exists in the directory and I run the current program with no arguments, it generates no file to me. So I think the current program is wrong. That's why I added a File(fileName, "w");. What do you think?

It depends on how you interpret it. The task describes two actions:
display and append. The question is: does the last sentence refer to
the append action or to both display and append. I choose to think it
refers to the append action because that makes more sense.

As for http://rosettacode.org/wiki/Simple_database

You removed the struct that I used to encapsulate the functions.

Aren't these functions now exposed to other modules? I wanted
them to only be callable from main. The input validation relies
on that.

At first I had declared them all private, but then I thought it
would be convenient to put a struct around them and declare it
private. Maybe there's a better way.

March 05, 2013
On 5-3-2013 0:57, Jos van Uden wrote:
> On 4-3-2013 23:04, bearophile wrote:
>> Now and then this thread becomes very useful for some coordination and discussion.
>>
>> Regarding this Task:
>> http://rosettacode.org/wiki/Take_notes_on_the_command_line#D
>>
>> Fwend has recently modified it with this note:
>>
>>> the file only needs to be created before append; filename can be written as one word in English, no need for camel case)<
>>
>> Sorry, I didn't know "filename" a single English word :-)
>> http://dictionary.cambridge.org/dictionary/business-english/filename?q=filename
>>
>>
>> Regarding the other problem, the last part of the Task says:
>>
>>> If NOTES.TXT doesn't already exist in the current directory then a new NOTES.TXT file should be created.<
>>
>> If no text file exists in the directory and I run the current program with no arguments, it generates no file to me. So I think the current program is wrong. That's why I added a File(fileName, "w");. What do you think?
>
> It depends on how you interpret it. The task describes two actions:
> display and append. The question is: does the last sentence refer to
> the append action or to both display and append. I choose to think it
> refers to the append action because that makes more sense.
>
> As for http://rosettacode.org/wiki/Simple_database
>
> You removed the struct that I used to encapsulate the functions.
>
> Aren't these functions now exposed to other modules? I wanted
> them to only be callable from main. The input validation relies
> on that.
>
> At first I had declared them all private, but then I thought it
> would be convenient to put a struct around them and declare it
> private. Maybe there's a better way.

Another consideration, I just remembered, was that it avoided
creating global variables.