Re: DlangUI Error

2017-08-11 Thread Jiyan via Digitalmars-d-learn

On Friday, 11 August 2017 at 02:25:51 UTC, Mike Parker wrote:

On Thursday, 10 August 2017 at 23:38:42 UTC, Jiyan wrote:


[...]


Sounds like you used the script from the download page that 
installs the compiler per user. It's designed to allow you to 
have multiple versions installed in your user directory and 
requires you to specify which version you want to activate. You 
could probably configure your bash shell to activate dmd when 
you launch it, or you could install dmd via the .deb or .rpm, 
assuming you're on a Linux flavor.


Ok thanks :)


DlangUI Error

2017-08-10 Thread Jiyan via Digitalmars-d-learn

Hey,
i get the following errors when i try to use dlangui, by just 
importing the package i get a lot of errors which look like:
function std.xml.Item.opEquals does not override any function, 
did you mean to override 'object.Object.opEquals'?


What is happening there?


Re: DlangUI Error

2017-08-10 Thread Jiyan via Digitalmars-d-learn

On Thursday, 10 August 2017 at 22:27:44 UTC, HyperParrow wrote:

On Thursday, 10 August 2017 at 20:48:23 UTC, Jiyan wrote:

Hey,
i get the following errors when i try to use dlangui, by just 
importing the package i get a lot of errors which look like:
function std.xml.Item.opEquals does not override any function, 
did you mean to override 'object.Object.opEquals'?


What is happening there?


The error message is correct but the error is only recognized 
by the compiler since the latest release. To fix it requires 
intervention of the author: either "override" must be removed 
from the opEquals that's indicated or the opEquals parameters 
must be changed o match exactly the signature used on 
Object.opEquals.


Until this is done in libdlangui you can use an older compiler, 
e.g last 2.074.x release should make the error disappearing 
(since it wasn't detected yet).


Hey thank you for your reply :)

So the strange thing is i had an older compiler (v2.074.1), so
i started running the 2.075 version - with which it worked!
The thing is i can start the 2.075 version only over the 
activate.sh
script in a shell. Can you tell me how i can really use the 2.075 
version
(without having to run the script each time i open a shell, and 
why do

i have to do that).


Vectorflow noob

2017-08-10 Thread Jiyan via Digitalmars-d-learn

Hey,
wanted to the following simple thing with vectorflow:

I want to develop a simple MLP, which has 2 input neurons and one 
output neuron.
The network should simply add the input values together, so [1,2] 
predicts [3] i guess.

I started in a newbish way to build the following code:

import vectorflow;


struct Obs // The represeneted data
{
	float label; // Did i get that right that label would be the 
DESIRED output (3=1+2)
	float []features; // The features are the input i guess, so 
features = f.e. [1,2]

}

void main()
{

auto net = NeuralNet()
.stack(DenseData(2))
	.stack(Linear(10));   // Is this the right way to construct 
the Net?


// The training data
Obs []data;


data.length = 10;

import std.random;
import std.algorithm;
foreach(ref Obs n; data)
{
		// The features are getting fille with random numbers between 
0.5 and 5

// The label becomes the sum of feature[0] and feature[1]
n.features.length = 2;
n.features[0] = uniform(0.5, 5);
n.features[1] = uniform(0.5, 5);

n.label = n.features.sum;
writeln(n.features[0], " ", n.features[1], " ", n.label);
assert (n.label == n.features[0] + n.features[1]);
}

net.learn(data, "logistic", AdaGrad(10, 0.1, 500), true, 3);

auto val = net.predict(data[0]); // is this wrong?
val.writeln;
}

Thanks :)


Re: Struct Constructor Lazy

2017-07-12 Thread Jiyan via Digitalmars-d-learn

On Wednesday, 12 July 2017 at 11:18:08 UTC, Biotronic wrote:

On Wednesday, 12 July 2017 at 11:00:54 UTC, Jiyan wrote:

[...]


The traditional solution is static opCall:

struct A {
int field;
static A opCall() {
A result;
result.field = getDataFromFile("file.txt");
return result;
}
}

A instance = A();

I believe I've heard this is frowned upon these days, but I 
don't know of a better solution.


For optimal speed you might also want to skip default 
initialization of result, by writing A result = void;.


I would be surprised if the optimizer wasn't able to optimize 
away the useless parameter though - have you looked at the 
generated assembly?


--
  Biotronic


Hey,
yes i did but to be honest i used dmd in debug version.
The thing about the static one, is that it creates a local object 
A isnt that a performance issue itself - or am i wrong - im 
confused actually :P?


Re: Struct Constructor Lazy

