digitalmars.D - [your code here]
- Jos van Uden (16/16) Feb 04 2012 import std.string, std.traits, std.uni;
- bearophile (5/5) Feb 04 2012 Jos van Uden:
- Jos van Uden (2/5) Feb 04 2012 Yeah, it's mine. And I bet the other one is yours :-)
- Manfred Nowak (13/15) Feb 04 2012 1)
- Tobias Pankrath (4/26) Feb 04 2012 forum, specifying "[your code here]" in the title. Upon approval, it wil...
- Manfred Nowak (11/14) Feb 04 2012 I doubt that the author of that text indeed wanted some hundred
- Timon Gehr (3/17) Feb 04 2012 This post is not making any sense. I kindly request the author to
- bearophile (4/7) Feb 04 2012 Because we are gentle and tolerant people, we tolerate those posts, desp...
- Timon Gehr (5/12) Feb 04 2012 'Got a brief example illustrating D? Submit your code to the
- Manfred Nowak (22/23) Feb 04 2012 The presented code is not an acceptable example for the usage of the D
- Andrei Alexandrescu (3/24) Feb 04 2012 Sensible arguments. Would you want to redo the example in better style?
- Manfred Nowak (9/10) Feb 06 2012 No.
- Jos van Uden (2/7) Feb 04 2012 Using CaseSensitive.no is a lot slower
- Era Scarecrow (58/63) Feb 05 2012 Hmmm then perhaps a whole re-write. I've gotten this done,
- Era Scarecrow (4/6) Feb 05 2012 somehow this got mixed up with the earlier messed up one.. this
- Marco Leise (7/13) Feb 06 2012 Actually, yeah a bit Scarecrow like. For dlang or rosettacode I prefer
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) if (indexOf(s, c) == -1 && indexOf(s, toUpper(c)) == -1) return false; return true; } --- A pangram is a sentence that contains every letter of a given alphabet at least once. A classic example is "The quick brown fox jumps over the lazy dog".
Feb 04 2012
Jos van Uden: See: http://rosettacode.org/wiki/Pangram_checker#D Bye, bearophile
Feb 04 2012
On 4-2-2012 14:14, bearophile wrote:Jos van Uden: See: http://rosettacode.org/wiki/Pangram_checker#DYeah, it's mine. And I bet the other one is yours :-)
Feb 04 2012
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 that such threads do neither belong into the D.learn-forum. 3) Because no general usability is visible I doubt, that such threads belong into the D.announce-forum. 4) Because all other forums are for specific themes a D.misc-forum should be the right place for such threads---but it is missing. -manfred
Feb 04 2012
Manfred Nowak wrote:Jos van Uden wrote:Quote from dlang.orgA 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 that such threads do neither belong into the D.learn-forum. 3) Because no general usability is visible I doubt, that such threads belong into the D.announce-forum. 4) Because all other forums are for specific themes a D.misc-forum should be the right place for such threads---but it is missing. -manfredGot a brief example illustrating D? Submit your code to the digitalmars.Dforum, specifying "[your code here]" in the title. Upon approval, it will be showcased on a random schedule on D‘s homepage.
Feb 04 2012
Tobias Pankrath wrote:Quote from dlang.orgI doubt that the author of that text indeed wanted some hundred contributers and lurkers to see this title pop up some hundred times and stay amused. digitalmars.D.misc or digitalmars.D.propaganda would be good places to not distract interested people from the language. Furthermore I believe, that the costs for creating a new digitalmars.D.abc group are negligible. For example digitalmars.D.debugger has fewer than 500 messages and about 80 threads within a time span of five years. -manfredGot a brief example illustrating D? Submit your code to the digitalmars.D forum, specifying "[your code here]" in the title.
Feb 04 2012
On 02/04/2012 09:38 PM, Manfred Nowak wrote:Tobias Pankrath wrote:This post is not making any sense. I kindly request the author to reconsider.Quote from dlang.orgI doubt that the author of that text indeed wanted some hundred contributers and lurkers to see this title pop up some hundred times and stay amused. digitalmars.D.misc or digitalmars.D.propaganda would be good places to not distract interested people from the language. Furthermore I believe, that the costs for creating a new digitalmars.D.abc group are negligible. For example digitalmars.D.debugger has fewer than 500 messages and about 80 threads within a time span of five years. -manfredGot a brief example illustrating D? Submit your code to the digitalmars.D forum, specifying "[your code here]" in the title.
Feb 04 2012
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
Feb 04 2012
On 02/04/2012 07:43 PM, bearophile wrote:Manfred Nowak:'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 the rest of your post though.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
Feb 04 2012
Jos van Uden wrote:bool isPangramThe 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 runtime of the presented code is O( `s.length' * `alpha.length') whereas O( `s.length' + `alpha.length') is possible. 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 . 3) The use of the literal value `-1' stands out of the code and hints to a maldesign in phobos. This is because `-1' is not mnemonic. -manfred
Feb 04 2012
On 2/4/12 10:05 PM, Manfred Nowak wrote:Jos van Uden wrote:Sensible arguments. Would you want to redo the example in better style? Andreibool isPangramThe 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 runtime of the presented code is O( `s.length' * `alpha.length') whereas O( `s.length' + `alpha.length') is possible. 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 . 3) The use of the literal value `-1' stands out of the code and hints to a maldesign in phobos. This is because `-1' is not mnemonic.
Feb 04 2012
Andrei Alexandrescu wrote:Would you want to redo the exampleNo. 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 prominently and the example code should be shown on request. At least such a goal is not obvious for this example. -manfred
Feb 06 2012
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 lot slower
Feb 04 2012
Hmmm then perhaps a whole re-write. I've gotten this done, although I'll need someone to tell me how well it does. Far as I can tell it's O(n). It's based loosely on the ascii version, except templatized. Hope it's not too ugly... import std.stdio, std.string, std.traits, std.uni, std.conv; string T_isPangram(string name, string set, string uset = "") { string x = "bool " ~ name ~ "(S)(S s) if (isSomeString!S) {\n"; if(set.length > 32) { x ~= "\tulong bitset;\n"; } else { x ~= "\tuint bitset;\n"; } x ~= "\tforeach(dchar c; s) {\n\t\tswitch(toLower(c)) {\n"; foreach(i, c; set) { x ~= "\t\t\tcase '" ~ c ~ "':"; x ~= "\tbitset |= 1 << " ~ to!string(i) ~ "; break;\n"; } int i = set.length; while(uset.length >= 6) { x ~= "\t\t\tcase '" ~ uset[0 .. 6] ~ "':"; x ~= "\tbitset |= 1 << " ~ to!string(i) ~ "; break;\n"; uset = uset[6 .. $]; i++; } x ~= "\t\t\tdefault:\n\t\t}\n\t}\n\treturn bitset == (1 << " ~ to!string(i) ~ ") - 1;\n}"; return x; } mixin(T_isPangram("EN_isPangram", "abcdefghijklmnopqrstuvwxyz")); mixin(T_isPangram("DE_isPangram", "abcdefghijklmnopqrstuvwxyz", "\\u00DF\\u00e4\\u00f6\\u00dc")); mixin(T_isPangram("SV_isPangram", "abcdefghijklmnopqrstuvwxyz", "\\u00e5\\u00e4\\u00f6")); unittest { writeln(T_isPangram("TEST_isPangram", "ab", "\\u00DF\\u00e4")); //example output below assert(!EN_isPangram("this doesn't cover everything")); assert(EN_isPangram("the quick brown fox jumps over the LAZY dog")); //to-lower check along with english assert(DE_isPangram("Falsches Üben von Xylophonmusik quält jeden größeren Zwerg")); assert(SV_isPangram("Yxskaftbud, ge vår wczonmö iqhjälp"w)); } /* bool TEST_isPangram(S)(S s) if (isSomeString!S) { uint bitset; foreach(dchar c; s) { switch(toLower(c)) { case 'a': bitset |= 1 << 0; break; case 'b': bitset |= 1 << 1; break; case '\u00DF': bitset |= 1 << 2; break; case '\u00e4': bitset |= 1 << 3; break; default: } } return bitset == (1 << 4) - 1; } */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
Feb 05 2012
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"));
Feb 05 2012
Am 06.02.2012, 07:38 Uhr, schrieb Era Scarecrow <rtcvb32 yahoo.com>:Actually, yeah a bit Scarecrow like. For dlang or rosettacode I prefer short and easy to read code. The one example where the result is checked against 0b11_1111111_11111111_11111111 was really nice, since it expresses the bit set nature in a concise and readable fashion. But it also shows that you can put integer literals in dual notation and place _ to segment the number.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"));
Feb 06 2012