Re: Stride

2012-02-14 Thread RenatoL
mmmhhh this is interesting nevertheless i don't understand the solution of my problem, and i cannot even understand it's origin: void main() { string s1 = abcd; s1 = s1[stride(s1,0)..1] ~ 'r' ~ s1[2..$]; writeln(s1); } why there is not way i cannot achive arcd?

Stride

2012-02-12 Thread RenatoL
Loosing my time on skittles... input abcd desired output arcd i want to use stride snippet, where x and y are integer in real code: string s1 = abcd; s1 = s1[stride(s1,x)..y] ~ 'r' ~ s1[2..$]; if x = 0 and y = 0 - run time error. ok if x = 0 and y = 1 - rcd (??) if x = 1 and y = 0 -

Re: Stride

2012-02-12 Thread RenatoL
This is the code i compiled v. 2057 and parameters 0 1 import std.stdio; import std.utf; void main() { string s1 = abcd; s1 = s1[stride(s1,0)..1] ~ 'r' ~ s1[2..$]; writeln(s1); }

Re: Stride

2012-02-12 Thread RenatoL
Mmmm this doesn't compile import std.stdio; import std.algorithm; void main() { string s1 = abcd; s1 = s1[stride(s1,0)..1] ~ 'r' ~ s1[2..$]; writeln(s1); } Error: undefined identifier stride, did you mean alias string?

for loop

2012-01-22 Thread RenatoL
This works: import�std.stdio; void�main() { int�x =�0; int�y =�0; for(;�((x��5)��(y��5));�x++,�y�++) { writeln(x + y = ,�x�+�y); } } The question is easy: is it possible to insert x and y internally in the for header? that is something like C# for (int x = 0, int y =

Re: for loop

2012-01-22 Thread RenatoL
Ops, tk u .. sometimes C# is a bad teacher :-)

Switch and break

2012-01-19 Thread RenatoL
Just curious: why in D we are not obligated to use break in every branch of a swicth structure? That is: switch (i) { case 1: writeln(You wrote 1); case 2: writeln(You wrote 2); case 3:

Re: Switch and break

2012-01-19 Thread RenatoL
Compile with -w enabled and the compiler will complain about implicit fall-through. You can use goto case/goto default for explicit fall- through. This gives a little relief

Re: associative arrays

2012-01-08 Thread RenatoL
Very interesting discussion. Tk u all.

associative arrays

2012-01-07 Thread RenatoL
Very quick question import std.stdio; void main() { auto arr1 = [uno:1, due:2, tre:3]; arr1.remove(xxx); } also in this case the compiler does not say anything and the program goes out silently ... why? Would not it be better if an exception was raised? After all if i write:

Re: associative arrays

2012-01-07 Thread RenatoL
Yes, Jonathan, you're right. the question arose precisely from a typo... i had to remove an item with key length... i wrote lengt and the item never went away... i knew that lengt was not in my key list... This kind of mistake is quite tricky, may be using and IDE could help.

Array of array

2012-01-02 Thread RenatoL
auto r = new int[][5]; this is ok auto r = new int[][]; this is not ok Error: new can only create structs, dynamic arrays or class objects , not int[][]'s why?

Re: Array of array

2012-01-02 Thread RenatoL
Just curious... the answer of the compiler it's a bit unclear to me... T[] is a dynamic array of type T. T[][] is a dynamic array of T[]. But this doesn't work. Why?

Re: Array of array

2012-01-02 Thread RenatoL
I have: auto r = new int[][]; Error: new can only create structs, dynamic arrays or class objects , not int[][]'s while auto r = new int[][3]; is ok.

Arrray sizeof

2011-12-24 Thread RenatoL
snippet: int[] arr1 = [1,2,3,4,5]; int[5] arr2 = [1,2,3,4,5]; writeln(arr1.sizeof); writeln(arr2.sizeof); Output: 8 20 0 is ok to me but why 8??

Array expanding

2011-12-18 Thread RenatoL
Reading the book from Alexandrescu we can find this (page 103-104, at least in my edition): Expanding arrays has a couple of subtleties that concern possible reallocation of the array. Consider: auto a = [87, 40, 10, 2]; auto b = a; // Now a and b refer to the same chunk a ~= [5, 17]; // Append

Re: Array expanding

2011-12-18 Thread RenatoL
Yes in pratice we can make in many different ways but theoretically speaking it seems (to me) a very bug prone behavior not nice.

Re: Array expanding

2011-12-18 Thread RenatoL
This is interesting i didn't know assumesafeappend (as a beginner i've still too much bugs)it is worth of investigation

deep copy or shallow copy?

2011-12-08 Thread RenatoL
snippet 1) auto arr1 = [1,2,3]; auto arr2 = arr1; arr1[1] = 22; arr2[2] = 33; foreach (i; 0..arr1.length) write(arr1[i], ); writeln(); foreach (i; 0..arr2.length) write(arr2[i], ); output: 1 22 33 1 22 33 OK snippet 2) int[3]

Re: Generic array

2011-11-17 Thread RenatoL
Ok, tk u all. I guess this is a very poor approach if we are looking for performance

Generic array

2011-11-15 Thread RenatoL
##[3] arr = [0, aa, 2.4]; What can i put instead of ##? In C#, just for example, i can write: object[] ar1 = new object[3]; ar1[0] = 1; ar1[1] = hello; ar1[2] = 'a'; and it works. But in D Object[3] arr0 = [0, aa, 2.4]; and compiler complains

Slincing behaviour

2011-11-11 Thread RenatoL
int[7] arr = [1,2,3,4,5,6,7]; writeln(arr[$..$]); this simply prints a newline... I expected a runtime error (or better a compile time error) but it does nothing ... why?

Re: Slincing behaviour

2011-11-11 Thread RenatoL
Yes, my fault. As Andrei write on his book The situation m == n is acceptable and yields an empty slice Thx.

WinRT

2011-09-29 Thread RenatoL
Hi all. What do you about WinRT? I think this new APIs could be a very interesting point for D... they are open to any language and i think that D is perfect to work with them. What's your opinion? Best regards