Re: Range violation error in the code

2011-04-12 Thread Ishan Thilina
>An array does not dynamically adjust its length when you assign an
>element, you have to assign the length explicitly before-hand.  Some
>dynamic languages do this (like Javascript), but not D.
>
>You can achieve this with an associative array:
>
>Node*[int] pointers;
>
>However, iterating an AA does not guarantee order.  So it depends on your
>requirements.
>
>-Steve

Thank you..!. That clarifies the things a lot. :)


Re: Range violation error in the code

2011-04-12 Thread Ishan Thilina
-Christian Manning wrote:

>Seems like Node*[] pointers needs to have a defined length before
>allocating to an index as adding "++pointers.length;" before
>"pointers[i]=n;" makes it work fine.

Thanks, it works...!

-Denis wrote:
>There is no node in pointers as of now, thus pointers[i] can only be a range
>violation, whatever i (even 0, which should point to the *first* node).
> pointers[i]=n;
>would *change* the current element number i. To put a *new* node into pointers,
>if that's what you intended, use the '~' appending operator (here in version 
>>'~=');
> pointers ~= n;

Yes, that's exactly what I wanted to do. Thanks...!


Range violation error in the code

2011-04-12 Thread Ishan Thilina
I can compile the following code. But when I run the program it gives me a
"core.exception.RangeError@untitled(34): Range violation
" error.

The code is as follows.

"
import std.stdio;

int main(char[][] args)
{
 struct Node{
int _value;
Node* _next,_prev,_up,_down;
}

Node*[]  pointers;
int i=0;

auto  n=new Node;
pointers[i]=n;

return 0;
}

"

Here's the error.

"
core.exception.RangeError@untitled(34): Range violation

/home/ishan/untitled(onRangeError+0x28) [0x8098a08]
/home/ishan/untitled(_d_array_bounds+0x16) [0x80968c6]
/home/ishan/untitled(_D8untitled7__arrayZ+0x12) [0x8094332]
/home/ishan/untitled(_Dmain+0x35) [0x8094309]
/home/ishan/untitled(_D2rt6dmain24mainUiPPaZi7runMainMFZv+0x1a) [0x8096a26]
/home/ishan/untitled(_D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv+0x20) [0x80969b8]
/home/ishan/untitled(_D2rt6dmain24mainUiPPaZi6runAllMFZv+0x32) [0x8096a6a]
/home/ishan/untitled(_D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv+0x20) [0x80969b8]
/home/ishan/untitled(main+0x94) [0x8096964]
/lib32/libc.so.6(__libc_start_main+0xe7) [0xf7613ce7]
/home/ishan/untitled() [0x8094221]
"

As it seems the problem is with the line "pointers[i]=n". What's wrong here? :s


Re: ElementType!(Range) problem

2011-04-06 Thread Ishan Thilina
--Philippe wrote::

>ElementType acts on types. It takes a type and 'returns' (compiles to,
>actually) another type. You need to give it typeof(listR).
>Then, as ElementType!(typeof(listR)) is a type, you cannot pass it to
>writeln. Use .stringof to go from the type to a string representation
>of its name.
>
>So:
>
>writefln("%s", ElementType!(typeof(listR)).stringof);
>
>ElementType!(typeof(listR)) is a type like any other. You can create a
>variable with it:
>
>ElementType!(typeof(listR)) elem;
>

Got it!. Thanks.

I faced this confusion because of the description for "ElementType" which is
available in http://d-programming-language.org/phobos/std_range.html. It says,

"
template ElementType(R):

The element type of R. R does not have to be a range. The element type is
determined as the type yielded by r.front for an object r or type R. For 
example,
ElementType!(T[]) is T. If R is not a range, ElementType!R is void.

"
So I thought that just passing ElementType!listR was adequate. :s




ElementType!(Range) problem

2011-04-05 Thread Ishan Thilina
I can use the ElementType() template in the std.rane library to find the type
of the elements of a range,isn't it? But I cant compile the following programme.

I get a "untitled.d(32): Error: template instance ElementType!(listR) does not
match template declaration ElementType(R)" error.

What could be the problem ?
--

import std.stdio;
import std.range;
import std.container;

int main(char[][] args)
{
auto list=SList!(int)(1,2,3);
auto listR=list.opSlice();
writefln("%s",ElementType!(listR));


return 0;
}
--

Thank you...!


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 that its backend tends to generate more efficient code than dmd's currently
>does.
>
>- Jonathan M Davis

I'm using GDC because I can't use DMD in linux. I have started a seperate thread
for that.
Here it is.
http://www.mail-archive.com/digitalmars-d-learn@puremagic.com/msg11525.html


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 am using DGC due to the problems I'm witnessing with DMD. I tried a 
> > similar
> > approach. But the following error comes.
> >
> > "
> >
> > structures.d:4: Error: module container cannot read file 'std/container.d'
> > import path[0] =
> > /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5/x86_64-linux-gnu
> > import path[1] = 
> > /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5
> >
> > "
> >
> > I dont know what is wrong. I'll try to compile in Windows and let you know.
> >
> > @David :
> >
> > Thanks for the clarifications :)

