Re: Downloading Files in D

2014-09-11 Thread Danyal Zia via Digitalmars-d-learn

On Thursday, 11 September 2014 at 17:37:24 UTC, Nordlöw wrote:
Ok, thanks. And I guess vibe.d can do this aswell without 
external dependencies, right?


I'm also interested to know how this can be done with vibe.d...


Re: UFCS doesn't work in some cases

2014-09-10 Thread Danyal Zia via Digitalmars-d-learn
On Tuesday, 9 September 2014 at 18:46:31 UTC, ketmar via 
Digitalmars-d-learn wrote:
UFCS is not working for nested functions. this is not a bug, it 
was

designed this way. the same for 'with', i believe.
Apparently it is a bug that UFCS doesn't work with 'with' 
statement.

https://issues.dlang.org/show_bug.cgi?id=10349

there is rationale. see http://dlang.org/function.html, UFCS 
section.

Must have missed it before, thanks.


UFCS doesn't work in some cases

2014-09-09 Thread Danyal Zia via Digitalmars-d-learn

Hi,

I don't know if this has been mentioned before, but I found two 
strange cases where UFCS doesn't work.


Case # 1: When the functions for UFCS are defined inside main 
scope


class Rect {
int x = 20;
int y = 20;
}

void main() {
import std.stdio : writeln;

int area(Rect rect) {
return rect.x * rect.y;
}

auto rect = new Rect;

rect.area.writeln; // Error: no property 'area' for type 
'main.Rect'

}

Put that 'area' definition outside the main body and it works 
fine.


Case # 2: When using UFCS in 'with' scope

class Rect {
int x = 20;
int y = 20;
}

int area(Rect rect) {
return rect.x * rect.y;
}

void main() {
import std.stdio : writeln;

auto rect = new Rect;

with(rect) {
		area.writeln; // Error: function main.area (Rect rect) is not 
callable using argument types ()

}
}

As far as I know, UFCS are designed to make it easy to extend the 
class for specific applications, however, without the ability to 
use UFCS for those cases, it limits its usefulness. Are these 
oversights/bugs? Or is their any rationale behind the decision to 
not implement UFCS for them?


Danyal


Re: Installing LDC on Windows

2014-09-06 Thread Danyal Zia via Digitalmars-d-learn
On Saturday, 6 September 2014 at 11:13:20 UTC, Russel Winder via 
Digitalmars-d-learn wrote:
OK I installed LDC pre-built on MinGW for Windows on Windows 
and then

Installed MinGW for Windows but when I run ldc2 it tells me
libgcc_s_dw2-1.dll is missing.

Is this problem soluble by any means other than destruction of 
Windows?


You need to set PATH in environment variables to the directory 
where shared libaries of MinGW are present...


Re: Really nooB question - @property

2014-07-21 Thread Danyal Zia via Digitalmars-d-learn

On Sunday, 20 July 2014 at 16:35:52 UTC, Eric wrote:

There are a lot of discussions in the forums about how @property
should or could be implemented.  But I can't seem to find 
anything
that explains why or when I should use @property with the 
current
compiler.  Can anyone explain why and when I should use the 
@property tag?


Consider the following struct:

struct Vector4 {
@property float x() { return vec[0]; }
.
.
@property void x(float _x) { vec[0] = _x }
.
.
private:
float[4] vec;
}

Here I like to use static array for storing components of vector 
because I want to use special operations on arrays while taking 
advantage of auto-vectorization if possible. In this case, it is 
very convenient to use properties.


Re: DStyle: Braces on same line

2014-07-14 Thread Danyal Zia via Digitalmars-d-learn

On Sunday, 13 July 2014 at 16:10:31 UTC, Gary Willoughby wrote:
Here is the 'official' style that is followed by most people 
including me.


http://dlang.org/dstyle.html


Unrelated to my original question. I already read that before 
asking.


Re: DStyle: Braces on same line

2014-07-13 Thread Danyal Zia via Digitalmars-d-learn
On Sunday, 13 July 2014 at 10:18:23 UTC, Joseph Rushton Wakeling 
via Digitalmars-d-learn wrote:
However, I do think there's value in deliberately matching the 
code style of the standard library, as it extends the volume of 
public D code with a common style.
 So unless you have a strong personal preference, I'd go with 
that.


I'm going with Andrei's style of preference on his talks ;)


DStyle: Braces on same line

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn

Hi,

