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. :)
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
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).
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,
// 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
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
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
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
// 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
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");`;
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
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
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
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
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
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
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
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
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
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
Is this D1 code? You can't use writef with a format specifier and no arguments.
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
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
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
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
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()) {
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.",
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
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
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.",
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
// 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)
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:
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
#!/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
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 +
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))
>
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
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 (
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
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
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
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
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;
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);
}
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
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
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"));
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
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
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
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
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
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
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
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
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.
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
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 :-)
Jos van Uden:
See:
http://rosettacode.org/wiki/Pangram_checker#D
Bye,
bearophile
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)
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
Jos van Uden wrote:
> BufferedFile("ukacd17.txt");
Me got an unicode-error on that file on line 100.
-manfred
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:)
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
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,
On 1/28/12 8:21 AM, Jos van Uden wrote:
if (line.walkLength > 1) {
if (line.walkLength(2) > 1) {
Andrei
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
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
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
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
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)
"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
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
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'
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
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
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
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
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
101 - 180 of 180 matches
Mail list logo