>structures.d:4: Error: module container cannot read file 'std/container.d'
>import path[0] =
>/usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5/x86_64-linux-gnu
>import path[1] = 
>/usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5

Ok, now std.container can be imported inside windows. The problem has been that
windows has used dmd to compile rather than using dmd2.
But I get an error message. I think it's what davis said.

>On 2011-03-28 07:48, David Nadlinger wrote:
>> ---
>> import std.container;
>> import std.stdio;
>>
>> void main() {
>>  auto rb = redBlackTree(4, 1, 2, 3);
>>  foreach (e; rb) {
>>  writeln(e);
>>  }
>> }
>> ---

>I believe that the redBlackTree function is only in the git repository at
>present (so, it'll be in the next release), so if he's using dmd 2.052, that
>particular way of creating a RedBlackTree won't work.

So how can I declare a redBlackTree..?



It seems that there's no importing problem inside windows now. But the problem
still there in Linux. I'm using GDC to compile.


Re: unit testing

2011-03-28 Thread Ishan Thilina
- Jonathan M Davis wrote:

>LOL. Goodness no. They're done by hand. I'm currently reworking std.datetime's
>unit tests, and it's very time consuming (since it's a large module with lots
>of tests). I don't know how you'd get a framework to generate what I want
>anyway. The fact that D has unit testing built in like it does is fantastic,
>but it is fairly simplistic.

I'm new to this concept of uni testing. Thanks for the help :)


Re: Container access in std.container

2011-03-28 Thread Ishan Thilina
>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

I copied container.d to /usr/include/d/4.3.5/std . But the problem is still 
there :s


Re: Container access in std.container

2011-03-28 Thread Ishan Thilina
Steven wrote:

>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


Really sorry for being a burden, I'm new to D. How can I fix this Environment?


Re: Container access in std.container

2011-03-28 Thread Ishan Thilina
>I am using GDC due to the problems I'm witnessing with DMD. I tried a similar
>approach. But the following error comes.
>
>"
>
>structures.d:4: Error: module container cannot read file 'std/container.d'
>import path[0] =
>/usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5/x86_64-linux-gnu
>import path[1] = 
>/usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5
>
>"
>
>I dont know what is wrong. I'll try to compile in Windows and let you know.
>
>

A module std.container cannot be found error comes in windows too. I'm using GDC
to compile in linux and DMD to compile in windows. I'm really confused about 
this :s


Re: unit testing

2011-03-28 Thread Ishan Thilina
@David:

No, my question was not about running them,but on how that code was generated. I
thought they were auto generated using a unitest framework :). Your answer
clarifies everything. Thank you..! :-)


Re: Container access in std.container

2011-03-28 Thread Ishan Thilina
I am using DGC due to the problems I'm witnessing with DMD. I tried a similar
approach. But the following error comes.

"

structures.d:4: Error: module container cannot read file 'std/container.d'
import path[0] =
/usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5/x86_64-linux-gnu
import path[1] = /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5

"

I dont know what is wrong. I'll try to compile in Windows and let you know.

@David :

Thanks for the clarifications :)


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

2011-03-28 Thread Ishan Thilina
@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 you were talking about. The only lib set I
left out was ia32-libs. So I installed it too.That didn't solve the problem. So 
I
tried to install the deb file by force.

"sudo dpkg -i --force-architecture dmd***.dmd"

now I get a whole lot more errors :s.

"
ishan@ishan-Ubu-I1464:~/Geany Projects$ dmd untitle.d
/usr/include/d/dmd/phobos/object.d(51): C-style function pointer and pointer to
array syntax is deprecated. Use 'function' to declare function pointers
/usr/include/d/dmd/phobos/std/format.d(672): no identifier for declarator
inout(fakevalue)
/usr/include/d/dmd/phobos/std/c/stdlib.d(43): C-style function pointer and 
pointer
to array syntax is deprecated. Use 'function' to declare function pointers
/usr/include/d/dmd/phobos/std/c/stdlib.d(59): C-style function pointer and 
pointer
to array syntax is deprecated. Use 'function' to declare function pointers
/usr/include/d/dmd/phobos/std/c/linux/linux.d(558): C-style function pointer and
pointer to array syntax is deprecated. Use 'function' to declare function 
pointers
/usr/include/d/dmd/phobos/std/c/linux/linux.d(574): C-style function pointer and
pointer to array syntax is deprecated. Use 'function' to declare function 
pointers
"

I'm trying to compile the following simple code. As you can see it should work
without any problem.

"
import std.stdio;



