Re: couple of really noob questions (ranges, toString)

2010-11-01 Thread Jonathan M Davis
On Monday 01 November 2010 19:21:27 spir wrote: > On Mon, 1 Nov 2010 18:47:38 -0700 > > Jonathan M Davis wrote: > > The best place to start learning about ranges is probably here: > > http://www.informit.com/articles/article.aspx?p=1407357 > > > > front, popFront(), and empty make perfect sense

Re: couple of really noob questions (ranges, toString)

2010-11-01 Thread Jesse Phillips
spir Wrote: > I'm certain its designer has a heavy Lisp baggage! I would rather have a > hasNext() and next() duo.] To build on what Jonathon wrote. There are three benefits that I have enjoyed having front and popFront instead of the next and hasNext. The first is simply that if I want to mak

Re: couple of really noob questions (ranges, toString)

2010-11-01 Thread spir
On Mon, 1 Nov 2010 18:47:38 -0700 Jonathan M Davis wrote: > The best place to start learning about ranges is probably here: > http://www.informit.com/articles/article.aspx?p=1407357 > > front, popFront(), and empty make perfect sense as they are and work quite > well. > hasNext() and next() h

Re: [D1, module, type conflict] Which bug is this?

2010-11-01 Thread %u
Disregard that, here is the real bug. I removed the circular struct definition. The code below results in: i.d(7): Error: b.B at b.d(5) conflicts with c.B at c.d(3) But if the selective imports are changed to non-selective public imports( bug[314] ) the error is gone. -- module main; import c;

Re: couple of really noob questions (ranges, toString)

2010-11-01 Thread Jonathan M Davis
On Monday 01 November 2010 18:05:19 spir wrote: > On Mon, 1 Nov 2010 20:02:14 + (UTC) > > Michael Woods wrote: > > I guess that I'm asking if write() calls an object's toString method > > Exactly. > > > Question 2: > > > > This is more a broad request for clarification, than a specific que

Re: couple of really noob questions (ranges, toString)

2010-11-01 Thread spir
On Mon, 1 Nov 2010 20:02:14 + (UTC) Michael Woods wrote: > I guess that I'm asking if write() calls an object's toString method Exactly. > Question 2: > > This is more a broad request for clarification, than a specific question. > I'm trying to understand the range interfaces. I'm tryi

[D1, module, type conflict] Which bug is this?

2010-11-01 Thread %u
The code below results in: i.d(7): Error: a.B at a.d(2) conflicts with c.B at c.d(4) changing main to only import i results in: b.d(4): Error: struct b.B unable to resolve forward reference in definition a.d(4): Error: struct a.A unable to resolve forward reference in definition repeated 5 times

Re: couple of really noob questions (ranges, toString)

2010-11-01 Thread Jesse Phillips
Michael Woods Wrote: > Thanks for your replies, bearophile and Jesse Phillips. :) > > Jesse, that makes a lot more sense, now. Thanks a lot for clearing > that up for me. > > Mike W I kept making the mistake of trying to use containers as a range too (end up creating a reset function to brin

Re: higher-order functions

2010-11-01 Thread bearophile
Jesse Phillips: > Since when? You are right, what I have said doesn't apply to map/filter. Sorry for my silly mistake. Bye, bearophile

Re: higher-order functions

2010-11-01 Thread Jesse Phillips
bearophile Wrote: > Simen kjaeraas: > > > They take both, in fact: > > > > auto cubes = map!((a){ return a*a*a; })(arr); > > But that needs to be compile-time constant, so if you have several functions, > you need to put them inside a typetuple, or duplicate the code. And some > idioms are ju

Re: couple of really noob questions (ranges, toString)

2010-11-01 Thread Michael Woods
Thanks for your replies, bearophile and Jesse Phillips. :) Jesse, that makes a lot more sense, now. Thanks a lot for clearing that up for me. Mike W

Re: exceptions thrown by new / object constructor ?

2010-11-01 Thread Jesse Phillips
I thought there was a Bug report on this, but I guess not. I say report it. Ether it should compile or the compiler should error that a constructor can not be nothrow.

Re: couple of really noob questions (ranges, toString)

2010-11-01 Thread Jesse Phillips
Hello and welcome. The toString does work the same as it does in Java, I suggest using override. override string toString(); Your error actually indicates a bug in Phobos. It has a special print function for classes and for an input range. These are conflicting with each other and has nothing

Re: Immutable struct fields

2010-11-01 Thread Dmitry Olshansky
On 02.11.2010 0:24, bearophile wrote: To answer the recent D.learn thread "How would I optimize this parser?", I have tried to find a more efficient way to build the parse tree, so I have used tagged structs, something like this: enum NodeType { node, text, tag } struct Node { /*immutab

Immutable struct fields

2010-11-01 Thread bearophile
To answer the recent D.learn thread "How would I optimize this parser?", I have tried to find a more efficient way to build the parse tree, so I have used tagged structs, something like this: enum NodeType { node, text, tag } struct Node { /*immutable*/ NodeType type = NodeType.node; N

Re: couple of really noob questions (ranges, toString)

2010-11-01 Thread bearophile
Michael Woods: > First question: toString(). is this handled exactly the way that it is in > Java? I've written a toString method for my class, I'll post it below. I can > call this method, and it works perfectly, if called specifically. > > linkedList!(int) list = new linkedList!(int)(); >

couple of really noob questions (ranges, toString)

2010-11-01 Thread Michael Woods
Hi. To describe my background really quickly, I'm a CS student with experience mostly in Java and Python. (I've done some C++ work, but not a lot.) Basically, I have two really newbish questions that I haven't been able to figure out from the library and language references, and I'm sure the an

