Re: Uniform Function Call Syntax?

2016-03-03 Thread user001 via Digitalmars-d

On Friday, 4 March 2016 at 02:09:25 UTC, Era Scarecrow wrote:

On Friday, 4 March 2016 at 01:56:34 UTC, user001 wrote:
Was just wondering why UFCS only works in one direction, that 
is why functions can be used as if it were part of a 
struct/class but not the other way around.


int dot;

float value = dot(a, b); // would be same as a.dot(b)
 // doesn't try to use local "int dot"


 Immediately looking at only that part of the code, i have to 
ask 'how the hell are you calling the int???'. Of course i can 
tell from your source dot is also a function in the vector.


 Considering dot could now shadow the variables or function 
names, it would quickly QUICKLY become annoying. A hierarchy of 
how the call is used plus the documentation of what it's 
obviously doing is a much better approach. Not to mention we've 
been using . and -> and * so long for accessing/de-referencing 
members that are attached so long that changing it is probably 
not an option.


You can say the same thing about how it is currently implemented.

int[] arr = [ 0, 1, 2, 3 ];

static map(alias F)(int[])
{
}

	writeln(arr.map!(a => a * 2)); // what does this mean array 
doesnt have a map function, does it use the local map function or 
the global one?


MAYBE if you were starting a language from scratch, but in this 
case i would firmly say no, this is ugly and confusing.


Well it could possibly be happening with C++17 so it's not that 
big of stretch to add it to an existing language, especially if 
that language already has it half implemented.





Uniform Function Call Syntax?

2016-03-03 Thread user001 via Digitalmars-d
Was just wondering why UFCS only works in one direction, that is 
why functions can be used as if it were part of a struct/class 
but not the other way around.


struct Vec3
{
float x;
float y;
float z;

float dot(Vec3 o)
{
return x * o.x + y * o.y + z * o.z;
}
}

int dot;
Vec3 a, b;

float value = dot(a, b); // would be same as a.dot(b)
 // doesn't try to use local "int dot"


It may not add as much value but I think it'd be a bit better as 
now you no longer have a global function with a simple name 
"dot". For mathematical purposes it is a lot easier to understand 
"dot(a, b)" than "a.dot(b)", at least in my opinion. Just curious 
that's all.


Re: Struct Inheritence

2016-02-19 Thread user001 via Digitalmars-d-learn

Yes that's exactly what i needed, thanks!


Struct Inheritence

2016-02-19 Thread user001 via Digitalmars-d-learn
Well struct don't have it, but i would like something like it but 
only for data, i don't need functions or anything like that just 
data.



struct A
{
int valueA;
}

struct B
{
A a;
int valueB;
}

struct C
{
B b;
int valueC;
}

C c;

c.b.a.valueA; // not elegant

B* b = 

b.a.valueA; // we can access A


// alternative 
--


struct A
{
int valueA;
}

struct B
{
int valueB;
}

struct C
{
A a;
B b;
int valueC;
}

C c;

c.a.valueA; // a bit more elegant but still not very, 
c.valueA would be prefered


B* b = 

b.? // can't access A, unless we do some hack that assumes B 
always follows A in the definition



Is there any way to do inheritance with structs, is there a 
reason why we can't extend structures like in C++?


DMD Issue with Asm Generation?

2016-02-13 Thread user001 via Digitalmars-d
There seems to be some invalid code generation for std.format for 
type of "real". Relavant links:


https://github.com/D-Programming-Language/phobos/blob/master/std/format.d#L1713
https://github.com/D-Programming-Language/phobos/blob/master/std/math.d#L5118


movabs rbx,7FF0| <-- problem, should 
be 0x7FFF

and rax,rbx|
cmp rax,rbx|
jne test.7FF6FF4762E4  |
mov rdx,qword ptr ss:[rbp-230] |
movabs rcx,F   |
test rdx,rcx   |
je test.7FF6FF4762E4   |
lea rax,qword ptr ds:[7FF6FF4C5C02]| ;7FF6FF4C5C02:"nan"
mov qword ptr ss:[rbp-2C8],rax |
mov qword ptr ss:[rbp-2D0],3   |
jmp test.7FF6FF476335  |
mov rsi,qword ptr ss:[rbp-230] |
movabs rax,7FFF|
and rsi,rax|
cmp rsi,rbx|
jne test.7FF6FF476335  |
fld tword ptr ss:[rbp-228] |
fldz   |
fcompi st1 |
fstp st0   |
ja test.7FF6FF47631B   |
jp test.7FF6FF47631B   |
lea rdx,qword ptr ds:[7FF6FF4C5C06]| ;7FF6FF4C5C06:"inf"
mov ebx,3  |
jmp test.7FF6FF476327  | ;format.d:1495
lea rdx,qword ptr ds:[7FF6FF4C5C0A]| ;7FF6FF4C5C0A:"-inf"

Seems to compile fine with DMD at least with simpler code with 
just an if statement. Also this issue doesn't exist for 32-bit 
x86.


Re: DMD Issue with Asm Generation?

2016-02-13 Thread user001 via Digitalmars-d
Disregard all that above, looks like someone used a "double" 
which uses 0x7FF0 to check if infinite. Not sure why the code 
runs fine on x86 though, different library maybe?


https://github.com/D-Programming-Language/phobos/blob/master/std/format.d#L1709