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"?
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?
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);
}
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
Ops, tk u .. sometimes C# is a bad teacher :-)
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, in
>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
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:
Very interesting discussion. Tk u all.
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.
Yes, i agree this may acceptable. On the other hand if i really
want/have to remove an item i have to be very careful cause a
trivial typo could cause a disaster
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 writ
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.
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?
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?
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"??
This is interesting i didn't know assumesafeappend (as a beginner
i've still too much bugs)it is worth of investigation
Yes "in pratice" we can make in many different ways but "theoretically
speaking" it seems (to me) a very bug prone behavior not nice.
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 t
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]
Ok, tk u all.
I guess this is a very poor approach if we are looking for
performance
##[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
Yes, my fault. As Andrei write on his book
The situation m == n is acceptable and yields an empty slice
Thx.
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?
Eh eh, it may be strange something good come out from MS... but i
think this time we could look at this with interest this an
object replacement for win32 and the OS exposes it in an "open"
way... i believe this is good for D (and Delphi, Scala)
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
26 matches
Mail list logo