Re: Status of $ in class/struct?

2011-03-29 Thread Jonathan M Davis
On 2011-03-29 19:29, Nick Sabalausky wrote: > I haven't been following the $/__dollar/opDollar/etc chronicles very > closely, and I can't find the answer in the docs, but I have simple > question: [snip] > Question: > > Is there currently any way for Foo's author to make "foo[$-1]" work? If so, >

Re: Contracts or Exceptions?

2011-03-29 Thread Ali Çehreli
On 03/29/2011 03:40 PM, Kai Meyer wrote: > I was given two words of advice on exceptions: > "Use exceptions for the exceptional" > "Use exceptions only for the exceptional" Those advices are given by wise people: they are wise only because they leave the definition as vague as "exceptional." :)

Re: Contracts or Exceptions?

2011-03-29 Thread Mike Linford
Thanks for the responses, everybody. They were helpful :-) -- --Mike Linford

Re: Status of $ in class/struct?

2011-03-29 Thread Andrej Mitrovic
I think its broken or something. It looks like its trying to find __dollar in the current scope. Because this non-solution seems to work: module opDollarTest; import std.stdio; class Foo { int[] data; this(int[] data) { this.data = data; } int opIndex(int a) {

Status of $ in class/struct?

2011-03-29 Thread Nick Sabalausky
I haven't been following the $/__dollar/opDollar/etc chronicles very closely, and I can't find the answer in the docs, but I have simple question: Suppose I have this: --- class Foo { int[] data; this(int[] data) { this.data = data; } re

Re: Memory usage of AAs?

2011-03-29 Thread Nick Sabalausky
"spir" wrote in message news:mailman.2909.1301443345.4748.digitalmars-d-le...@puremagic.com... > On 03/30/2011 01:24 AM, Nick Sabalausky wrote: >> My understanding of hash tables is that they allocate a fixed size array >> and >> map keys to indicies within the range 0..predefined_length_of_the_

Re: Memory usage of AAs?

2011-03-29 Thread spir
On 03/30/2011 01:24 AM, Nick Sabalausky wrote: My understanding of hash tables is that they allocate a fixed size array and map keys to indicies within the range 0..predefined_length_of_the_AA. So I've been wondering, how many elements do D's built-in AAs have? And what's the content of each one

Memory usage of AAs?

2011-03-29 Thread Nick Sabalausky
My understanding of hash tables is that they allocate a fixed size array and map keys to indicies within the range 0..predefined_length_of_the_AA. So I've been wondering, how many elements do D's built-in AAs have? And what's the content of each one, just a single pointer?

Re: Contracts or Exceptions?

2011-03-29 Thread Kai Meyer
On 03/29/2011 12:40 PM, Mike Linford wrote: Hello, So I'm writing a function for a library. It takes a struct as an argument. The struct's fields can't just be any old values, though. The function won't work if some of the fields are weird. It could return an erroneous value, or even crash. The

Re: Container access in std.container

2011-03-29 Thread Daniel Green
On 3/29/2011 4:45 AM, Ishan Thilina wrote: now all that is left is the problem with GDC. Why can't I do "import std.container" in Linux :( std.container is a D2 module. Based on your include path you have a D1 version of GDC. GDC uses include/d for D1 and include/d2 for D2.

Re: Static asserts within unittest block

2011-03-29 Thread Piotr Szturmaj
Now it's clear. Thanks to both of you :)

Re: Using D libs in C

2011-03-29 Thread Dainius (GreatEmerald)
Oh, never mind. About sending strings, I got it working, I just had to create a function like this in D: immutable(char)* GetString() { return StringD.toStringz(); } As for D not compiling, I had to declare it in D, d'oh :D And that extern is in the wrong place there.

Re: Contracts or Exceptions?

2011-03-29 Thread spir
On 03/29/2011 08:49 PM, Steven Schveighoffer wrote: On Tue, 29 Mar 2011 14:40:02 -0400, Mike Linford wrote: Hello, So I'm writing a function for a library. It takes a struct as an argument. The struct's fields can't just be any old values, though. The function won't work if some of the fields

Re: Using D libs in C

2011-03-29 Thread Dainius (GreatEmerald)
All right, I solved that part of the problem by creating a linked list. However, getting the string out of D is still problematic, namely because toStringz() gives me an immutable char*, and I don't seem to be able to pass those, since I can't assign those to immutable variables outside their const

Re: Contracts or Exceptions?

2011-03-29 Thread Steven Schveighoffer
On Tue, 29 Mar 2011 14:40:02 -0400, Mike Linford wrote: Hello, So I'm writing a function for a library. It takes a struct as an argument. The struct's fields can't just be any old values, though. The function won't work if some of the fields are weird. It could return an erroneous value, or

Contracts or Exceptions?

2011-03-29 Thread Mike Linford
Hello, So I'm writing a function for a library. It takes a struct as an argument. The struct's fields can't just be any old values, though. The function won't work if some of the fields are weird. It could return an erroneous value, or even crash. The thing is, though, that I can't tell wheth

Re: Static asserts within unittest block

2011-03-29 Thread bearophile
Jonathan M Davis: > If a static assert is in a unit test block it's to verify that something > works. You don't necessarily want it in normal code. For instance, what if > the > static assert is verifying something about a templated type or function? > Having that static assert in the normal c

Re: Static asserts within unittest block

2011-03-29 Thread Jonathan M Davis
On 2011-03-29 10:08, Piotr Szturmaj wrote: > I see this is common practice in Phobos. I though static asserts should > be checked at each compilation, not only when compiling with unittest. > Or is it supposed to shorten compile time for already tested modules? :) If a static assert is in a unit t

Static asserts within unittest block

2011-03-29 Thread Piotr Szturmaj
I see this is common practice in Phobos. I though static asserts should be checked at each compilation, not only when compiling with unittest. Or is it supposed to shorten compile time for already tested modules? :)

Re: Container access in std.container

2011-03-29 Thread Steven Schveighoffer
On Tue, 29 Mar 2011 04:49:41 -0400, Jonathan M Davis wrote: On 2011-03-29 01:38, Ishan Thilina wrote: So how can I declare a redBlackTree..? I believe that you'd just do auto rb = RedBlackTree(4, 1, 2, 3); I think: auto rb = RedBlackTree!(int)(4, 1, 2, 3); But the version in git will

Re: Container access in std.container

2011-03-29 Thread spir
On 03/29/2011 12:43 PM, Ishan Thilina wrote: I'm using GDC because I can't use DMD in linux. I have started a seperate thread for that. I'm using dmd on Linux without any issue. But only stable releases (several versions have passed). May I suggest you take some time to uninstall everything p

Re: object.d: Error: module object is in file 'object.d' which cannot be read

2011-03-29 Thread David Nadlinger
On 3/27/11 12:28 PM, Ishan Thilina wrote: When I give "dmd untitled.d" command in my ubuntu maverick 64 bit laptop I get the following error. " object.d: Error: module object is in file 'object.d' which cannot be read import path[0] = /etc/../../src/phobos import path[1] = /etc/../../src/druntim

Re: Container access in std.container

2011-03-29 Thread Ishan Thilina
>Unless you really need gdc, I'd just suggest using dmd. It's quite easy to get >working. You just unzip it wherever you want it and add >/path/to/unzipped/dmd2/linux/bin to your path, and it works. I have no clue >what it takes to get gdc to work. And the only advantage to gdc I'm aware of >is tha

Re: Container access in std.container

2011-03-29 Thread Jonathan M Davis
On 2011-03-29 01:45, Ishan Thilina wrote: > >So how can I declare a redBlackTree...? > > I'm so sorry for being this much foolish. I found the way to do it( make a > redBlackTree). Again I'm really sorry :-/. > > now all that is left is the problem with GDC. Why can't I do "import > std.container

Re: Container access in std.container

2011-03-29 Thread Jonathan M Davis
On 2011-03-29 01:38, Ishan Thilina wrote: > == Quote from Steven Wawryk (stev...@acres.com.au)'s article > > > Your environment looks wrong. Note that > > /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5 > > is equivalent to > > /usr/include/d/4.3.5 > > so I expect it can't find co

Re: Container access in std.container

2011-03-29 Thread Ishan Thilina
>So how can I declare a redBlackTree...? I'm so sorry for being this much foolish. I found the way to do it( make a redBlackTree). Again I'm really sorry :-/. now all that is left is the problem with GDC. Why can't I do "import std.container" in Linux :(

Re: Container access in std.container

2011-03-29 Thread Ishan Thilina
== Quote from Steven Wawryk (stev...@acres.com.au)'s article > Your environment looks wrong. Note that > /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5 > is equivalent to > /usr/include/d/4.3.5 > so I expect it can't find container.d > On 29/03/11 04:54, Ishan Thilina wrote: > > I

Re: object.d: Error: module object is in file 'object.d' which cannot be read

2011-03-29 Thread Jacob Carlborg
On 2011-03-28 16:49, Ishan Thilina wrote: @Jonathan: Yeah I checked. It's there :s. I dont know what has gone wrong, but I'm using the default settings . I have GDC installed too. Can this have any connection with this problem( just a wild guess ) ? @Jacob: I wasn't sure about which libraries