Re: How do I simulate variadic parameters for template (range) functions?

2011-08-24 Thread Jacob Carlborg
On 2011-08-24 19:40, Andrej Mitrovic wrote: Here's what I can do with a variadic function: void main() { int[] a = [ 1, 2, 4, 7, 7, 2, 4, 7, 3, 5]; process(a[a.countUntil(7) .. $]); process(1); } void process(int[] vals...) { foreach (val; vals) { } } Very simple

Re: Default libraries by dmd

2011-08-24 Thread Jesse Phillips
On Thu, 25 Aug 2011 04:46:11 +, Cleem wrote: > What libraries are linked by command dmd as linker? I want to use g++ as > linker and link phobos2 and druntime libraries. But there are some > undefined references, for example: > _D3std4conv13ConvException7__ClassZ > _D3std4conv16__T5parseTlTAya

Re: Default libraries by dmd

2011-08-24 Thread Jonathan M Davis
On Thursday, August 25, 2011 04:46:11 Cleem wrote: > What libraries are linked by command dmd as linker? I want to use g++ > as linker and link phobos2 and druntime libraries. But there are some > undefined references, for example: > _D3std4conv13ConvException7__ClassZ > _D3std4conv16__T5parseTlTAy

Re: Split by length?

2011-08-24 Thread Vladimir Panteleev
On Mon, 15 Aug 2011 05:49:59 +0300, Andrej Mitrovic wrote: Is there something in Phobos with which I could do: auto arr = [1, 2, 3, 4, 5, 6]; int[][] newarr = arr.splitLength(2); assert(newarr.length == 3); Almost but not quite: auto newarr = cast(int[2][])arr; -- Best regards, Vladimir

Default libraries by dmd

2011-08-24 Thread Cleem
What libraries are linked by command dmd as linker? I want to use g++ as linker and link phobos2 and druntime libraries. But there are some undefined references, for example: _D3std4conv13ConvException7__ClassZ _D3std4conv16__T5parseTlTAyaZ5parseFKAyaZl _D3std5ascii7isDigitFNaNbNfwZb _d_arraysetcap

Re: Why no (auto foo = bar) in while loops?

2011-08-24 Thread Timon Gehr
On 08/25/2011 12:47 AM, Mafi wrote: Am 24.08.2011 21:04, schrieb Timon Gehr: On 08/24/2011 08:04 PM, Andrej Mitrovic wrote: Here's some code that iterates through "parents" of some class object until it finds an object with no parent (where parent is null): import std.stdio; class Foo { Foo p

Re: Why no (auto foo = bar) in while loops?

2011-08-24 Thread Mafi
Am 24.08.2011 21:04, schrieb Timon Gehr: On 08/24/2011 08:04 PM, Andrej Mitrovic wrote: Here's some code that iterates through "parents" of some class object until it finds an object with no parent (where parent is null): import std.stdio; class Foo { Foo parent; int state; this (int state) {

Re: Why no (auto foo = bar) in while loops?

2011-08-24 Thread Andrej Mitrovic
Req'd: http://d.puremagic.com/issues/show_bug.cgi?id=6550

Re: Why no (auto foo = bar) in while loops?

2011-08-24 Thread Timon Gehr
On 08/24/2011 09:36 PM, Jonathan M Davis wrote: On Wednesday, August 24, 2011 21:29:23 Timon Gehr wrote: On 08/24/2011 09:21 PM, Andrej Mitrovic wrote: On 8/24/11, Timon Gehr wrote: it is usually faster in debug mode Huh.. How come? Well, not notably faster, but many compilers will emit

Re: Why no (auto foo = bar) in while loops?

2011-08-24 Thread Jonathan M Davis
On Wednesday, August 24, 2011 21:29:23 Timon Gehr wrote: > On 08/24/2011 09:21 PM, Andrej Mitrovic wrote: > > On 8/24/11, Timon Gehr wrote: > >> it is usually faster > >> in debug mode > > > > Huh.. How come? > > Well, not notably faster, but many compilers will emit something in the > lines of

Re: Why no (auto foo = bar) in while loops?

2011-08-24 Thread Timon Gehr
On 08/24/2011 09:21 PM, Andrej Mitrovic wrote: On 8/24/11, Timon Gehr wrote: it is usually faster in debug mode Huh.. How come? Well, not notably faster, but many compilers will emit something in the lines of mov eax, 1 test eax jnz beginning_of_loop if no optimizer is run, whereas mos

Re: Why no (auto foo = bar) in while loops?

