Re: Issues with std.format template function

2017-08-14 Thread HyperParrow via Digitalmars-d-learn

On Tuesday, 15 August 2017 at 04:44:25 UTC, LeqxLeqx wrote:

Hello!

I'm having issues with the format function.

My program is as follows:


  import std.format;
  import std.stdio;

  int main ()
  {

auto s = format!"%s is %s"("Pi", 3.14);
writeln(s); // "Pi is 3.14";

  }




and when compiling with GDC, I'm getting this error:

  test.d:8: error: template instance format!"format is �i{" 
template '{ih��


 ���

P��

   @P�  �N� P��

 ' is not defined


I do not know why. Any help would be much appreciated!


Thank you all!


GDC front-end is based on DMD 2.068.2 but the feature you use 
(format specifier as template parameter) is only there since DMD 
2.075. The error comes from the fact that you read the online 
documentation which is not valid for GDC.


with GDC you can only does unchecked fmt:

`auto s = format("%s is %s", "Pi", 3.14);`


Re: Persistent Storage

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

On Friday, 11 August 2017 at 22:21:53 UTC, Mr. Pib wrote:
Does D have a persistent storage somewhere? I'd like something 
easy to use that allows me to load and save settings to disk in 
between executions of the program. I want to specify the 
variable to be saved or loaded and a default value.


e.g.,

Persist_Load(Some_variable, 100);

will load Some_variable from disk. If the storage does not 
exist on disk it will use the value 100.


It should manage the variables internally so it knows what is 
what. I don't mind actually specifying some_variable as a 
string to do this or using mixins and templates to achieve 
this, but it should be a one liner thing.


Try a serialization library or inifiled. Some may even use a DB 
with ORM for this.


https://code.dlang.org/packages/inifiled
https://code.dlang.org/packages/jsonizer
https://code.dlang.org/packages/asdf
https://code.dlang.org/packages/yamlserialized

etc... there are much.


Re: __dtor vs __xdtor

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

On Friday, 11 August 2017 at 17:10:14 UTC, bitwise wrote:

On Friday, 11 August 2017 at 17:02:20 UTC, HyperParrow wrote:

On Friday, 11 August 2017 at 16:53:02 UTC, bitwise wrote:

What do they do?
What's the difference?

Thanks


__xdtor() also calls the __dtor() that are mixed with template 
mixins while __dtor() only call the __dtor() that matches to 
the normal ~this(){}


Ok thanks.

I don't understand why you would ever want to call __dtor 
then...


Indeed. And there's also another one for the field called 
__fieldDtor.


is it possible to have only __dtor without also having __xdtor? 
Like, if I want to call a struct's destructor, do I have to 
check for both, or can I just always check for, and call 
__xdtor?


Always use __xdtor unless you know there's no other destructor to 
call.
Actually these functions are an implementation details and should 
be only used for low level things like custom memory handling.


You can look at core/lifetime.d to see how it's used by the d 
runtime.





Re: __dtor vs __xdtor

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

On Friday, 11 August 2017 at 17:12:22 UTC, bitwise wrote:

On Friday, 11 August 2017 at 17:06:40 UTC, HyperParrow wrote:
[...]

int i;
struct Foo
{
template ToMix(){ ~this(){i;}}
~this(){++i;}
mixin ToMix;
}

void main()
{
Foo* foo = new Foo;
foo.__xdtor;
assert(i==3);
Foo* other = new Foo;
foo.__dtor;
assert(i==4); // and not 6 ;)
}
=


I think you mean assert(i == 1) for the second one, right?


I made a mistake but it's not about i, which is a global.
I meant "other.__dtor." just before the last assert.
This doesn't change the results.


Re: __dtor vs __xdtor

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

On Friday, 11 August 2017 at 17:02:20 UTC, HyperParrow wrote:

On Friday, 11 August 2017 at 16:53:02 UTC, bitwise wrote:

What do they do?
What's the difference?

Thanks


__xdtor() also calls the __dtor() that are mixed with template 
mixins while __dtor() only call the __dtor() that matches to 
the normal ~this(){}


Nice example that speaks by itself:

=
int i;
struct Foo
{
template ToMix(){ ~this(){i;}}
~this(){++i;}
mixin ToMix;
}

void main()
{
Foo* foo = new Foo;
foo.__xdtor;
assert(i==3);
Foo* other = new Foo;
foo.__dtor;
assert(i==4); // and not 6 ;)
}
=


Re: __dtor vs __xdtor

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

On Friday, 11 August 2017 at 16:53:02 UTC, bitwise wrote:

What do they do?
What's the difference?

Thanks


__xdtor() also calls the __dtor() that are mixed with template 
mixins while __dtor() only call the __dtor() that matches to the 
normal ~this(){}


Re: DlangUI Error

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

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

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!


Small confusion from my part.

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).


I have no idea of what is this script. Actually i don't use 
dlangui at all.

I stop here.


Re: string hash significant speedup

2017-08-10 Thread HyperParrow via Digitalmars-d-learn
On Thursday, 10 August 2017 at 20:07:35 UTC, Steven Schveighoffer 
wrote:

On 8/10/17 3:36 PM, Johnson Jones wrote:
when using T[string], hashing is used. Computing the hash is 
slow(relatively speaking).


Does D cache the hashes? Strings are immutable so there is 
absolutely no reason why the hash ever need to be computed 
more than once.


It computes them on insertion, and caches the result in the 
structure of the hash table.


-Steve


But i think he speaks about the strings that are tested for 
inclusion (i.e opIn RHS), not those who are inserted, for which 
obviously the hash is known.


Re: DlangUI Error

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

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).