2017-07-12 Thread Jiyan via Digitalmars-d-learn

Thank you, one last question:
If i declare the parameter as ref i, then there shouldnt be any 
overhead wouldnt it?


Thanks :)



Struct Constructor Lazy

2017-07-12 Thread Jiyan via Digitalmars-d-learn

Hey there:)

i want to know whether the following is somehow possible:
structs dont have default constructors, i know so:

struct A
{
int field;
this(int i){field = getDataFromFile("file.txt");}
}

A instance = A(0);

Here comes my issue:
when A(0) is called I would want here optimal performance, so 
there doesnt even need to be a value pushed on the stack (i=0), 
what would be like having a constructor with zero arguments (i is 
never used!).

Im pretty new to D, can somebody tell me how i would do this?
Is this(lazy int i){ ... a solution?




Struct Postblit Void Initialization

2017-07-30 Thread Jiyan via Digitalmars-d-learn

Hey,
just wanted to know whether something like this would be possible 
sowmehow:


struct S
{
int m;
int n;
this(this)
{
m = void;
n = n;
}
}

So not the whole struct is moved everytime f.e. a function is 
called, but only n has to be "filled"




Re: Struct Postblit Void Initialization

2017-07-30 Thread Jiyan via Digitalmars-d-learn

On Sunday, 30 July 2017 at 19:32:48 UTC, Eugene Wissner wrote:

On Sunday, 30 July 2017 at 19:22:07 UTC, Jiyan wrote:

Hey,
just wanted to know whether something like this would be 
possible sowmehow:


struct S
{
int m;
int n;
this(this)
{
m = void;
n = n;
}
}

So not the whole struct is moved everytime f.e. a function is 
called, but only n has to be "filled"


this(this) is called after the struct is copied. Doing 
something in the postblit constructor is too late. The second 
thing is that the struct is copied with memcpy. What you 
propose would require 2 memcpy calls to copy the first part of 
the struct and then the second part. Besides it is difficult to 
implement, it may reduce the performance of the copying since 
memcpy is optimized to copy memory chunks.


Ok thank you :)


Imports

2017-10-04 Thread Jiyan via Digitalmars-d-learn

Hey,

as i see it the -Ipath command for dmd just imports the files 
within a directory but it doesnt work for sub directories, so i 
can write something like:


import subdirectoryFromPath.file;

Also with dub this doesnt seem possible (sourcePaths seems to 
work as the -I command).


Is there a way to do what i want? Or am i doing something wrong?
And by the way what is the difference from sourcePaths to 
importPaths?




Re: Imports

2017-10-05 Thread Jiyan via Digitalmars-d-learn

On Thursday, 5 October 2017 at 00:28:32 UTC, Mike Parker wrote:

On Wednesday, 4 October 2017 at 16:31:35 UTC, Jiyan wrote:

[...]



If you have this directory tree:

- mylib
-- pack1
--- a.d
--- b.d
 pack2
- c.d

[...]


Thank you, i think i kinda got that :)

But as i see it with sourcePaths the directories are not 
influencing

the module names(in the directories except "source"), so "dir.sub"
will just have the name "sub" is there a way around that, except
naming every module like:

module dir.sub;


Re: Imports

2017-10-05 Thread Jiyan via Digitalmars-d-learn

On Thursday, 5 October 2017 at 12:35:26 UTC, Mike Parker wrote:

On Thursday, 5 October 2017 at 12:25:27 UTC, Mike Parker wrote:


[...]


Right. I had to go back and look at what I wrote in Learning D, 
which is the last (and only) time I played around with the 
default module behavior. I always use module statements (and 
you should too).


[...]


Thank you :)

PS: is it spam to say thank you?


Re: Anonymous nogc class

2017-09-08 Thread Jiyan via Digitalmars-d-learn

On Friday, 8 September 2017 at 06:37:54 UTC, Biotronic wrote:

On Thursday, 7 September 2017 at 23:40:11 UTC, Jiyan wrote:

[...]


Sadly, even std.typecons.scoped isn't currently @nogc:
https://issues.dlang.org/show_bug.cgi?id=13972
https://issues.dlang.org/show_bug.cgi?id=17592

[...]


First thanks :)

i understand the part with scopedAnon, but can you explain what 
the ~this is referring to?

Is it the Modul destructor?
And in general is it just that scoped is just not marked @nogc or 
is it that it would really need to use the gc?


Re: Anonymous nogc class

2017-09-08 Thread Jiyan via Digitalmars-d-learn

On Friday, 8 September 2017 at 16:10:55 UTC, Biotronic wrote:

On Friday, 8 September 2017 at 12:32:35 UTC, Jiyan wrote:

[...]


It's scoped!T's destructor. If you decide to use that 
workaround, you should probably copy scoped!T from std.typecons 
and have your own version. It's not safe in all cases, and the 
next standard library update might break it.



[...]


In your case, scoped!T is can be safely called from @nogc code, 
and thus could be marked @nogc. However, when a class C has a 
destructor that allocates, scoped!C could not be @nogc. So in 
order to be safe in all cases, it can't be @nogc in the general 
case.


--
  Biotronic


Thank you very much :)


Anonymous nogc class

2017-09-07 Thread Jiyan via Digitalmars-d-learn

Hey,
wanted to know whether it is possible to make anonymous nogc 
classes:


interface I
{
public void ap();
}
void exec(I i)
{
i.ap;
}

// now execute, but with something like `scope`
exec( new  class  I
{
int tr = 43;
override void ap(){tr.writeln;}
});

Thanks :)


Re: Template Question

2017-11-19 Thread Jiyan via Digitalmars-d-learn

With working i mean that
Text X;
Doesnt compile!



Re: Template Question

2017-11-19 Thread Jiyan via Digitalmars-d-learn
On Sunday, 19 November 2017 at 19:42:02 UTC, Jonathan M Davis 
wrote:
On Sunday, November 19, 2017 19:25:40 Jiyan via 
Digitalmars-d-learn wrote:

[...]


Okay. For starters,

[...]


Ah ok thanks very much, this helped me a lot :)


Template Question

2017-11-19 Thread Jiyan via Digitalmars-d-learn

Hello,

i wanted to ask why this isnt working:

struct Text(T : char)
{
size_t _len;
T* _ptr;
}

Thanks :)


Re: Template Question

2017-11-19 Thread Jiyan via Digitalmars-d-learn
On Sunday, 19 November 2017 at 19:28:37 UTC, Jonathan M Davis 
wrote:
On Sunday, November 19, 2017 19:22:51 Jiyan via 
Digitalmars-d-learn wrote:

Hello,

i wanted to ask why this isnt working:

struct Text(T : char)
{
  size_t _len;
  T* _ptr;
}

Thanks :)


What about it isn't working? I think that you need to explain 
what you're trying to do and what you think that this code 
should be doing but isn't.


- Jonathan M Davis


Text X;

Here X would be an Object from type Text with T being char when 
i'm right.

But this doesn't compile!
Thanks :)


Rvalue references

2018-01-08 Thread Jiyan via Digitalmars-d-learn


Sry i know i asked it already in IRC:
Are rvalue references already solved with auto ref?

https://p0nce.github.io/d-idioms/#Rvalue-references:-Understanding-auto-ref-and-then-not-using-it

Says rvalues are moved!

The other solution seems not so practical.

Is any solution to them intended, or was all the talk about 
rvalue references simply discarded?


Thanks :)


Trait compiles

2018-01-15 Thread Jiyan via Digitalmars-d-learn

Hello,
is there anyway to do something like this:

mixin template foo( exp)
{
static if(__traits(compiles, exp))exp;
}

Thanks :)


Implicit conversion

2018-01-17 Thread Jiyan via Digitalmars-d-learn

Hello,

I want to convert from ints implicit to a struct type, so for 
example:


struct use
{
int x;

int toInt()
{
return x;
}

use fromInt(int v)
{
return use(v);
}

alias toInt this; // implicit conversion to int value

this(int v)
{x = v;}
}

void useP(int v)
{
v.writeln;
}

void useV(use v)
{
v.writeln;
}

void main(string[] args)
{
use a = use(2);
//useP(a);
useV(2); // how can i let this work?
}

Thanks :)



Re: Interactive Interpreter

2018-02-06 Thread Jiyan via Digitalmars-d-learn

On Tuesday, 6 February 2018 at 01:23:57 UTC, Stefan Koch wrote:

On Monday, 5 February 2018 at 19:54:09 UTC, Jiyan wrote:
Is there any work for an interactive interpreter for D -maybe 
just for ctfe-able expressions?
It shouldnt be too hard to implement it regarding the fact, 
that ctfe is kinda doing what

an interpreter should do i guess.


There is https://github.com/dlang-community/drepl which should 
give you what you want.
As the person who builds newCTFE I can tell you that it is 
rather tricky :)


Thank you very much :)


Interactive Interpreter

2018-02-05 Thread Jiyan via Digitalmars-d-learn
Is there any work for an interactive interpreter for D -maybe 
just for ctfe-able expressions?
It shouldnt be too hard to implement it regarding the fact, that 
ctfe is kinda doing what

an interpreter should do i guess.


Destructing Struct

