Re: Need help to get OpenSSL 64 work on Windows x64 | I hate D's GC!

2017-07-15 Thread Ali Çehreli via Digitalmars-d-learn

On 07/15/2017 03:05 PM, tetyys wrote:

On Friday, 14 July 2017 at 17:24:05 UTC, Suliman wrote:

GC on 32-bit machine show a lot of bugs.


such as..?


D's GC is conservative i.e. it cannot assume an integer is not a 
pointer. There are ways around this such as marking the memory block as 
not containing pointers but in general, if the language allows you to 
cast a pointer to integer, it's possible that any integer may be the 
only reference to a GC memory.


The problem with 32-bit is, it's very likely that an integer value may 
happen to have a value that equals to an address into GC memory. This 
happens when you allocate e.g. half gigabyte memory, read a file into 
it. So far so good. Unfortunately, it's likely that there is some 
integer in the program that points into this half a gig memory and the 
GC will never release it.


Ali



Re: Add property setting to chain

2017-07-15 Thread Ali Çehreli via Digitalmars-d-learn

On 07/15/2017 12:53 PM, closescreen wrote:

Let i have code:

Clock.currTime.to!DateTime.Interval!DateTime( 24.hours ).fwdRange(
h=>h+1.hours ).writeln;

Now if i want to set the minute=0 and second=0 without breaking chain,
what i should do?


I think about somewhat like:

with( Clock.currTime.to!DateTime){
 minute=0;
 second=0
}.Interval!DateTime( 24.hours ).fwdRange( h=>h+1.hours ).writeln;

But it is wrong, because 'with' not return me anything.


I would probably write a function:

import std.datetime;
import std.stdio;
import std.range;
import std.conv;

DateTime hourPrecision(DateTime dt) {
dt.minute = 0;
dt.second = 0;
return dt;
}

void main() {
Clock.currTime.to!DateTime.hourPrecision.Interval!DateTime( 
24.hours ).fwdRange( h=>h+1.hours ).writeln;

}

Ali



Re: Auto-decoding

2017-07-15 Thread Seb via Digitalmars-d-learn

On Saturday, 15 July 2017 at 18:47:25 UTC, Joakim wrote:

On Saturday, 15 July 2017 at 18:14:48 UTC, aberba wrote:

So what is the current plan? :)


Andrei has talked about having a non-auto-decoding path for 
those who know what they're doing and actively choose that 
path, while keeping auto-decoding the default, so as not to 
break existing code.  Jack has been submitting PRs for this, 
but it is probably tedious work, so progress is slow and I 
don't know how much more remains to be done:


https://github.com/dlang/phobos/pulls?q=is%3Apr+auto-decoding+is%3Aclosed


The idea is that once DIP1000 has matured, more focus on compiler 
support for reference-counting will be given with the aim of 
improving the @nogc experience. One example is DIP1008 for @nogc 
exceptions [1], but another one that is important in this context 
is RCString [2]. The idea is that RCString will be a new opt-in 
string type without auto-decoding and GC.


Another idea in the game is `version(NoAutoDecode)`:

https://github.com/dlang/phobos/pull/5513

However, here's unfortunately still unclear whether that could 
result in a working solution.


[1] https://github.com/dlang/DIPs/blob/master/DIPs/DIP1008.md
[2] https://github.com/dlang/phobos/pull/4878


Re: Need help to get OpenSSL 64 work on Windows x64 | I hate D's GC!

2017-07-15 Thread tetyys via Digitalmars-d-learn

On Friday, 14 July 2017 at 17:24:05 UTC, Suliman wrote:

GC on 32-bit machine show a lot of bugs.


such as..?


Re: Add property setting to chain

2017-07-15 Thread closescreen via Digitalmars-d-learn

I found this solution:

Clock.currTime.to!DateTime.pipe!( dt=>(dt.minute=0,dt.second=0, 
dt) ).Interval!DateTime( 24.hours ).fwdRange( h=>h+1.hours 
).writeln;


Or:

Clock.currTime.to!DateTime.pipe!( "a.minute=0, a.second=0, a" 
).Interval!DateTime( 24.hours ).fwdRange( h=>h+1.hours ).writeln;




Is this code looks good, idiomatic?


Add property setting to chain

2017-07-15 Thread closescreen via Digitalmars-d-learn

Let i have code:

Clock.currTime.to!DateTime.Interval!DateTime( 24.hours 
).fwdRange( h=>h+1.hours ).writeln;


Now if i want to set the minute=0 and second=0 without breaking 
chain, what i should do?



I think about somewhat like:

with( Clock.currTime.to!DateTime){
 minute=0;
 second=0
}.Interval!DateTime( 24.hours ).fwdRange( h=>h+1.hours ).writeln;

But it is wrong, because 'with' not return me anything.


Re: Auto-decoding

2017-07-15 Thread Joakim via Digitalmars-d-learn

On Saturday, 15 July 2017 at 18:14:48 UTC, aberba wrote:

On Saturday, 15 July 2017 at 05:54:32 UTC, ag0aep6g wrote:

On 07/15/2017 06:21 AM, bauss wrote:

[...]


1) Drop two elements from "Bär". With auto-decoding you get 
"r", which is nice. Without auto-decoding you get [0xA4, 'r'] 
where 0xA4 is the second half of the encoding of 'ä'. You have 
to know your Unicode to understand what is going on there.


[...]


So what is the current plan? :)


Andrei has talked about having a non-auto-decoding path for those 
who know what they're doing and actively choose that path, while 
keeping auto-decoding the default, so as not to break existing 
code.  Jack has been submitting PRs for this, but it is probably 
tedious work, so progress is slow and I don't know how much more 
remains to be done:


https://github.com/dlang/phobos/pulls?q=is%3Apr+auto-decoding+is%3Aclosed


Re: rdmd issues

2017-07-15 Thread Joakim via Digitalmars-d-learn

On Thursday, 6 July 2017 at 00:31:04 UTC, FoxyBrown wrote:

rdmd -m64 Build.d
Error: can't run 'C:\Program 
Files\VS\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64', check PATH


The path exists, but since it doesn't tell me what it is trying 
to run, I have no clue. The path contains link.exe.


Add the --chatty command-line option, it will tell you everything 
rdmd is trying to do.


Re: Auto-decoding

2017-07-15 Thread ag0aep6g via Digitalmars-d-learn

On 07/15/2017 08:14 PM, aberba wrote:

So what is the current plan? :)


As far as I'm aware, there's no concrete plan to change anything. We 
just gotta deal with auto-decoding for the time being.


Re: Auto-decoding

2017-07-15 Thread aberba via Digitalmars-d-learn

On Saturday, 15 July 2017 at 05:54:32 UTC, ag0aep6g wrote:

On 07/15/2017 06:21 AM, bauss wrote:

[...]


1) Drop two elements from "Bär". With auto-decoding you get 
"r", which is nice. Without auto-decoding you get [0xA4, 'r'] 
where 0xA4 is the second half of the encoding of 'ä'. You have 
to know your Unicode to understand what is going on there.


[...]


So what is the current plan? :)


Re: stacktrace for InvalidMemoryOperationError

2017-07-15 Thread Joakim via Digitalmars-d-learn

On Tuesday, 11 July 2017 at 01:34:08 UTC, crimaniak wrote:

Hi!

I have vibe.d application and long-standing error in it.
For the current moment, I have logs for stdout, stderr, and 
additional log to write exceptions I catch. This error gives me 
only the short line in stderr log:


core.exception.InvalidMemoryOperationError@src/core/exception.d(696): Invalid 
memory operation