I noticed that in Andrei's talks and his book, he used braces on 
the same line of delcaration, however Phobos and other D 
libraries I know use braces on their own line. Now I'm in a 
position where I need to take decision on coding style of my 
library and I get accustomed to use braces on same line but I'm 
worried if that would make my library less readable to other D 
users.


Should I worry about it? Or is that's just a debatable style that 
won't really matter if it's persistent throughout library?


Thanks


Re: struct template help

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn

On Saturday, 12 July 2014 at 19:19:28 UTC, seany wrote:
For reasons further down in the software, I need to do this 
with a pointer. How do I do it with a pointer, please?


I don't know what are you trying to achieve, but if that's what 
you want, you can do:


void MYfunction()
{
auto strArr = [Hello, World!];
arc!(string, string[]) * a = new arc!(string, string[])(s, 
strArr);

a.some_var = hello;
}

If you want to use a from outside the function you have to 
declare it in the class and then initialize it in your function.


Re: struct template help

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn

On Saturday, 12 July 2014 at 19:32:48 UTC, seany wrote:
do I have to initialize all variables of the struct? or may I 
also use a this(){} in the struct and initialize only those 
which are known at a given moment?


You can initialize in constructor this(), but you can't 
initialize partial fields of struct when using pointer to struct. 
There would be other trivial ways to do what you are trying to 
do. Also, I never used any pointer to struct (which is of value 
type) in my code .


Re: struct template help

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn

On Saturday, 12 July 2014 at 19:42:13 UTC, Ali Çehreli wrote:
Actually, that works too but members must be initialized from 
the beginning. The trailing ones are left with .init values:


struct S
{
int i;
string s;
}

void main()
{
auto s = new S(42);
static assert(is (typeof(s) == S*));
}

Ali


Ah, right. I still has C++ background in my veins I guess :)



Re: DStyle: Braces on same line

2014-07-12 Thread Danyal Zia via Digitalmars-d-learn

On Saturday, 12 July 2014 at 19:35:11 UTC, anonymous wrote:

There is another stylistic choice which I do find confusing:
capitalized identifiers for non-types, e.g. variables and
functions. Please don't do that.


Agreed about variables and functions. However I personally prefer 
to use PascalCased identifiers in enum unlike what is preached in 
Dstyle page.


Using two flags in conditonal compilation (version)

2014-06-25 Thread Danyal Zia via Digitalmars-d-learn
Hi, In the development of my library, I'm in a position where I 
need to add support for multiple compilers. For instance, 
supporting both the assembly of LDC/DMD and GDC. I want to do 
something like:


version(DigitalMars  LDC)
{
}

However, it doesn't compile which forces me to rewrote the same 
code for both DigitalMars and LDC


version(DigitalMars)
{
}

version(LDC)
{
}

Is there a way to check both versions at the same time? (I can't 
seem to find the solution through google, sorry)


Thanks,
Danyal Zia


Converting from C const(dchar*) to dstring

2014-06-24 Thread Danyal Zia via Digitalmars-d-learn
Hi, I like to print the strings from a C function that returns 
const(dchar*), but I can't make the conversion to dstring. I can 
convert vice versa by:


dstring text = Hello;
const(dchar)* str = toUTFz!(const(dchar)*)(text);
// passing it to C function prints Hello

However, I don't have the idea how can I go the other way. I 
tried several methods such as using to!dstring, toUTF32 etc which 
compiles successfully however printing them gives address of them 
instead of text.


Thanks,

Danyal Zia


Re: Converting from C const(dchar*) to dstring

2014-06-24 Thread Danyal Zia via Digitalmars-d-learn
On Tuesday, 24 June 2014 at 17:59:41 UTC, Steven Schveighoffer 
wrote:

const(dchar *)x = ...;

// assuming 0 terminated
dstring text = x[0..x.strlen].idup;

-Steve

const(dchar)* x = Hello\0;
dstring text = x[0..x.strlen].idup;
writeln(text);

Error: no property 'strlen' for type 'const(dchar)*'


Re: Converting from C const(dchar*) to dstring

2014-06-24 Thread Danyal Zia via Digitalmars-d-learn

On Tuesday, 24 June 2014 at 18:34:31 UTC, Chris Cain wrote:
You can do what he said, but you'll have to write your own 
strlen function:


something like:

size_t strlen(in dchar* s) pure @system nothrow
{
size_t pos = 0;
dchar term = '\0';
while(s[pos] != term)
++pos;
return pos;
}
const(dchar)* ds = hello\0;
dstring text = ds[0..strlen(ds)].idup;
writeln(text);

works
It works indeed, thanks a lot! Any chance of making it into std 
phobos?