On 09/02/2010 10:24 PM, bearophile wrote:
simendsjo:
Suggestions for D-ifying the code is welcome.
Your unit tests are not good enough, they miss some important corner cases.
This my first version in D2:
import std.string: indexOf;
/// return True if s1 is a rotated version of s2
bool
Pelle wrote:
On 09/02/2010 10:24 PM, bearophile wrote:
simendsjo:
Suggestions for D-ifying the code is welcome.
Your unit tests are not good enough, they miss some important corner
cases.
This my first version in D2:
import std.string: indexOf;
/// return True if s1 is a rotated version
simendsjo:
I agree that's much simpler, but s1 ~ s1 doesn't perform too well I
think. Always creates a new heap allocation and copies the array..
The version written by Pelle is better. On the other hand performance is not an
absolute thing, it's good enough or not good enough, and in many
On 09/03/2010 01:35 PM, bearophile wrote:
Pelle:
bool isRotated(T)(T[] a, T[] b) {
return a.length == b.length (a.length == 0 ||
canFind(chain(a,a), b));
}
Nice clean solution. I suggest to add pure and two const in the signature.
canFind isn't really the best possible name, is it?
Pelle:
bool isRotated(T)(T[] a, T[] b) {
return a.length == b.length (a.length == 0 ||
canFind(chain(a,a), b));
}
Nice clean solution. I suggest to add pure and two const in the signature.
canFind isn't really the best possible name, is it?
Some name/APIs of Phobos are not the
On Friday 03 September 2010 04:35:30 bearophile wrote:
canFind isn't really the best possible name, is it?
Some name/APIs of Phobos are not the best possible, they were often
invented by a single person. I don't know if contains() or isIn() are
better.
It used to be that all you had was
I was reading about the various range templates in std.range and I found this:
http://www.digitalmars.com/d/2.0/phobos/std_range.html#isInfinite
Seems simple enough. But I dont understand it's implementation, this from
range.d:
template isInfinite(Range)
{
static if (isInputRange!Range
On Fri, 03 Sep 2010 11:12:29 -0400, Andrej Mitrovic
andrej.mitrov...@test.com wrote:
I was reading about the various range templates in std.range and I found
this:
http://www.digitalmars.com/d/2.0/phobos/std_range.html#isInfinite
Seems simple enough. But I dont understand it's
Ah, you're right. Whenever I see the square brackets my brain automatically
things we're indexing something. I'll blame that on C. :p
Thanks.
Steven Schveighoffer Wrote:
On Fri, 03 Sep 2010 11:12:29 -0400, Andrej Mitrovic
andrej.mitrov...@test.com wrote:
I was reading about the various
Jonathan M Davis:
Still, naming functions is a bit of an art and most function names are
debatable as to how good they are, so you're bound to have functions
in any API that aren't named the way that you think they should be.
I don't like what you say.
If you take a look at how in the last
So what's the word on this? Will we have simple indexing of tuples via T[] or
do we still need T.field[] and T._1 ? The situations is the same in 2.048 as it
was in 2.047.
There are more examples of tuples being used via T[] in some Phobos code
examples (which don't compile and I've reported
This is from TDPL page 407:
import std.algorithm,
std.concurrency,
std.stdio;
void main()
{
enum bufferSize = 1024 * 100;
auto tid = spawn(fileWriter);
// Read loop
foreach (immutable(ubyte)[] buffer; stdin.byChunk(bufferSize))
{
send(tid, buffer);
On Friday 03 September 2010 10:14:24 bearophile wrote:
Jonathan M Davis:
Still, naming functions is a bit of an art and most function names are
debatable as to how good they are, so you're bound to have functions
in any API that aren't named the way that you think they should be.
I don't
Hello,
I decided to exercise my skills in D a bit and wrote an implementation
for an echo server using D. I figure before I post it to the site, I'd
post it here for comments as I'd like to get the best possible version
on the site vs. something that's half-assed. Considering I'm very new
With dmd 2.048 this code:
import std.stdio: File;
void main() {
auto f = File(TEST.ppm, w);
f.writef(%c, 50);
}
Prints at run-time:
std.format.FormatError: std.format integral
So to write a char I've had to use:
f.write(cast(char)50);
Partially unrelated: is is possible to perform
15 matches
Mail list logo