2011-08-24 Thread Andrej Mitrovic
On 8/24/11, Timon Gehr wrote: > it is usually faster > in debug mode Huh.. How come?

Re: Why no (auto foo = bar) in while loops?

2011-08-24 Thread Timon Gehr
On 08/24/2011 08:04 PM, Andrej Mitrovic wrote: Here's some code that iterates through "parents" of some class object until it finds an object with no parent (where parent is null): import std.stdio; class Foo { Foo parent; int state; this (int state) { this.state = state; } } v

Re: How do I simulate variadic parameters for template (range) functions?

2011-08-24 Thread Jonathan M Davis
On Wednesday, August 24, 2011 11:00 Timon Gehr wrote: > On 08/24/2011 07:54 PM, Steven Schveighoffer wrote: > > On Wed, 24 Aug 2011 13:40:38 -0400, Andrej Mitrovic > > > > wrote: > >> Here's what I can do with a variadic function: > >> > >> void main() > >> { > >> int[] a = [ 1, 2, 4, 7, 7, 2, 4

Re: links to nested structure

2011-08-24 Thread Adam Ruppe
Yeah, it should work with any level of nesting. If toPrettyChars() doesn't work out, my parent plan is actually more like: auto item = this.parent; while(item) { str ~= "." ~ item.toChars(); item = this.parent; } so it'd go any level needed.

Re: reading in text files

2011-08-24 Thread Jesse Phillips
Brian Brady Wrote: > but it just hangs there, not doing anything(for a considerable time) so I am > assuming I am doing something wrong. There isn't any actual mention in the > book of *how* reading in the text file should be accomplished, so what is the > best way to do this? Now that you know h

Re: Why no (auto foo = bar) in while loops?

2011-08-24 Thread Andrej Mitrovic
P.S. I'm aware I'm loosing the reference to the first foo object but this is just demonstration code.

Re: links to nested structure

2011-08-24 Thread jdrewsen
Den 23-08-2011 22:38, Adam D. Ruppe skrev: Jonathan M Davis wrote: I'm fairly certain that the anchors are generated by ddoc, not std.ddoc Well, it's a bit of both. DDOC_PSYMBOL =$(U $0) Looking at doc.c, DDOC_PSYMBOL is used in the toDocBuffer() methods. The paramater to it is always this.t

Re: How do I simulate variadic parameters for template (range) functions?

2011-08-24 Thread Timon Gehr
On 08/24/2011 07:54 PM, Steven Schveighoffer wrote: On Wed, 24 Aug 2011 13:40:38 -0400, Andrej Mitrovic wrote: Here's what I can do with a variadic function: void main() { int[] a = [ 1, 2, 4, 7, 7, 2, 4, 7, 3, 5]; process(a[a.countUntil(7) .. $]); process(1); } void process(int[] vals...)

Why no (auto foo = bar) in while loops?

2011-08-24 Thread Andrej Mitrovic
Here's some code that iterates through "parents" of some class object until it finds an object with no parent (where parent is null): import std.stdio; class Foo { Foo parent; int state; this (int state) { this.state = state; } } void main() { auto foo = new Foo(0);

Re: How do I simulate variadic parameters for template (range) functions?

2011-08-24 Thread Steven Schveighoffer
On Wed, 24 Aug 2011 13:40:38 -0400, Andrej Mitrovic wrote: Here's what I can do with a variadic function: void main() { int[] a = [ 1, 2, 4, 7, 7, 2, 4, 7, 3, 5]; process(a[a.countUntil(7) .. $]); process(1); } void process(int[] vals...) { foreach (val; vals) { } }

Re: How do I simulate variadic parameters for template (range) functions?

2011-08-24 Thread Timon Gehr
On 08/24/2011 07:40 PM, Andrej Mitrovic wrote: Here's what I can do with a variadic function: void main() { int[] a = [ 1, 2, 4, 7, 7, 2, 4, 7, 3, 5]; process(a[a.countUntil(7) .. $]); process(1); } void process(int[] vals...) { foreach (val; vals) { } } Very sim

How do I simulate variadic parameters for template (range) functions?

2011-08-24 Thread Andrej Mitrovic
Here's what I can do with a variadic function: void main() { int[] a = [ 1, 2, 4, 7, 7, 2, 4, 7, 3, 5]; process(a[a.countUntil(7) .. $]); process(1); } void process(int[] vals...) { foreach (val; vals) { } } Very simple, pass one or multiple arguments. But then I thought

Re: reading in text files