Also, I use registerMemoryErrorHandler(); (see 
http://vibed.org/docs#handling-segmentation-faults )


What else can I do to have the stack trace for this error?

I can't debug it because I don't have it on my developer's 
machine.


See the wiki page about this:

https://wiki.dlang.org/InvalidMemoryOperationError

If you can't do all that, look for places you might be allocating 
in a destructor.  The recent GC allocation flag -vgc might help:


https://dlang.org/blog/2017/06/16/life-in-the-fast-lane/


Re: Implementing interface in the class hierarchy

2017-07-15 Thread Arek via Digitalmars-d-learn
On Friday, 14 July 2017 at 12:31:49 UTC, Steven Schveighoffer 
wrote:



Relevant enhancement request:
https://issues.dlang.org/show_bug.cgi?id=2565

-Steve


So it looks like there are no rational arguments for such a 
language specification, and this behavior is derived from some 
aspect of the compiler implementation.


Thanks

Arek


Re: sorting a string

2017-07-15 Thread Gerald Jansen via Digitalmars-d-learn

On Friday, 14 July 2017 at 20:52:54 UTC, Jonathan M Davis wrote:
And of course, this whole issue is incredibly confusing to 
anyone
coming to D - especially those who aren't well-versed in 
Unicode.


Right on. Thanks for your very clear summary (the whole thing, 
not just the last line!). Much appreciated.


How to initialize the Variant variable with the default value using TypeInfo?

2017-07-15 Thread RedCAT via Digitalmars-d-learn
I have only TypeInfo taken dynamically from an arbitrary type, 
and I need to initialize the Variant variable to the default 
value for this type. How can I do that?


I tried this:

TypeInfo ti = typeid(int);
Variant v = ti.initializer;

But after,

int o = v.get!int;

and

int o = v.coerce!int;

doesn't work.




Re: Exported Class Error

2017-07-15 Thread Damien Gibson via Digitalmars-d-learn

TypeInfo doesn't cross the dll boundary atm on Windows.
Known bug.

Which means no classes or exceptions.

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


oh how lovely


Re: Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Morimur55 via Digitalmars-d-learn

On Saturday, 15 July 2017 at 14:46:17 UTC, Adam D. Ruppe wrote:

On Saturday, 15 July 2017 at 14:36:40 UTC, Morimur55 wrote:
...let me try that again without accidentally sending it 
before I'd finished...


tab on the web interface is so useful... but so annoying 
sometimes too.


...and I think my problem is actually that redeclared static 
variables update on the base class if called from a base class 
function?


Yeah, member variables are always directly attached to the 
class they are on, no virtualness there.


Why are you redeclaring it? A virtual property getter/setter 
pair might be what you need.



I'm reading in some objects from yaml, assigning them incremental 
ids per type so they can be queried and changed at runtime with 
Lua by another programmer, and then spat back out as yaml when 
they're done.


Mostly redeclaring because I tried it, didn't get a compiler 
error, so I thought it'd just work the way I imagined it would. 
What can I say, I like to live dangerously. :p


Thanks for your help, I'll put in some virtual properties and 
hope for the best.




Re: Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Adam D. Ruppe via Digitalmars-d-learn

On Saturday, 15 July 2017 at 14:36:40 UTC, Morimur55 wrote:
...let me try that again without accidentally sending it before 
I'd finished...


tab on the web interface is so useful... but so annoying 
sometimes too.


...and I think my problem is actually that redeclared static 
variables update on the base class if called from a base class 
function?


Yeah, member variables are always directly attached to the class 
they are on, no virtualness there.


Why are you redeclaring it? A virtual property getter/setter pair 
might be what you need.


Re: Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Morimur55 via Digitalmars-d-learn

On Saturday, 15 July 2017 at 14:26:30 UTC, Morimur55 wrote:

On Saturday, 15 July 2017 at 14:04:17 UTC, Adam D. Ruppe wrote:

On Saturday, 15 July 2017 at 13:45:40 UTC, Morimur55 wrote:
Well I want to cast to the derived type so I can use a method 
that's defined in the base class, but is overridden in 
several of the derived types... and calling it without a cast 
seems to give me the base type functionality, but I'd like 
the derived type functionality when it's defined.


That means you're doing something wrong. What does your base 
class method look like? Is it a template?


class Base {
private static int idcounter = 0;
int nextid(){ return ++idcounter }
}

class Derrived {


...let me try that again without accidentally sending it before 
I'd finished...


class Base {
private static int idcounter = 0;
int nextid(){ return ++idcounter }
} //nextid updates Base.idcounter

class Derived {
private static int idcounter = 1000;
private static int derivedcounter = 0;
override int nextid(){
derivedcounter++;
return ++idcounter
}
} //nextid updates Derived.idcounter and Derived.derivedcounter

class Derived2 {
private static int idcounter = 2000;
} //nextid updates Base.idcounter :(

...and I think my problem is actually that redeclared static 
variables update on the base class if called from a base class 
function?


Re: Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Morimur55 via Digitalmars-d-learn

On Saturday, 15 July 2017 at 14:04:17 UTC, Adam D. Ruppe wrote:

On Saturday, 15 July 2017 at 13:45:40 UTC, Morimur55 wrote:
Well I want to cast to the derived type so I can use a method 
that's defined in the base class, but is overridden in several 
of the derived types... and calling it without a cast seems to 
give me the base type functionality, but I'd like the derived 
type functionality when it's defined.


That means you're doing something wrong. What does your base 
class method look like? Is it a template?


class Base {
private static int idcounter = 0;
int nextid(){ return ++idcounter }
}

class Derrived {



Re: Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Nicholas Wilson via Digitalmars-d-learn

On Saturday, 15 July 2017 at 13:45:40 UTC, Morimur55 wrote:

On Saturday, 15 July 2017 at 13:12:49 UTC, Adam D. Ruppe wrote:

On Saturday, 15 July 2017 at 13:02:52 UTC, Morimur55 wrote:

[...]


The `typeid(obj)` will give the type... but why do you need 
it? The classinfo returned by that doesn't give a lot of info.


Casting is how you actually get the object, though you might 
be better off putting the necessary methods in the base class.


Well I want to cast to the derived type so I can use a method 
that's defined in the base class, but is overridden in several 
of the derived types... and calling it without a cast seems to 
give me the base type functionality, but I'd like the derived 
type functionality when it's defined.


It should work, please post some test code.

We have a syntax If you want to call a method from a different 
class on an object:

A a;
a.B.foo(); // call a.foo as if `a` were a B


I have a lot of derived types, some of which may be added in 
future by someone else... was hoping something like 
`cast(typeid(obj))` was going to work... but my compiler 
doesn't like that :(


Re: Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Adam D. Ruppe via Digitalmars-d-learn

On Saturday, 15 July 2017 at 13:45:40 UTC, Morimur55 wrote:
Well I want to cast to the derived type so I can use a method 
that's defined in the base class, but is overridden in several 
of the derived types... and calling it without a cast seems to 
give me the base type functionality, but I'd like the derived 
type functionality when it's defined.


That means you're doing something wrong. What does your base 
class method look like? Is it a template?


Re: Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Morimur55 via Digitalmars-d-learn

On Saturday, 15 July 2017 at 13:12:49 UTC, Adam D. Ruppe wrote:

On Saturday, 15 July 2017 at 13:02:52 UTC, Morimur55 wrote:
is there a way to check without attempting to cast to every 
derived type?


The `typeid(obj)` will give the type... but why do you need it? 
The classinfo returned by that doesn't give a lot of info.


Casting is how you actually get the object, though you might be 
better off putting the necessary methods in the base class.


Well I want to cast to the derived type so I can use a method 
that's defined in the base class, but is overridden in several of 
the derived types... and calling it without a cast seems to give 
me the base type functionality, but I'd like the derived type 
functionality when it's defined.


I have a lot of derived types, some of which may be added in 
future by someone else... was hoping something like 
`cast(typeid(obj))` was going to work... but my compiler doesn't 
like that :(


Re: Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Adam D. Ruppe via Digitalmars-d-learn

On Saturday, 15 July 2017 at 13:02:52 UTC, Morimur55 wrote:
is there a way to check without attempting to cast to every 
derived type?


The `typeid(obj)` will give the type... but why do you need it? 
The classinfo returned by that doesn't give a lot of info.


Casting is how you actually get the object, though you might be 
better off putting the necessary methods in the base class.


Get which derived class an object is if it's stored in an array of its base class

2017-07-15 Thread Morimur55 via Digitalmars-d-learn
I've got a bunch of different classes all derived from the same 
base class sitting in a base[]. I need to check what the derived 
types are of these objects - is there a way to check without 
attempting to cast to every derived type?


Re: Exception handling

2017-07-15 Thread ANtlord via Digitalmars-d-learn

On Friday, 14 July 2017 at 20:22:21 UTC, Ali Çehreli wrote:

On 07/14/2017 12:36 PM, ANtlord wrote:

All you need is to catch Exception there as well:

catch(Exception) {
assert(false, "throwable_fn threw something 
unexpected");

}

Ali


Thank you, Ali! You answer for my question again.

Again, this depends on the exact internals available at the 
semantic analysis time, but in theory, it should be possible 
that when a ThrowStatement is encountered, the surrounding 
scope aggregates the exception's type in it's aggregated 
exception set (ignoring things not inherited from Exception).


Sounds good. It doesn't appear too hard for implementation. But I 
tried to understand dmd architecture at least 5 times. 
Unfortunaly I can't get it. If there is a thing for talking 
closer then it can help to ask mini questions. I mean something 
like Slack or Telegram.


Re: ddox filters out my doc

2017-07-15 Thread Jean-Louis Leroy via Digitalmars-d-learn

On Saturday, 15 July 2017 at 08:55:41 UTC, Mike Parker wrote:
On Saturday, 15 July 2017 at 08:29:52 UTC, Jean-Louis Leroy 
wrote:



My module has a name in dub.sdl.


No, it does not. That's the name of the DUB project. The module 
in this case is source/methods.d. I've never used ddox, but 
based on what I see in the readme and on looking at the ddox 
source where that specific error message is displayed, if I 
were you my first attempt at resolving this would be to add a 
module declaration to the top of methods.d and try again:


module methods;

import std.traits;
import...


Aaaah yes that fixed it. I suspected it was something *that* 
simple. Thanks a bunch.


J-L


Re: ddox filters out my doc

2017-07-15 Thread Mike Parker via Digitalmars-d-learn

On Saturday, 15 July 2017 at 08:29:52 UTC, Jean-Louis Leroy wrote:


My module has a name in dub.sdl.


No, it does not. That's the name of the DUB project. The module 
in this case is source/methods.d. I've never used ddox, but based 
on what I see in the readme and on looking at the ddox source 
where that specific error message is displayed, if I were you my 
first attempt at resolving this would be to add a module 
declaration to the top of methods.d and try again:


module methods;

import std.traits;
import...


ddox filters out my doc

2017-07-15 Thread Jean-Louis Leroy via Digitalmars-d-learn
I began to write documentation for my open method library. After 
googling around quite a bit, I came across the incantation:


dub build -b ddox

Problem is, it generates no doc. And I believe that it actually 
says so:


Performing "ddox" build using dmd for x86_64.
methods ~genesis: building configuration "library"...
Performing "debug" build using dmd for x86_64.
[...]
Running ../../../.dub/packages/ddox-0.16.2/ddox/ddox filter 
--min-protection=Protected --only-documented docs.json

Reading doc file...
Parsing JSON...
Filtering modules...
No name for module source/methods.d - ignoring
Writing filtered docs...

My module has a name in dub.sdl. After running ddox I see that an 
empty docs.json has been created in my root dir. Maybe I must put 
things in there? But I haven't found such a file in several dlang 
projects I have sought inspiration from...


Project is here: https://github.com/jll63/meth.d/tree/genesis and 
the exact snapshot I am using is here: 
https://github.com/jll63/meth.d/tree/28b3419a6f5f9936fb95e906fc990e00568a32f8