int main()

{

writefln("Hello world");



return 0;

}

"
"


unit testing

2011-03-28 Thread Ishan Thilina
I see that almost all of the phobos library files have "unittests". Were these
unit tests were created using some framework? If so, then what is it?

Thank you...!


Re: Sample source code for D

2011-03-28 Thread Ishan Thilina
@Denis:

The tutorials in the dsource were very helpful.

I have read most of those articles that are in the prowiki( the ones you have
given links to). As you have stated they are more suited for beginners :-/ .

Thank you for the help :)


Container access in std.container

2011-03-28 Thread Ishan Thilina
I know that D has some Containers implemented by default( such as a a List,
Red-black tree, Array). In C++ these data structures can be used as follows.

#include 

int main(){

std::vector myVector;
std::vector::iterator myIterator;

}

Then I can use "myIterator" to manipulate "myVector".

But in D the containers are embedded in the std.container( as far as I
understood it) and I can't do "import std.container" too. So how can I access
the built in containers?

Thank you..!


Re: Sample source code for D

2011-03-27 Thread Ishan Thilina
@ David:

I'm looking for example code that explains specific pieces of functionality :)

@Lutger:

Those two links were really helpful :). Thank you :)


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

2011-03-27 Thread Ishan Thilina
@Jacob:

An error comes when the " ./dvm install dvm" command is given.

"
./dvm: error while loading shared libraries: libz.so.1: cannot open shared 
object
file: No such file or directory
"

@Trass3r:

No, dmd.conf in the dmd2/linux/bin is there safely


Re: Sample source code for D

2011-03-27 Thread Ishan Thilina
Yeah, I saw them. Aren't there any other places? :)


Sample source code for D

2011-03-27 Thread Ishan Thilina
I am a novice to D. Is there any place that I can get sample source codes for D 
?

Thanks...!


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

2011-03-27 Thread Ishan Thilina
Trass3r wrote:

>As you can see dmd.conf uses relative paths.
>That guide needs an overhaul.
>
>The easiest way is to copy the contents of the zip archive into some local
>dmd directory and add dmd/linux/bin to your PATH.
>(i.e. remove your etc/dmd.conf for now)

I did as you have said. Now a new error comes :-/.

"object.d: Error: module object is in file 'object.d' which cannot be read
Specify path to file 'object.d' with -I switch
"

@Spir:

I think you have not understood what my problem is. I'm not trying to solve a
problem with my source code. I'm having an issue in which I can'ct compile 
code( I
have compiled them using dmd in windows and they can be compiled in linux using 
GCD)


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

2011-03-27 Thread Ishan Thilina
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/druntime/import
"

I tried all morning to solve this problem, tried every google result I could
find. Checked the mail archive to solve this problem. But I still couldn't get
rid of that error.I anybody can help me, it would be a great help.

I followed the steps in http://www.digitalmars.com/d/2.0/dmd-linux.html .I
first used the command "cp dmd2/linux/bin/dmd.conf /etc
" . Then I gave "sudo apt-get install gcc-multilib g++-multilib libc6-i386
libc6-dev-i386" command.

Thank you :)


Re: Need help in templates

2011-03-25 Thread Ishan Thilina
@Simen:

Thanks a lot, That solved the problem :).

@Ali:

:s I'm confused, some of the readers has got the attachment correctly :s


Need help in templates

2011-03-24 Thread Ishan Thilina
Hi,

I'm still new to D. I tried to implement a stack using templates. But I get an
"Access Violation" error when I try to run a test on the stack that I made.The
source code is attached with this mail. Can somebody please point out the
error of this code?
begin 644 main.d
M;6]D=6QE(&UA:6X[#0H-"FEM<&]R="!S=&0N5-T86-K+G!UPT*"0EWPT*"0T*"7!R
M:79A=&4@:6YT(&UA>%-I>F4["2\O%-I>F4]3UN
M97<@:6YT6VUA>%-I>F5=.PT*"0ET;W`]+3$["0D)"2\O:6YD:6-A=&5S('1H
M870@;F\@:71E;7,@87)E(&EN('1H92!S=&%C:PT*"0D-"@D)?0T*"0T*"2\O
M4'5S:"!I=&5M5LK*W1O<%T]96QE;65N=#L-
M"@D)#0H)"7T-"@D-"@DO+U1A:V4@86X@:71E;2!FPT*"0ER971U5MT;W`M+5T[
M#0H)"7T-"@D-"@DO+U!E96L@870@=&AE('-T86-K('1O<`T*"7!U8FQI8R!4
M('!E96LH*7L-"@D)2@I>PT*"0EI9BAT;W`]/2TQ*7L-"@D)"7)E='5R;B!T
MPT*"0D)PT*"0EI9BAT;W`]/6UA>%-I>F4M,2E[
M#0H)"0ER971U