associative arrays with arrays as value

2009-04-18 Thread MLT
I am just learning D, and playing around. So I have no good reason why one would do the following, but I also don't understand why it doesn't work... I was trying to make an associative array with int[5] as the value type. That didn't work properly. int[] did, and I don't understand why. Here is

problem with gdc for OSX?

2009-04-19 Thread MLT
Sorry, this could be a bug report and not a question, and probably the wrong place to post it then. I installed gdc according to the instructions given in http://www.dsource.org/projects/tango/wiki/MacOSXInstall from http://sourceforge.net/project/downloading.php?group_id=135857&filename=gdc-tr

Re: problem with gdc for OSX?

2009-04-20 Thread MLT
== Quote from Denis Koroskin (2kor...@gmail.com)'s article > Bad installation, I suppose. 'string' is defined in Object.d, which is > automatically imported in each source file. Error is defined there, too. Looks like it can't find it. Make sure it does exist and paths are properly configured. >

Re: problem with gdc for OSX?

2009-04-21 Thread MLT
Jacob Carlborg Wrote: > DFLAGS is working for me. I've placed dmd.conf in the same folder as > dmd. Mac OS X doesn't have /etc by default. That was the problem: dmd.conf was copied to /usr/local/bin The copy in /etc did nothing. The copy in /usr/local/bin was overriding any DFLAGS I set. And I

tango iterators and related questions

2009-04-21 Thread MLT
D is really great. I am trying to implement a medium sized project to get to know it. For this I need a sorted data structure, with cheap search, and somewhat cheap forward and backward traversing. I thought I should use tango (though it is a bit confusing that there is so much overlap between

Re: tango iterators and related questions

2009-04-21 Thread MLT
Steven Schveighoffer Wrote: > On Tue, 21 Apr 2009 08:46:18 -0400, MLT wrote: > dcollections+tango should do the trick for you. It is incidentally what I > use (of course I wrote dcollections, so big surprise there ;) > Good! I just managed to compile my first program using 0

how to initialize an array of typedef-ed type?

2009-05-01 Thread MLT
The fact that D has real typedef, not like the fake ones of C++ is, I think, one of its great features. But the fact that there is no automatic cast, together with typedef is causing me problems. The one I'm currently fighting with is initialization: typedef long location ; location a[] = [1,

How to get the base type of a typedef

2009-05-01 Thread MLT
Another question about typedef... I am using typedef long location ; Now I would like to use tango.math.random.Random. But I am having problems with calling r.uniformR( hi ) when r is a random genarator, and hi is of type location. I need to call r.uniform!(long)( cast(long)(hi) ) ; This is u

Re: how to initialize an array of typedef-ed type?

2009-05-01 Thread MLT
typedef long location ; location a[] = cast(location[])[1,2,3,4] ; Seems to work. I was afraid of the mess that would happen if I cast (int *) to (long *) in C... Can I trust it? Is that the "right way" to do it? MLT Wrote: > The fact that D has real typedef, not like the fake o

Re: How to get the base type of a typedef

2009-05-01 Thread MLT
#x27; do some magic? bearophile Wrote: > MLT: > > Is there a way to get the base type of location? > > See the BaseTypedef() template in the "templates" module of my dlibs (they > are for Phobos): > http://www.fantascienza.net/leonardo/so/libs_d.zip > > Bye, > bearophile

Re: how to initialize an array of typedef-ed type?

2009-05-01 Thread MLT
Jarrett Billingsley Wrote: > On Fri, May 1, 2009 at 9:15 AM, MLT wrote: > > > > typedef long location ; > > location a[] = cast(location[])[1,2,3,4] ; > > > > Seems to work. > > I was afraid of the mess that would happen if I cast (int *) to (long *) in &

Re: how to initialize an array of typedef-ed type?

2009-05-01 Thread MLT
[] = a[] doesn't seem to work... Jarrett Billingsley Wrote: > On Fri, May 1, 2009 at 10:07 AM, MLT wrote: > > > At first I thought that maybe on my machine int and long have the same > > length, or some such. But it works, for int, long, and short. And they do >

going beyond your bounds

2009-05-21 Thread MLT
After a discussion on digitalmars.D I played with arrays a bit. Look at the following code: int[] a = [1,2,3,4,5,6,7,8,9] ; int[] b = a ; a ~= 10 ; b ~= 11 ; b[0] = 12 ; Stdout(b).newline ;

Re: going beyond your bounds

2009-05-21 Thread MLT
Derek Parnell Wrote: > > So remember, assigning one array to another is just creating an alias to > the original array. You end up with two arrays pointing to the same data > buffer. Yes. My question relates to what happens when you go beyond the bounds originally assigned. Why does an extensio

Re: going beyond your bounds

2009-05-21 Thread MLT
> Because new elements are pre-initialized in D. > > Just by increasing the length, you 'create' a new element (from the 'b' > point of view) so D initializes it. (We were talking about something like int a[] = [1,2,3,4,5] ; b = a ; a ~= 6 ; b.length = b.length+1;) Hmmm... yes, that has some l