Re: exceptions thrown by new / object constructor ?

2010-11-01 Thread Michal Minich
On Mon, 01 Nov 2010 15:17:11 -0400, Kagamin wrote: > Michal Minich Wrote: > >> What exceptions can be throw by object constructor / new expression? >> Following code fails to compile because compiler says that both >> functions foo and bar can throw. >> >> class C { >> nothrow this () {} >>

Re: exceptions thrown by new / object constructor ?

2010-11-01 Thread Kagamin
Michal Minich Wrote: > What exceptions can be throw by object constructor / new expression? > Following code fails to compile because compiler says that both functions > foo and bar can throw. > > class C { > nothrow this () {} > } > > nothrow void foo () { > auto c = new C; > } >

exceptions thrown by new / object constructor ?

2010-11-01 Thread Michal Minich
What exceptions can be throw by object constructor / new expression? Following code fails to compile because compiler says that both functions foo and bar can throw. class C { nothrow this () {} } nothrow void foo () { auto c = new C; } nothrow void bar () { auto o = new Object

Re: lazy variables cannot be lvalues - why?

2010-11-01 Thread Stewart Gordon
On 01/11/2010 16:20, Jonathan M Davis wrote: 1. I 'm stunned that the compiler doesn't complain about you declaring f as void. It strikes me as a bug with lazy. You can't declare variables of type void. It makes no sense. It isn't a bug. Read the documentation on lazy - D explicitly supports

Re: lazy variables cannot be lvalues - why?

2010-11-01 Thread Stewart Gordon
On 01/11/2010 15:57, Adam Cigánek wrote: void capture(lazy void f) { fun =&f; } It says "Error: lazy variables cannot be lvalues", pointing to the "fun =&f" line. Because f doesn't have an address. It's just an expression that's evaluated where it's used. It's true that the fu

Re: lazy variables cannot be lvalues - why?

2010-11-01 Thread Jonathan M Davis
On Monday, November 01, 2010 08:57:09 Adam Cigánek wrote: > Hello, > > why is the following code illegal? > > > import std.stdio; > > void delegate() fun; > > void capture(lazy void f) { > fun = &f; > } > > void main() { > capture(writeln("hello")); > fun(); > } > >

lazy variables cannot be lvalues - why?

2010-11-01 Thread Adam Cigánek
Hello, why is the following code illegal? import std.stdio; void delegate() fun; void capture(lazy void f) { fun = &f; } void main() { capture(writeln("hello")); fun(); } It says "Error: lazy variables cannot be lvalues", pointing to the "fun = &f" line. It can be w

Re: 2-dimensional array confusion

2010-11-01 Thread spir
On Mon, 1 Nov 2010 07:50:12 + (UTC) Andreas Kaempf wrote: > According to the documentation, the declaration of test should declare 3 > arrays of two ints. The initialization works fine so that's ok for me. > > But why do I have to access it with test[x][y] to produce this result? Yes, this

Re: How would I optimize this parser?

2010-11-01 Thread bearophile
spir: > Then an optimization would be to somehow grossly predict array sizes and > preallocate? I have answered the wrong question sorry :-) My answer was about the tree node allocations. I have not studied enough the allocation patterns of those arrays, so I can't answer. You may collect bet

Re: How would I optimize this parser?

2010-11-01 Thread bearophile
spir: > Then an optimization would be to somehow grossly predict array sizes and > preallocate? In some situations that's not handy to do, because you don't know what's a good size to preallocate. So I suggest a more general solution, to create a struct that inside keeps a dynamic array of poi

Re: How would I optimize this parser?

2010-11-01 Thread spir
On Sun, 31 Oct 2010 22:02:10 -0400 bearophile wrote: > The children arrays inside TagNode receive a total of 414_000 appends, they > cause reallocations. Then an optimization would be to somehow grossly predict array sizes and preallocate? Denis -- -- -- -- -- -- -- vit esse estrany ☣ spir.

Re: higher-order functions

2010-11-01 Thread spir
On Sun, 31 Oct 2010 20:24:59 -0600 Rainer Deyke wrote: > On 10/31/2010 16:57, Simen kjaeraas wrote: > > For very short functions, strings are better, because of the length of > > the 'return' keyword. Had D instead always returned the result of the > > last line of a function (unless specified to

2-dimensional array confusion

2010-11-01 Thread Andreas Kaempf
Hey folks! Please enlight me with that prefix notation of 2-dimensional arrays! I prepared a snippet giving me headaches: auto int[2][3] test = [[11,12],[21,22],[31,32]]; foreach (x, row; test) { Stdout.format("x={}: ", x+1); foreach (y, cell; row) { Stdou