Re: [your code here]

2013-01-31 Thread FG
On 2013-01-31 12:38, Namespace wrote: If you want to do something, then take destroy. AFAIK delete destroy _and_ release the memory immediately. 'destroy' doesn't. And that's why delete is valuable (at least on 32-bit windows). Especially when you are comparing 500 MB files in a loop. :)

Re: [your code here]

2013-01-31 Thread Namespace
On Thursday, 31 January 2013 at 10:58:48 UTC, Peter Alexander wrote: On Thursday, 31 January 2013 at 08:42:48 UTC, Roumen Roupski wrote: finally { delete m1; delete m2; } D has a GC. No need for manual deletion. (In fact, I think this is

Re: [your code here]

2013-01-31 Thread Peter Alexander
On Thursday, 31 January 2013 at 08:42:48 UTC, Roumen Roupski wrote: finally { delete m1; delete m2; } D has a GC. No need for manual deletion. (In fact, I think this is deprecated? Or scheduled for removal? Or maybe neither. Who knows).

Re: [your code here]

2013-01-31 Thread bearophile
Roumen Roupski: private bool equals(in string f1, in string f2) { if (getSize(f1) != getSize(f2)) return false; // different file sizes if (getSize(f1) == 0) return true;// zero-length files are equal Making equals() private is not useful,

[your code here]

2013-01-31 Thread Roumen Roupski
// Checks if two files have equal content using memory mapped files import std.file; import std.mmfile; import std.stdio; // Compares the content of two files private bool equals(in string f1, in string f2) { if (getSize(f1) != getSize(f2)) return false; // different fi

[your code here]

2012-12-20 Thread H. S. Teoh
D's front page solicits for code examples to be showcased on the front page upon approval, and several people have submitted samples (including myself), but AFAIK nothing has ever been actually done about it. The source code seen on the front page is statically coded into the DDoc template that pro

Re: [your code here]

2012-04-17 Thread H. S. Teoh
On Wed, Apr 18, 2012 at 05:35:24AM +0200, jerro wrote: [...] > There is a bug in this code. If a line is longer then width but > doesn't contain spaces, find will return an empty range and the > length of line will not decrease on each while loop iteration. So > there is an endless loop. You're ri

Re: [your code here]

2012-04-17 Thread jerro
On Wednesday, 18 April 2012 at 01:59:19 UTC, H. S. Teoh wrote: // Wraps long lines in standard input. // Demonstrates D's powerful array manipulation facility and generic // algorithms. import std.algorithm; import std.array; import std.range; import std.stdio; void main() { int width

[your code here]

2012-04-17 Thread H. S. Teoh
// Wraps long lines in standard input. // Demonstrates D's powerful array manipulation facility and generic // algorithms. import std.algorithm; import std.array; import std.range; import std.stdio; void main() { int width = 80; foreach (line; stdin.byLine()) { wh

Re: [your code here]

2012-02-18 Thread Joshua Niehus
On Saturday, 18 February 2012 at 08:18:32 UTC, Denis Shelomovskij wrote: Some remarks: 0. `string[] args` isn't needed; 1. `delegate` is not needed; 2. `isSomeString!(T)` can be replaced by `isSomeString!T`; 3. `static if` can be replaced by `auto m = mixin(isSomeString!T ? "n ~ i" : "n + i");`;

Re: [your code here]

2012-02-18 Thread Denis Shelomovskij
18.02.2012 0:33, Joshua Niehus пишет: Not as fancy as the other submits, but it might be worthy of the front page: import std.stdio, std.traits; void main(string[] args) { auto foo(T)(T n) { return delegate(T i) { static if (isSomeString!(T)) auto m = mix

Re: [your code here]

2012-02-17 Thread a
Assuming that by "any" you mean "any particular", you would have to read all the lines first. Otherwise, if the code selects the first line with probability 1/K, then I can just input some other number of lines. I'm not sure if I understood your post correctly, but it seems to me that you

Re: File Api [Was: [your code here]]

2012-02-17 Thread H. S. Teoh
On Sat, Feb 18, 2012 at 04:41:09AM +0100, Brad Anderson wrote: > On Saturday, 18 February 2012 at 02:46:52 UTC, H. S. Teoh wrote: [...] > >Anyway, is anyone working on a new file I/O interface? I'd like to > >see std.stream and std.stdio combined, for one thing. Or replaced > >with a range-based AP

Re: [your code here]

2012-02-17 Thread Andrei Alexandrescu
On 2/17/12 8:18 PM, Matt Soucy wrote: On 02/17/2012 08:57 PM, Jonathan M Davis wrote: On Saturday, February 18, 2012 02:53:44 Timon Gehr wrote: If you want it to be executable as a script, rdmd works just fine. But is there any guarantee that rdmd will even be on the system? It seems much saf

Re: File Api [Was: [your code here]]

2012-02-17 Thread Brad Anderson
On Saturday, 18 February 2012 at 02:46:52 UTC, H. S. Teoh wrote: On Fri, Feb 17, 2012 at 09:20:59PM -0500, bearophile wrote: H. S. Teoh: > P.S.S. The .idup is a bit ugly, but necessary, since > apparently > byLine() calls readln() with a static buffer, so choice will > be > silently overwrit

Re: File Api [Was: [your code here]]

2012-02-17 Thread bearophile
Timon Gehr: > Note that what we have now is clear, handy, quite short and safe and > efficient. What you propose takes away the clarity and efficiency parts. What we have now: - by Line() is explicit, but if you don't use it is not that clear, if a Python programmer iterates on File it gives a

Re: [your code here]

2012-02-17 Thread H. S. Teoh
On Sat, Feb 18, 2012 at 03:38:59AM +0100, Andrej Mitrovic wrote: > Is this D1 code? You can't use writef with a format specifier and no > arguments. Probably a mistake, the extra arguments on the second writef() should be moved to the first write(). T -- When solving a problem, take care that

Re: File Api [Was: [your code here]]

2012-02-17 Thread H. S. Teoh
On Fri, Feb 17, 2012 at 09:20:59PM -0500, bearophile wrote: > H. S. Teoh: > > > P.S.S. The .idup is a bit ugly, but necessary, since apparently > > byLine() calls readln() with a static buffer, so choice will be > > silently overwritten if the .idup is omitted. > > An alternative File API that to

Re: File Api [Was: [your code here]]

2012-02-17 Thread Timon Gehr
On 02/18/2012 03:20 AM, bearophile wrote: H. S. Teoh: P.S.S. The .idup is a bit ugly, but necessary, since apparently byLine() calls readln() with a static buffer, so choice will be silently overwritten if the .idup is omitted. An alternative File API that to me looks nice. This is a first pa

Re: [your code here]

2012-02-17 Thread Timon Gehr
On 02/18/2012 03:16 AM, H. S. Teoh wrote: On Sat, Feb 18, 2012 at 02:52:15AM +0100, Alf P. Steinbach wrote: On 18.02.2012 02:39, H. S. Teoh wrote: // Outputs a randomly selected line from standard input with equal // likelihood. import std.random; import std.stdio; void main() { auto n

Re: [your code here]

2012-02-17 Thread Andrej Mitrovic
Is this D1 code? You can't use writef with a format specifier and no arguments.

File Api [Was: [your code here]]

2012-02-17 Thread bearophile
H. S. Teoh: > P.S.S. The .idup is a bit ugly, but necessary, since apparently byLine() > calls readln() with a static buffer, so choice will be silently > overwritten if the .idup is omitted. An alternative File API that to me looks nice. This is a first part, it's for scripting-like or not high

Re: [your code here]

2012-02-17 Thread Jonathan M Davis
On Friday, February 17, 2012 21:03:43 Matt Soucy wrote: > On 02/17/2012 08:13 PM, Jonathan M Davis wrote: > > On Friday, February 17, 2012 18:50:32 Matt Soucy wrote: > >> #!/usr/bin/rdmd > >> import std.stdio; > >> void main() > >> { > >> uint guesses=0, high=100, low=0, guess=50; > >> char returne

Re: [your code here]

2012-02-17 Thread Matt Soucy
On 02/17/2012 08:57 PM, Jonathan M Davis wrote: On Saturday, February 18, 2012 02:53:44 Timon Gehr wrote: If you want it to be executable as a script, rdmd works just fine. But is there any guarantee that rdmd will even be on the system? It seems much safer to me to use dmd, since dmd _will_ b

Re: [your code here]

2012-02-17 Thread H. S. Teoh
On Sat, Feb 18, 2012 at 02:52:15AM +0100, Alf P. Steinbach wrote: > On 18.02.2012 02:39, H. S. Teoh wrote: > >// Outputs a randomly selected line from standard input with equal > >// likelihood. > >import std.random; > >import std.stdio; > > > >void main() { > > auto n = 0; > > string choic

Re: [your code here]

2012-02-17 Thread Timon Gehr
On 02/18/2012 02:52 AM, Alf P. Steinbach wrote: On 18.02.2012 02:39, H. S. Teoh wrote: // Outputs a randomly selected line from standard input with equal // likelihood. import std.random; import std.stdio; void main() { auto n = 0; string choice; foreach (line; stdin.byLine()) {

Re: [your code here]

2012-02-17 Thread Matt Soucy
On 02/17/2012 08:13 PM, Jonathan M Davis wrote: On Friday, February 17, 2012 18:50:32 Matt Soucy wrote: #!/usr/bin/rdmd import std.stdio; void main() { uint guesses=0, high=100, low=0, guess=50; char returned; writef("Please choose a number between %s and %s.\n"); writef("Press enter to begin.",

Re: [your code here]

2012-02-17 Thread Matt Soucy
Thank you, however I feel that using the case 'y','Y': demonstrates another feature that C/C++ doesn't have. I'm aware of those two functions. ...although in the middle of testing this I realized that "guesses=0" should have been "guesses=1". Whoops. On 02/17/2012 08:07 PM, MattCodr wrote: Ni

Re: [your code here]

2012-02-17 Thread Jonathan M Davis
On Saturday, February 18, 2012 02:53:44 Timon Gehr wrote: > If you want it to be executable as a script, rdmd works just fine. But is there any guarantee that rdmd will even be on the system? It seems much safer to me to use dmd, since dmd _will_ be there if you're programming in D, but rdmd may

Re: [your code here]

2012-02-17 Thread Timon Gehr
On 02/18/2012 02:13 AM, Jonathan M Davis wrote: On Friday, February 17, 2012 18:50:32 Matt Soucy wrote: #!/usr/bin/rdmd import std.stdio; void main() { uint guesses=0, high=100, low=0, guess=50; char returned; writef("Please choose a number between %s and %s.\n"); writef("Press enter to begin.",

Re: [your code here]

2012-02-17 Thread Alf P. Steinbach
On 18.02.2012 02:39, H. S. Teoh wrote: // Outputs a randomly selected line from standard input with equal // likelihood. import std.random; import std.stdio; void main() { auto n = 0; string choice; foreach (line; stdin.byLine()) { n++; if

[your code here]

2012-02-17 Thread H. S. Teoh
// Outputs a randomly selected line from standard input with equal // likelihood. import std.random; import std.stdio; void main() { auto n = 0; string choice; foreach (line; stdin.byLine()) { n++; if (uniform(0,n) == 0)

Re: [your code here]

2012-02-17 Thread Jonathan M Davis
On Friday, February 17, 2012 18:50:32 Matt Soucy wrote: > #!/usr/bin/rdmd > import std.stdio; > void main() > { > uint guesses=0, high=100, low=0, guess=50; > char returned; > writef("Please choose a number between %s and %s.\n"); > writef("Press enter to begin.",low,high); > readln(); > checkLoop:

Re: [your code here]

2012-02-17 Thread MattCodr
Nice, but just a little thing: switch(toUpper(returned)) { case 'Y': break checkLoop; case 'H': {low=guess; break;} case 'L': {high=guess; break;} default: break; } PS: Yeah you can you tolower() too! On Friday, 17 February 2012 at 23:50:32 UTC, Matt Soucy wrote: #!/us

[your code here]

2012-02-17 Thread Matt Soucy
#!/usr/bin/rdmd import std.stdio; void main() { uint guesses=0, high=100, low=0, guess=50; char returned; writef("Please choose a number between %s and %s.\n"); writef("Press enter to begin.",low,high); readln(); checkLoop: do { guess = (high-low)/2+low; // Avoi

Re: [your code here]

2012-02-17 Thread Andrei Alexandrescu
On 2/17/12 2:33 PM, Joshua Niehus wrote: Not as fancy as the other submits, but it might be worthy of the front page: import std.stdio, std.traits; void main(string[] args) { auto foo(T)(T n) { return delegate(T i) { static if (isSomeString!(T)) auto m = mixin("n ~ i"); else auto m = mixin("n +

Re: [your code here]

2012-02-17 Thread Jose Armando Garcia
On Fri, Feb 17, 2012 at 6:33 PM, Joshua Niehus wrote: > Not as fancy as the other submits, but it might be worthy of the front page: > > import std.stdio, std.traits; > > void main(string[] args) { >    auto foo(T)(T n) { >        return delegate(T i) { >            static if (isSomeString!(T)) >

[your code here]

2012-02-17 Thread Joshua Niehus
Not as fancy as the other submits, but it might be worthy of the front page: import std.stdio, std.traits; void main(string[] args) { auto foo(T)(T n) { return delegate(T i) { static if (isSomeString!(T)) auto m = mixin("n ~ i"); else

Re: [your code here]

2012-02-11 Thread Kapps
On 11/02/2012 9:55 AM, H. S. Teoh wrote: The bad thing about taking signed long as parameter and then restrict it to 0..uint.max means that you're unnecessarily constraining the domain of the function. T In this case, you're actually not changing the domain of the function. The domain was (

Re: [your code here]

2012-02-11 Thread Jos van Uden
On 11-2-2012 16:30, H. S. Teoh wrote: On Sat, Feb 11, 2012 at 12:20:22PM +0100, Jos van Uden wrote: bool isKaprekar(in long n) pure nothrow in { assert(n> 0, "isKaprekar(n): n must be> 0"); assert(n<= uint.max, "isKaprekar(n): n must be<= uint.max"); } body { [...] Shouldn't you ju

Re: [your code here]

2012-02-11 Thread H. S. Teoh
On Sat, Feb 11, 2012 at 10:47:01AM -0500, bearophile wrote: > H. S. Teoh: > > > > bool isKaprekar(in long n) pure nothrow > > > in { > > > assert(n > 0, "isKaprekar(n): n must be > 0"); > > > assert(n <= uint.max, "isKaprekar(n): n must be <= uint.max"); > > > } body { > > [...] > > > > S

Re: [your code here]

2012-02-11 Thread bearophile
H. S. Teoh: > > bool isKaprekar(in long n) pure nothrow > > in { > > assert(n > 0, "isKaprekar(n): n must be > 0"); > > assert(n <= uint.max, "isKaprekar(n): n must be <= uint.max"); > > } body { > [...] > > Shouldn't you just use "in ulong n" as parameter instead of long with a > contrac

Re: [your code here]

2012-02-11 Thread H. S. Teoh
On Sat, Feb 11, 2012 at 12:20:22PM +0100, Jos van Uden wrote: > bool isKaprekar(in long n) pure nothrow > in { > assert(n > 0, "isKaprekar(n): n must be > 0"); > assert(n <= uint.max, "isKaprekar(n): n must be <= uint.max"); > } body { [...] Shouldn't you just use "in ulong n" as parameter

[your code here]

2012-02-11 Thread Jos van Uden
bool isKaprekar(in long n) pure nothrow in { assert(n > 0, "isKaprekar(n): n must be > 0"); assert(n <= uint.max, "isKaprekar(n): n must be <= uint.max"); } body { ulong powr = n ^^ 2UL; ulong tens = 10, r, l; while (r < n) { r = powr % tens; l = powr / tens;

Re: [your code here]

2012-02-11 Thread Jos van Uden
S rot13(S)(S s) if (isSomeString!S) { return rot(s, 13); } S rot(S)(S s, int key) if (isSomeString!S) { auto r = new dchar[s.walkLength()]; foreach (i, dchar c; s) { if (isLower(c)) r[i] = ((c - 'a' + key) % 26 + 'a'); else if (isUpper(c)) r[i] = ((c - 'A' + key) % 26 + 'A'); } return to!S(r); }

Re: [your code here]

2012-02-06 Thread Manfred Nowak
Andrei Alexandrescu wrote: > Would you want to redo the example No. I do not see the usefullness of a random ten liner shown on the frontpage of a programming language. If the goal is to attract the attention of a visitor to some feature of the language, that feature should be stated prominent

Re: [your code here]

2012-02-06 Thread Marco Leise
Am 06.02.2012, 07:38 Uhr, schrieb Era Scarecrow : mixin(T_isPangram("DE_isPangram", "abcdefghijklmnopqrstuvwxyz", "\\u00DF\\u00e4\\u00f6\\u00dc")); somehow this got mixed up with the earlier messed up one.. this is the correction for this line. mixin(T_isPangram("DE_isPangram", "abcdefghi

Re: [your code here]

2012-02-05 Thread Era Scarecrow
mixin(T_isPangram("DE_isPangram", "abcdefghijklmnopqrstuvwxyz", "\\u00DF\\u00e4\\u00f6\\u00dc")); somehow this got mixed up with the earlier messed up one.. this is the correction for this line. mixin(T_isPangram("DE_isPangram", "abcdefghijklmnopqrstuvwxyz", "\\u00DF\\u00e4\\u00f6\\u00fc"));

Re: [your code here]

2012-02-05 Thread Era Scarecrow
The optional third parameter of `indexOf' can be called with `CaseSensitive.no'. But that parameter is left untouched. Instead a check with `toUpper( c)' is used, thereby risking a further visitation of the whole string . Using CaseSensitive.no is a lot slower Hmmm then perhaps a whole re-wr

Re: [your code here]

2012-02-04 Thread Jos van Uden
On 5-2-2012 5:05, Manfred Nowak wrote: 2) The optional third parameter of `indexOf' can be called with `CaseSensitive.no'. But that parameter is left untouched. Instead a check with `toUpper( c)' is used, thereby risking a further visitation of the whole string . Using CaseSensitive.no is a lo

Re: [your code here]

2012-02-04 Thread Andrei Alexandrescu
On 2/4/12 10:05 PM, Manfred Nowak wrote: Jos van Uden wrote: bool isPangram The presented code is not an acceptable example for the usage of the D programming language. 1) `indexOf( s, c)' has a worst case running time of O( `s.length'). `indexOf' is called once for each `c' in the used memb

Re: [your code here]

2012-02-04 Thread Manfred Nowak
Jos van Uden wrote: > bool isPangram The presented code is not an acceptable example for the usage of the D programming language. 1) `indexOf( s, c)' has a worst case running time of O( `s.length'). `indexOf' is called once for each `c' in the used member `alpha' of `Alphabet'. Therefore the

Re: [your code here]

2012-02-04 Thread Timon Gehr
On 02/04/2012 09:38 PM, Manfred Nowak wrote: Tobias Pankrath wrote: Quote from dlang.org Got a brief example illustrating D? Submit your code to the digitalmars.D forum, specifying "[your code here]" in the title. I doubt that the author of that text indeed wanted some hundred co

Re: [your code here]

2012-02-04 Thread Manfred Nowak
Tobias Pankrath wrote: > Quote from dlang.org >> Got a brief example illustrating D? Submit your code to the >> digitalmars.D forum, specifying "[your code here]" in the title. I doubt that the author of that text indeed wanted some hundred contributers and lurkers to s

Re: [your code here]

2012-02-04 Thread Timon Gehr
them is in D.learn. Bye, bearophile 'Got a brief example illustrating D? Submit your code to the ***digitalmars.D*** forum, specifying "[your code here]" in the title. Upon approval, it will be showcased on a random schedule on D‘s homepage.' I completely agree with t

Re: [your code here]

2012-02-04 Thread bearophile
Manfred Nowak: > Because such definitions do not contribute to D as a programming > language, I believe that such threads do not belong into the D-forum. > etc. Because we are gentle and tolerant people, we tolerate those posts, despite a better place for them is in D.learn. Bye, bearophile

Re: [your code here]

2012-02-04 Thread Tobias Pankrath
er forums are for specific themes a D.misc-forum > should be the right place for such threads---but it is missing. > > -manfred Quote from dlang.org > Got a brief example illustrating D? Submit your code to the digitalmars.D forum, specifying "[your code here]" in the title. Upon approval, it will be showcased on a random schedule on D‘s homepage.

Re: [your code here]

2012-02-04 Thread Manfred Nowak
Jos van Uden wrote: > A pangram is a sentence that contains every letter of a given > alphabet at least once. 1) Because such definitions do not contribute to D as a programming language, I believe that such threads do not belong into the D-forum. 2) Because solutions are presented, I believe t

Re: [your code here]

2012-02-04 Thread Jos van Uden
On 4-2-2012 14:14, bearophile wrote: Jos van Uden: See: http://rosettacode.org/wiki/Pangram_checker#D Yeah, it's mine. And I bet the other one is yours :-)

Re: [your code here]

2012-02-04 Thread bearophile
Jos van Uden: See: http://rosettacode.org/wiki/Pangram_checker#D Bye, bearophile

[your code here]

2012-02-04 Thread Jos van Uden
import std.string, std.traits, std.uni; enum Alphabet : dstring { DE = "abcdefghijklmnopqrstuvwxyzßäöü", EN = "abcdefghijklmnopqrstuvwxyz", SV = "abcdefghijklmnopqrstuvwxyzåäö" } bool isPangram(S)(S s, dstring alpha = Alphabet.EN) if (isSomeString!S) { foreach (c; alpha)

Re: [your code here]

2012-01-29 Thread Jos van Uden
On 29-1-2012 7:55, Manfred Nowak wrote: Jos van Uden wrote: BufferedFile("ukacd17.txt"); Me got an unicode-error on that file on line 100. -manfred The original file is encoded ISO 8859-1. You'll have to convert it to utf-8. My earlier code sample used the unixdict.txt that I found here h

Re: [your code here]

2012-01-28 Thread Manfred Nowak
Jos van Uden wrote: > BufferedFile("ukacd17.txt"); Me got an unicode-error on that file on line 100. -manfred

Re: [your code here]

2012-01-28 Thread Joshua Niehus
I ran this code on Mac OSX Lion using the "/usr/share/dict/words" file and got 235834 words out of 235886. I think something is wrong. found the problem: PEBKAC (problem exists between keyboard and chair) sorry:)

Re: [your code here]

2012-01-28 Thread Joshua Niehus
import std.stdio, std.stream, std.string, std.range, std.algorithm; void main() { int countPalindromes; auto infile = new BufferedFile("ukacd17.txt"); foreach (char[] line; infile) { if (line.walkLength(2) > 1) { line.toLowerInPlace; if (equal(line, retro(li

Re: [your code here]

2012-01-28 Thread Jos van Uden
On 28-1-2012 16:07, Andrei Alexandrescu wrote: import std.stdio, std.stream, std.string, std.range, std.algorithm; void main() { int countPalindromes; auto infile = new BufferedFile("unixdict.txt"); foreach (char[] line; infile) { if (line.walkLength > 1) { line.toLowerInPlace; if (equal(line,

Re: [your code here]

2012-01-28 Thread Andrei Alexandrescu
On 1/28/12 8:21 AM, Jos van Uden wrote: if (line.walkLength > 1) { if (line.walkLength(2) > 1) { Andrei

Re: [your code here]

2012-01-28 Thread Andrei Alexandrescu
On 1/28/12 8:21 AM, Jos van Uden wrote: On 28-1-2012 14:57, Mantis wrote: 28.01.2012 15:31, Jos van Uden пишет: import std.stdio, std.stream, std.string, std.range; void main() { int countPalindromes; auto infile = new BufferedFile("unixdict.txt"); foreach (char[] line; infile) { if (line.walk

Re: [your code here]

2012-01-28 Thread Jos van Uden
On 28-1-2012 14:57, Mantis wrote: 28.01.2012 15:31, Jos van Uden пишет: import std.stdio, std.stream, std.string, std.range; void main() { int countPalindromes; auto infile = new BufferedFile("unixdict.txt"); foreach (char[] line; infile) { if (line.walkLength > 1) { line.toLowerInPlace; if (li

Re: [your code here]

2012-01-28 Thread Andrei Alexandrescu
On 1/28/12 7:31 AM, Jos van Uden wrote: import std.stdio, std.stream, std.string, std.range; void main() { int countPalindromes; auto infile = new BufferedFile("unixdict.txt"); foreach (char[] line; infile) { if (line.walkLength > 1) { line.toLowerInPlace; if (line == line.dup.reverse) countPali

Re: [your code here]

2012-01-28 Thread Mantis
28.01.2012 15:31, Jos van Uden пишет: import std.stdio, std.stream, std.string, std.range; void main() { int countPalindromes; auto infile = new BufferedFile("unixdict.txt"); foreach (char[] line; infile) { if (line.walkLength > 1) { line.toLowerInPlace; if (line == line.dup.reverse) countPalind

[your code here]

2012-01-28 Thread Jos van Uden
import std.stdio, std.stream, std.string, std.range; void main() { int countPalindromes; auto infile = new BufferedFile("unixdict.txt"); foreach (char[] line; infile) { if (line.walkLength > 1) { line.toLowerInPlace; if (line == line.dup.reverse)

[OT] Re: [your code here]

2012-01-15 Thread Nick Sabalausky
"Andrei Alexandrescu" wrote in message news:jeuqua$1gfg$3...@digitalmars.com... > > Thanks! Well, we don't have yet the javascript that rotates the examples. > Would anyone be interested to work on that? > Speaking of d-p-l.org contributions, #39 has been merged and could use to be put up on t

Re: [your code here]

2012-01-15 Thread Jos van Uden
On 15-1-2012 17:26, Timon Gehr wrote: On 01/15/2012 03:23 PM, Jos van Uden wrote: import std.conv, std.traits, std.ascii; S rot13(S)(S s) if (isSomeString!S) { return rot(s, 13); } S rot(S)(S s, int key) if (isSomeString!S) { dchar[] r = new dchar[s.length]; foreach (i, dchar c; s) { if (isLo

Re: [your code here]

2012-01-15 Thread Timon Gehr
On 01/15/2012 03:23 PM, Jos van Uden wrote: import std.conv, std.traits, std.ascii; S rot13(S)(S s) if (isSomeString!S) { return rot(s, 13); } S rot(S)(S s, int key) if (isSomeString!S) { dchar[] r = new dchar[s.length]; foreach (i, dchar c; s) { if (isLower(c)) c = ((c - 'a' + key) % 26 + 'a'

Re: [your code here]

2012-01-15 Thread Andrei Alexandrescu
On 1/15/12 9:26 AM, bearophile wrote: Andrei Alexandrescu: Thanks! Well, we don't have yet the javascript that rotates the examples. Would anyone be interested to work on that? Do you want a large amount of D2 "examples"? Have you seen this page? http://rosettacode.org/wiki/Category:D Bye, b

Re: [your code here]

2012-01-15 Thread bearophile
Andrei Alexandrescu: > Thanks! Well, we don't have yet the javascript that rotates the > examples. Would anyone be interested to work on that? Do you want a large amount of D2 "examples"? Have you seen this page? http://rosettacode.org/wiki/Category:D Bye, bearophile

Re: [your code here]

2012-01-15 Thread Andrei Alexandrescu
On 1/15/12 8:23 AM, Jos van Uden wrote: import std.conv, std.traits, std.ascii; S rot13(S)(S s) if (isSomeString!S) { return rot(s, 13); } S rot(S)(S s, int key) if (isSomeString!S) { dchar[] r = new dchar[s.length]; foreach (i, dchar c; s) { if (isLower(c)) c = ((c - 'a' + key) % 26 + 'a'); e

Re: [your code here]

2012-01-15 Thread bearophile
Jos van Uden: > still learning this stuff, feel free to correct or improve Next time I suggest you to use D.learn. This is a first draft with some changes: import std.traits, std.string, std.ascii, std.conv, std.range; // is partial application better here? dstring rot13(C)(immutable(C[]) s) p

[your code here]

2012-01-15 Thread Jos van Uden
import std.conv, std.traits, std.ascii; S rot13(S)(S s) if (isSomeString!S) { return rot(s, 13); } S rot(S)(S s, int key) if (isSomeString!S) { dchar[] r = new dchar[s.length]; foreach (i, dchar c; s) { if (isLower(c)) c = ((c - 'a' + key) % 26 + 'a'); el

<    1   2