2011-08-24 Thread Cristi Cobzarenco
The program reads the "file" from stdin, so you need to redirect stdin to the file you want: try "./readingHamlet < hamlet.txt" or "cat hamlet.txt | ./readingHamlet" without the quotes on a *NIX system. --- Cristi Cobzarenco BSc in Artificial Intelligence and Computer Science University of Edinbur

Re: reading in text files

2011-08-24 Thread Christophe
> The default stdin doesn't have an end, and unless you type something > in, there's no input at all. That's why the program just hangs. You can end keyboard stdin by typing ^D (Ctrl + D) under unix.

Re: What's the technical reason that class ctors aren't virtual?

2011-08-24 Thread Jacob Carlborg
On 2011-08-24 16:59, Andrej Mitrovic wrote: class Foo { this(int x, int y) { } } class Bar : Foo { } Bar has to define its own ctor even if it only forwards the call to the super() ctor, e.g.: class Bar : Foo { this(int x, int y) { super(x, y); } } But I'm curious why this works thi

Re: What's the technical reason that class ctors aren't virtual?

2011-08-24 Thread Ary Manzana
On 8/24/11 12:27 PM, Ali Çehreli wrote: On Wed, 24 Aug 2011 16:59:46 +0200, Andrej Mitrovic wrote: class Foo { this(int x, int y) { } } class Bar : Foo { } Bar has to define its own ctor even if it only forwards the call to the super() ctor, e.g.: class Bar : Foo { this(int x, int

Re: What's the technical reason that class ctors aren't virtual?

2011-08-24 Thread Ali Çehreli
On Wed, 24 Aug 2011 16:59:46 +0200, Andrej Mitrovic wrote: > class Foo > { > this(int x, int y) { } > } > > class Bar : Foo > { > } > > Bar has to define its own ctor even if it only forwards the call to the > super() ctor, e.g.: > > class Bar : Foo > { > this(int x, int y) { super(x, y

What's the technical reason that class ctors aren't virtual?

2011-08-24 Thread Andrej Mitrovic
class Foo { this(int x, int y) { } } class Bar : Foo { } Bar has to define its own ctor even if it only forwards the call to the super() ctor, e.g.: class Bar : Foo { this(int x, int y) { super(x, y); } } But I'm curious why this works this way. If I have a large inheritance tree of cla

Re: reading in text files

2011-08-24 Thread Andrej Mitrovic
Maybe ./readingHamlet < hamlet.txt

Re: reading in text files

2011-08-24 Thread Brian Brady
== Quote from Johannes Pfau (s...@example.com)'s article > Brian Brady wrote: > >All > > > >I am working through Andrei Alexandrescus "The D Programming Language" > >but have hit a road block fairly early on. > > > >There is a program in the book which is designed to read through a > >text file and

Re: reading in text files

2011-08-24 Thread Steven Schveighoffer
On Wed, 24 Aug 2011 10:25:18 -0400, Johannes Pfau wrote: On Linux/unix you can for example pipe the output from one command to another: cat hamlet.txt | ./readingHamlet this way readingHamlet's standard input is connected to cat's standard output. I believe in all OSes (Windows included) ./

Re: reading in text files

2011-08-24 Thread Johannes Pfau
Brian Brady wrote: >All > >I am working through Andrei Alexandrescus "The D Programming Language" >but have hit a road block fairly early on. > >There is a program in the book which is designed to read through a >text file and do a simple word count. The program looks like this: > >import std.stdio

reading in text files

2011-08-24 Thread Brian Brady
All I am working through Andrei Alexandrescus "The D Programming Language" but have hit a road block fairly early on. There is a program in the book which is designed to read through a text file and do a simple word count. The program looks like this: import std.stdio, std.string; void main() {

Re: How do "pure" member functions work?

2011-08-24 Thread Don
Simen Kjaeraas wrote: On Mon, 22 Aug 2011 22:19:50 +0200, Don wrote: BTW: The whole "weak pure"/"strong pure" naming was just something I came up with, to convince Walter to relax the purity rules. I'd rather those names disappeared, they aren't very helpful. The concepts are useful, but be

Re: links to nested structure

2011-08-24 Thread Johannes Pfau
Adam D. Ruppe wrote: >Jonathan M Davis wrote: >> I'm fairly certain that the anchors are generated by ddoc, not >> std.ddoc > >Well, it's a bit of both. > >DDOC_PSYMBOL = $(U $0) > >Looking at doc.c, DDOC_PSYMBOL is used in the toDocBuffer() methods. >The paramater to it is always this.toChars(). >