2018-02-21 Thread Jiyan via Digitalmars-d-learn

Hi :),

What i thought was that when i create a struct dynamically i can 
just deconstruct it with __dtor lets say:


struct U {...}
struct S {... private U _member;}

S* p;
p = cast(S*)malloc(S.sizeof);

// just run that if it compiles, for simplicity
// we dont use __traits(compiles, ...)
p.__dtor;

The thing here is that this doesn't work because of when S has an 
element that that is private and has a __dtor itself, the __dtor 
from U doesnt get called before the call of __dtor from S - or 
after.


Is there any way with traits or sth to do that?

Are delete, destroy or any other functions the standard library 
working here?
I would prefer a solution that can be build by myself - so 
without the standard library for example with traits.


Thanks :)



Re: Destructing Struct

2018-02-21 Thread Jiyan via Digitalmars-d-learn

On Wednesday, 21 February 2018 at 11:12:01 UTC, Jiyan wrote:

Hi :),

What i thought was that when i create a struct dynamically i 
can just deconstruct it with __dtor lets say:


struct U {...}
struct S {... private U _member;}

S* p;
p = cast(S*)malloc(S.sizeof);

// just run that if it compiles, for simplicity
// we dont use __traits(compiles, ...)
p.__dtor;

The thing here is that this doesn't work because of when S has 
an element that that is private and has a __dtor itself, the 
__dtor from U doesnt get called before the call of __dtor from 
S - or after.


Is there any way with traits or sth to do that?

Are delete, destroy or any other functions the standard library 
working here?
I would prefer a solution that can be build by myself - so 
without the standard library for example with traits.


Thanks :)


I think i found my solution: is it __xdtor? :P


Forward references

2018-02-25 Thread Jiyan via Digitalmars-d-learn

Hi,
is there any document or text describing forward references?
It is kinda strange, i implemented a list structure which is 
kinda like this:


struct list(T)
{
private:

struct node
{
T val;
node* next;
node* prev;
}

node* head;
node* last;
size_t size;

 .
}

The thing is when i implement following struct:

struct Tre
{
list!Tre a;
}

theoretically it should be constructable. But it gives me out a 
compiler error about Forward reference. Ok maybe the compiler at 
this point cant do that but ...


The strange thing is i somehow managed earlier without knowing to 
do exactly this in a much more complicated struct.

Can somebody enlighten me about this?







Re: Forward references

2018-02-25 Thread Jiyan via Digitalmars-d-learn
On Sunday, 25 February 2018 at 22:20:13 UTC, Steven Schveighoffer 
wrote:

On 2/25/18 4:25 PM, Jiyan wrote:

[...]


Looks like this was fixed in 2.064.

What version of the compiler are you using?

-Steve


2.077.0

It is really strange, it works now but there still seems to be 
some strangeness about forward references.


Thanks till now i guess :P


Postblit constructor

2018-02-28 Thread Jiyan via Digitalmars-d-learn

Hey,
i thought i had understood postblit, but in my Code the following 
is happening (simplified):


struct C
{
this(this){/*Do sth*/}
list!C;

void opAssign(const C c)
{
 "Postlbit from C called".writeln;
 // Do sth
}
}

struct list(T)
{
node* head;
node* last;
size_t size;

struct node
{
T val;
node* next;
node* prev;

void deleteNode()
{
static if(!isPointer!T){
static if(__traits(compiles,val.__xdtor))val.__xdtor;
}
}

void constructNodeFrom(ref const T op)
{
 static if(isPointer!T)
 {
  val = cast(T) op;
 }
 else
 {
  val.opAssign(op);
 }
}

~this(){this.erase}
 /// Methods Add, Remove, erase are implemented here ...
}

The nodes are only allocated over malloc(). So i have to take 
care of the initioalisation myself.
The problem is, that i found out by debugging, that it seems that 
when i call val.opAssign(op) in constructNodeFrom(), there isnt 
any postblit constructor called in there, the struct seems just 
to get copied by a memcpy, can that be? Or is it a bug? Shouldnt 
the postblit constructor get called there?


Greetings


Re: Postblit constructor

2018-02-28 Thread Jiyan via Digitalmars-d-learn

On Wednesday, 28 February 2018 at 18:23:04 UTC, Jiyan wrote:

Hey,
i thought i had understood postblit, but in my Code the 
following is happening (simplified):


struct C
{
this(this){/*Do sth*/}
list!C;

void opAssign(const C c)
{
 "Postlbit from C called".writeln;
 // Do sth
}
}


Sry of course it is

"Postlbit from C called".writeln; in this(this)
and the c from opAssign should get constructed via postblit. 
Doesnt it?