Re: [SDL + TKD] Seg fault from creating DirectoryDialog

2014-11-05 Thread Gary Willoughby via Digitalmars-d-learn

On Tuesday, 4 November 2014 at 23:09:33 UTC, Jack wrote:
So there must be an incompatibility with the video subsystem 
and tcl/tk.


So it seems. Thank you very much for helping me.
You were a big help.


Sorry i can't do more. I'm the author of Tkd and would like to 
get to the bottom of it.


druntime vararg implementation

2014-11-05 Thread Mike via Digitalmars-d-learn

Greetings,

In core.varar. 
(https://github.com/D-Programming-Language/druntime/blob/master/src/core/vararg.d), 
why is the X86 implementation singled out and written in D rather 
than leveraging the standard c library implementation like the 
others?


Mike


Access Violation Tracking

2014-11-05 Thread Bauss via Digitalmars-d-learn
Is there any way to track down access violations, instead of me 
having to look through my source code manually.


I have a pretty big source code and an access violation happens 
at runtime, but it's going to be a nightmare looking through it 
all to find the access violation. Not to mention all the tests I 
have to run.


So if there is a way to catch an access violation and find out 
where it occured it would be appreciated!


Re: Access Violation Tracking

2014-11-05 Thread thedeemon via Digitalmars-d-learn

On Wednesday, 5 November 2014 at 11:09:42 UTC, Bauss wrote:
Is there any way to track down access violations, instead of me 
having to look through my source code manually.


I have a pretty big source code and an access violation happens 
at runtime, but it's going to be a nightmare looking through it 
all to find the access violation. Not to mention all the tests 
I have to run.


So if there is a way to catch an access violation and find out 
where it occured it would be appreciated!


What OS are you using? Did you run any debugger?


Re: Access Violation Tracking

2014-11-05 Thread bearophile via Digitalmars-d-learn

Bauss:

Is there any way to track down access violations, instead of me 
having to look through my source code manually.


I have a pretty big source code and an access violation happens 
at runtime, but it's going to be a nightmare looking through it 
all to find the access violation. Not to mention all the tests 
I have to run.


So if there is a way to catch an access violation and find out 
where it occured it would be appreciated!


This was discussed some times, and Walter is against this, but I 
think he is wrong, and eventually things will change. So I think 
this discussion should be brought to the main D newsgroup again.


Ideally in non-release mode D should put asserts where a access 
violation could happen. But I don't know how much slowdown this 
will cause. If practical real tests show that the slowdown is 
excessive, then a compiler switch could be added to activate 
those asserts.


Bye,
bearophile


Re: Access Violation Tracking

2014-11-05 Thread via Digitalmars-d-learn

On Wednesday, 5 November 2014 at 11:09:42 UTC, Bauss wrote:
Is there any way to track down access violations, instead of me 
having to look through my source code manually.


I have a pretty big source code and an access violation happens 
at runtime, but it's going to be a nightmare looking through it 
all to find the access violation. Not to mention all the tests 
I have to run.


So if there is a way to catch an access violation and find out 
where it occured it would be appreciated!


If you're on Linux, you can turn SEGVs into Errors:

import etc.linux.memoryerror;
registerMemoryErrorHandler();


Re: Access Violation Tracking

2014-11-05 Thread Bauss via Digitalmars-d-learn

On Wednesday, 5 November 2014 at 11:27:02 UTC, thedeemon wrote:

On Wednesday, 5 November 2014 at 11:09:42 UTC, Bauss wrote:
Is there any way to track down access violations, instead of 
me having to look through my source code manually.


I have a pretty big source code and an access violation 
happens at runtime, but it's going to be a nightmare looking 
through it all to find the access violation. Not to mention 
all the tests I have to run.


So if there is a way to catch an access violation and find out 
where it occured it would be appreciated!


What OS are you using? Did you run any debugger?


I am running Windows, but I am not using any debugger.
I was more looking for a build in function.

On Wednesday, 5 November 2014 at 11:31:01 UTC, bearophile wrote:

Bauss:

Is there any way to track down access violations, instead of 
me having to look through my source code manually.


I have a pretty big source code and an access violation 
happens at runtime, but it's going to be a nightmare looking 
through it all to find the access violation. Not to mention 
all the tests I have to run.


So if there is a way to catch an access violation and find out 
where it occured it would be appreciated!


This was discussed some times, and Walter is against this, but 
I think he is wrong, and eventually things will change. So I 
think this discussion should be brought to the main D newsgroup 
again.


Ideally in non-release mode D should put asserts where a access 
violation could happen. But I don't know how much slowdown this 
will cause. If practical real tests show that the slowdown is 
excessive, then a compiler switch could be added to activate 
those asserts.


Bye,
bearophile
I agree with you completely thathe is wrong. There should 
definitely be a way to find access violations within the program. 
I cannot add asserts and checks everywhere since performance is 
my number one priority within my program, so I have to make sure 
that the access violation cannot happen in the first place.
However it's a bit hard to track down access violations in big 
programs if you don't know when exactly it occured and where 
exactly it occured.


Re: Access Violation Tracking

2014-11-05 Thread Bauss via Digitalmars-d-learn

On Wednesday, 5 November 2014 at 11:39:21 UTC, Marc Schütz wrote:

On Wednesday, 5 November 2014 at 11:09:42 UTC, Bauss wrote:
Is there any way to track down access violations, instead of 
me having to look through my source code manually.


I have a pretty big source code and an access violation 
happens at runtime, but it's going to be a nightmare looking 
through it all to find the access violation. Not to mention 
all the tests I have to run.


So if there is a way to catch an access violation and find out 
where it occured it would be appreciated!


If you're on Linux, you can turn SEGVs into Errors:

import etc.linux.memoryerror;
registerMemoryErrorHandler();


I am on Windows, but thanks that might come in handy when I have 
to test my program on other platforms.


cannot sort an array of char

2014-11-05 Thread Ivan Kazmenko via Digitalmars-d-learn

Hi!

This gives an error (cannot deduce template function from 
argument types):


-
import std.algorithm;
void main () {
char [] c;
sort (c);
}
-

Why is char [] so special that it can't be sorted?

For example, if I know the array contains only ASCII characters, 
sorting it sounds no different to sorting an int [].


Ivan Kazmenko.


scope exception do not rise

2014-11-05 Thread Suliman via Digitalmars-d-learn

void openFile(string fname, string current_folder)
{
auto file = readText(current_folder ~ fname);
scope(failure)
{
writeln(failure);
}

//  writeln(file);

}

if file name do not exists, I want to rise scope exception. But 
it's do not rise, and I am getting only standard error like:


std.file.FileException@std\file.d(191): 
D:\code\d\App1\source\app.d1: ╨Э╨╡ ╤Г╨┤╨

░╨╡╤В╤Б╤П ╨╜╨░╨╣╤В╨╕ ╤Г╨║╨░╨╖╨░╨╜╨╜╤Л╨╣ ╤Д╨░╨╣╨╗.


what's wrong? if I use block success it's work fine.


Re: cannot sort an array of char

2014-11-05 Thread via Digitalmars-d-learn
On Wednesday, 5 November 2014 at 12:54:03 UTC, Ivan Kazmenko 
wrote:

Hi!

This gives an error (cannot deduce template function from 
argument types):


-
import std.algorithm;
void main () {
char [] c;
sort (c);
}
-

Why is char [] so special that it can't be sorted?

For example, if I know the array contains only ASCII 
characters, sorting it sounds no different to sorting an int 
[].


Hmm... this doesn't work either:

import std.algorithm;
import std.utf;
void main () {
char [] c;
sort (c.byCodeUnit);
}

But IMO it should.


Re: cannot sort an array of char

2014-11-05 Thread via Digitalmars-d-learn

On Wednesday, 5 November 2014 at 13:34:05 UTC, Marc Schütz wrote:
On Wednesday, 5 November 2014 at 12:54:03 UTC, Ivan Kazmenko 
wrote:

Hi!

This gives an error (cannot deduce template function from 
argument types):


-
import std.algorithm;
void main () {
char [] c;
sort (c);
}
-

Why is char [] so special that it can't be sorted?

For example, if I know the array contains only ASCII 
characters, sorting it sounds no different to sorting an int 
[].


Hmm... this doesn't work either:

import std.algorithm;
import std.utf;
void main () {
char [] c;
sort (c.byCodeUnit);
}

But IMO it should.


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


Re: scope exception do not rise

2014-11-05 Thread Suliman via Digitalmars-d-learn
I can't understand what I am missing. Try-catch block also do not 
handle exception:


void main()
{
string fname = app.d1; //file name with error
string current_folder = (getcwd() ~\\);
writeln(current_folder);
openFile(fname, current_folder);
}

void openFile(string fname, string current_folder)
{
try
{
auto file = readText(current_folder ~ fname);
if(exists(current_folder ~ fname))
scope(success)
writeln(success);
}

catch(Exception e)
{
writeln(e); //what class of error I am handling? any?
}


}


Re: scope exception do not rise

2014-11-05 Thread MadProgressor via Digitalmars-d-learn

On Wednesday, 5 November 2014 at 12:56:41 UTC, Suliman wrote:

void openFile(string fname, string current_folder)
{
auto file = readText(current_folder ~ fname);
scope(failure)
{
writeln(failure);
}

//  writeln(file);

}

if file name do not exists, I want to rise scope exception. But 
it's do not rise, and I am getting only standard error like:


std.file.FileException@std\file.d(191): 
D:\code\d\App1\source\app.d1: ╨Э╨╡ ╤Г╨┤╨

░╨╡╤В╤Б╤П ╨╜╨░╨╣╤В╨╕ ╤Г╨║╨░╨╖╨░╨╜╨╜╤Л╨╣ ╤Д╨░╨╣╨╗.


what's wrong? if I use block success it's work fine.


Try:

scope(failure){writeln(failure);}
auto file = readText(current_folder ~ fname);


The scope(failure) is translated to a try catch after the 
satement you wann monitor.

So put it before


Re: scope exception do not rise

2014-11-05 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 5 November 2014 at 14:04:26 UTC, MadProgressor 
wrote:
The scope(failure) is translated to a try catch after the 
satement you wann monitor.

So put it before


That shouldn't matter. See: http://dlang.org/exception-safe.html


Re: Access Violation Tracking

2014-11-05 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 5 November 2014 at 11:31:01 UTC, bearophile wrote:
This was discussed some times, and Walter is against this, but 
I think he is wrong, and eventually things will change.


An access violation already thrown on Win32. Just catch a 
Throwable in main and write out exception.toString. But you do 
need to have debugging info compiled in to get a readable 
backtrace with dmd -g.


Re: scope exception do not rise

2014-11-05 Thread ketmar via Digitalmars-d-learn
On Wed, 05 Nov 2014 14:09:20 +
Gary Willoughby via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com wrote:

 That shouldn't matter. See: http://dlang.org/exception-safe.html
this indeed matter. and it should.


signature.asc
Description: PGP signature


Re: druntime vararg implementation

2014-11-05 Thread Sean Kelly via Digitalmars-d-learn

On Wednesday, 5 November 2014 at 09:45:50 UTC, Mike wrote:

Greetings,

In core.varar. 
(https://github.com/D-Programming-Language/druntime/blob/master/src/core/vararg.d), 
why is the X86 implementation singled out and written in D 
rather than leveraging the standard c library implementation 
like the others?


No idea.  It seems like a pointless duplication of code.  Maybe 
just to have some documented functions within the module?


Re: scope exception do not rise

2014-11-05 Thread Suliman via Digitalmars-d-learn
Am I right understand that keyword Exception is handle 
universal type of exceptions?


catch (Exception)
{
writeln(inner);
}

But in my example with try block can I change it's to something 
more informative?


How to turn this C++ into D?

2014-11-05 Thread Patrick Jeeves via Digitalmars-d-learn
So this is more a stackoverflow question, but I feel like later 
searchers will be more likely to find it if I put it here.


if I have the following C++ code:

class foo
{
static std::listfoo* foo_list;
typedef std::listfoo*::iterator iterator;
public:
foo()
{
   foo_list.push_back(this);
}
~foo()
{
   foo_list.remove(this);
}

static void DO_TASK()
{
for(iterator i = foo_list.begin(); i  foo_list.end(); 
++i)

{
(*i)-process();
}

for(iterator i = foo_list.begin(); i  foo_list.end(); 
++i)

{
(*i)-advance();
}
}

virtual void process() = 0;
virtual void advance() = 0;
}

How can I turn this into D?  Is there a way to register that 
static list with the garbage collector so it doesn't look into it 
or anything?


Similarly, I feel like this would be an interface in D, but 
interfaces don't have constructors.


Re: cannot sort an array of char

2014-11-05 Thread Ali Çehreli via Digitalmars-d-learn

On 11/05/2014 05:44 AM, Marc Schütz schue...@gmx.net wrote:

On Wednesday, 5 November 2014 at 13:34:05 UTC, Marc Schütz wrote:

On Wednesday, 5 November 2014 at 12:54:03 UTC, Ivan Kazmenko wrote:

Hi!

This gives an error (cannot deduce template function from argument
types):

-
import std.algorithm;
void main () {
char [] c;
sort (c);
}
-

Why is char [] so special that it can't be sorted?

For example, if I know the array contains only ASCII characters,
sorting it sounds no different to sorting an int [].


Hmm... this doesn't work either:

import std.algorithm;
import std.utf;
void main () {
char [] c;
sort (c.byCodeUnit);
}

But IMO it should.


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


It can't be a RandomAccessRange because it cannot satisfy random access 
at O(1) time.


Ali



Re: How to turn this C++ into D?

2014-11-05 Thread Ali Çehreli via Digitalmars-d-learn

On 11/05/2014 09:17 AM, Patrick Jeeves wrote:

 class foo
 {
 static std::listfoo* foo_list;
 typedef std::listfoo*::iterator iterator;
 public:
  foo()
  {
 foo_list.push_back(this);
  }
  ~foo()
  {
 foo_list.remove(this);
  }

Going completely off-topic, I recommend against objects registering 
themselves that way. That idiom has caused trouble in more than one 
project for us.


In general, I think a constructor should not have side-effects unless 
needed for the object's construction (e.g. allocating a resource for the 
object should obviously fine).


Ali



Re: How to turn this C++ into D?

2014-11-05 Thread Ali Çehreli via Digitalmars-d-learn

On 11/05/2014 10:07 AM, Ali Çehreli wrote:

 On 11/05/2014 09:17 AM, Patrick Jeeves wrote:

   class foo
   {
   static std::listfoo* foo_list;
   typedef std::listfoo*::iterator iterator;
   public:
foo()
{
   foo_list.push_back(this);
}

Argh! I forgot to add an important, perhaps philosophical, point. :) 
Continuing the off-topic, an object should be considered constructed 
only after hitting that closing curly bracket above. If so, then that 
push_back would be adding an incomplete object to the list.


Ali



Re: How to turn this C++ into D?

2014-11-05 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 5 November 2014 at 18:10:38 UTC, Ali Çehreli wrote:
If so, then that push_back would be adding an incomplete object 
to the list.


scope(success)?


But the D translation worries me too because the destructor won't 
run at the same time as the C++ version, unless you make it a 
scope class or something.


Re: How to turn this C++ into D?

2014-11-05 Thread Ali Çehreli via Digitalmars-d-learn

On 11/05/2014 10:12 AM, Adam D. Ruppe wrote:

 On Wednesday, 5 November 2014 at 18:10:38 UTC, Ali Çehreli wrote:
 If so, then that push_back would be adding an incomplete object to the
 list.

 scope(success)?

I really like that! :)

But still not for this case because in addition to the problem with the 
destruction order, I would like to feel free to remove unused objects 
like the following without worrying about side-effects:


// C++ code
void bar()
{
Foo seemingly_unused_here();
// ...
}

Ali



Re: scope exception do not rise

2014-11-05 Thread Ali Çehreli via Digitalmars-d-learn

On 11/05/2014 06:01 AM, Suliman wrote:

 I can't understand what I am missing. Try-catch block also do not handle
 exception:

I does. This turned out to be very tricky for me. :)

 void main()
 {
  string fname = app.d1; //file name with error
  string current_folder = (getcwd() ~\\);
  writeln(current_folder);
  openFile(fname, current_folder);
 }

 void openFile(string fname, string current_folder)
 {
  try
  {
  auto file = readText(current_folder ~ fname);
  if(exists(current_folder ~ fname))
  scope(success)
  writeln(success);

Unrelated to the problem, but did you really want that scope(success) 
under the if statement?


  }

  catch(Exception e)
  {
  writeln(e); //what class of error I am handling? any?
  }

Replace that with something like writeln(caught) and you will see that 
it is indeed caught. :) Printing the exception mimicks the default 
behavior and you (and I) think that the exception is not caught. :)


Ali



Re: cannot sort an array of char

2014-11-05 Thread Ali Çehreli via Digitalmars-d-learn

On 11/05/2014 10:01 AM, Ali Çehreli wrote:

 sort (c.byCodeUnit);
 }

 But IMO it should.

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

 It can't be a RandomAccessRange because it cannot satisfy random access
 at O(1) time.

Sorry, I misunderstood (again): code unit is random-access, code point 
is not.


Ali

P.S. I would like to have a word with the Unicode people who settled on 
the terms code unit and code point. Every time I come across one of 
those, I have to think at least 5 seconds to fool myself to think that I 
understood correctly which one was meant. :p




Re: How to turn this C++ into D?

2014-11-05 Thread luminousone via Digitalmars-d-learn

On Wednesday, 5 November 2014 at 18:18:18 UTC, Ali Çehreli wrote:

On 11/05/2014 10:12 AM, Adam D. Ruppe wrote:

 On Wednesday, 5 November 2014 at 18:10:38 UTC, Ali Çehreli
wrote:
 If so, then that push_back would be adding an incomplete
object to the
 list.

 scope(success)?

I really like that! :)

But still not for this case because in addition to the problem 
with the destruction order, I would like to feel free to remove 
unused objects like the following without worrying about 
side-effects:


// C++ code
void bar()
{
Foo seemingly_unused_here();
// ...
}

Ali


unless delete is explicitly called, I don't believe the 
destructor would ever be called, it would still have a reference 
in the static foo_list object that would stop it from being 
collected by the gc.


I could see the constructor situation being a problem in threaded 
code as well, tho it may be bad practice, I don't believe the 
insert(this) would actually break anything.


The scope(success) is a good idea either way however.


Re: How to turn this C++ into D?

2014-11-05 Thread Patrick Jeeves via Digitalmars-d-learn

On Wednesday, 5 November 2014 at 18:56:08 UTC, luminousone wrote:
unless delete is explicitly called, I don't believe the 
destructor would ever be called, it would still have a 
reference in the static foo_list object that would stop it from 
being collected by the gc.


This is exactly why I asked about it, and even if delete is 
explicitly called-- which i believe is deprecated, wouldn't the 
runtime fill the space with the default construtor until the GC 
decides to remove it? meaning it would be immediatly added back 
into the list?


Re: How to turn this C++ into D?

2014-11-05 Thread luminousone via Digitalmars-d-learn
On Wednesday, 5 November 2014 at 19:05:32 UTC, Patrick Jeeves 
wrote:
On Wednesday, 5 November 2014 at 18:56:08 UTC, luminousone 
wrote:
unless delete is explicitly called, I don't believe the 
destructor would ever be called, it would still have a 
reference in the static foo_list object that would stop it 
from being collected by the gc.


This is exactly why I asked about it, and even if delete is 
explicitly called-- which i believe is deprecated, wouldn't the 
runtime fill the space with the default construtor until the GC 
decides to remove it? meaning it would be immediatly added back 
into the list?


I don't believe that the default constructor is called. I am 
pretty sure delete immediately deallocates the object, 
deregistering its memory from the gc.


In fact I am 99% sure no constructor is called after delete, it 
would cause problems for objects with no default constructor, or 
for system related stuff done in constructors, and I haven't seen 
anything like that in my X11 work in d.




Re: accessing numeric template parameters

2014-11-05 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn

On Monday, 3 November 2014 at 21:17:09 UTC, Philippe Sigaud via
Digitalmars-d-learn wrote:

struct polynomial(uint base)
{
private:
   uint[] N;
public:
   this(uint x) { base = x; }


base is part of the type. polynomial is just a 'recipe' for a 
type,
the real struct would be Polynomial!(0), Polynomial!(1), etc. 
Note

that Polynomial!0, Polynomial!1, ... are all different types.

Yes, that's what I intend.


Being part of the type means it's defined only at compile-time, 
you

cannot use a runtime value (like 'x') to initialize it.

Note that with your current code, `base' is not visible outside
Polynomial. You can alias it to a field to make it visible:

struct Polynomial(uint base)
{
alias b = base; // b is visible outside (but set at


Ah, ok. Thank you!


compile-time !)
...
}

You can create one like this:

Polynomial!2 poly;
poly.N = [0,1,0,0,1,1];

Ok, now I remember, struct doesn't need an explicit constructor.
(in this case)


Re: How to turn this C++ into D?

2014-11-05 Thread Patrick Jeeves via Digitalmars-d-learn

On Wednesday, 5 November 2014 at 19:44:57 UTC, luminousone wrote:
On Wednesday, 5 November 2014 at 19:05:32 UTC, Patrick Jeeves 
wrote:
On Wednesday, 5 November 2014 at 18:56:08 UTC, luminousone 
wrote:
unless delete is explicitly called, I don't believe the 
destructor would ever be called, it would still have a 
reference in the static foo_list object that would stop it 
from being collected by the gc.


This is exactly why I asked about it, and even if delete is 
explicitly called-- which i believe is deprecated, wouldn't 
the runtime fill the space with the default construtor until 
the GC decides to remove it? meaning it would be immediatly 
added back into the list?


I don't believe that the default constructor is called. I am 
pretty sure delete immediately deallocates the object, 
deregistering its memory from the gc.


In fact I am 99% sure no constructor is called after delete, it 
would cause problems for objects with no default constructor, 
or for system related stuff done in constructors, and I haven't 
seen anything like that in my X11 work in d.


I guess I got confused by something... I don't know.  But what 
I'd really like is for it to be garbage colleceted when no 
references outside of that static array exist, as i mentioned at 
the bottom of my first post.  I illustrated my example with that 
specific class because when i looked up weak pointers on the 
site I found discussions getting caught up with how to avoid 
dangling pointers when weak pointers are used; and I wanted to 
illustrate that that's a non-issue in this case, because I wasn't 
sure how much that contributed to the solutions given.


I suppose it doesn't matter because this is based on something I 
do with multiple inheritance in C++, I felt like I may be able to 
get it to work in D because the only public members of those 
classes were always pure virtual functions.


As an aside, how does scope(success) work in the context of a 
constructor? given:


abstract class foo
{
this()
{
   scope(success) onAdd();
}
~this()
{
   onRemove();
}

onAdd();
onRemove();
}

class bar : foo
{
int _a;

this(int a)
{
   _a = a;
}

void onAdd(){ writeln(_a); }
void onRemove() { writeln(_a); }
}

is _a defined as anything in either of writes? or would it be 
called at the wrong time relative to setting _a?


Curiously Cyclic Template Pattern causes segfault?

2014-11-05 Thread Patrick Jeeves via Digitalmars-d-learn


When I tried to test out the following code the compiler 
segfaulted:



interface BarBase
{
void do_a_thing();
}

interface Bar(T) : BarBase
{
	static if(hasMember!(T, rotation)  is(typeof(T.rotation) == 
double))

{
@property
double rotation();

final void do_a_thing()
{
//do a thing with rotation;
}
}
else
{
final void do_a_thing()
{
//do a thing without rotation;
}
}
}

class Foo1 : Bar!Foo1
{
}

class Foo2 : Bar!Foo2
{
@property
double rotation() { return 1.0; };
}

Is there some rule against doing this or is it a glitch?


Re: Curiously Cyclic Template Pattern causes segfault?

2014-11-05 Thread Justin Whear via Digitalmars-d-learn
On Wed, 05 Nov 2014 20:48:06 +, Patrick Jeeves wrote:

 When I tried to test out the following code the compiler segfaulted:
 
 Is there some rule against doing this or is it a glitch?

Please file a bug report on issues.dlang.org --any compiler crash is a bug
regardless of whether the source is valid D code or not.


Re: How to turn this C++ into D?

2014-11-05 Thread luminousone via Digitalmars-d-learn
On Wednesday, 5 November 2014 at 20:31:54 UTC, Patrick Jeeves 
wrote:
On Wednesday, 5 November 2014 at 19:44:57 UTC, luminousone 
wrote:
On Wednesday, 5 November 2014 at 19:05:32 UTC, Patrick Jeeves 
wrote:
On Wednesday, 5 November 2014 at 18:56:08 UTC, luminousone 
wrote:
unless delete is explicitly called, I don't believe the 
destructor would ever be called, it would still have a 
reference in the static foo_list object that would stop it 
from being collected by the gc.


This is exactly why I asked about it, and even if delete is 
explicitly called-- which i believe is deprecated, wouldn't 
the runtime fill the space with the default construtor until 
the GC decides to remove it? meaning it would be immediatly 
added back into the list?


I don't believe that the default constructor is called. I am 
pretty sure delete immediately deallocates the object, 
deregistering its memory from the gc.


In fact I am 99% sure no constructor is called after delete, 
it would cause problems for objects with no default 
constructor, or for system related stuff done in constructors, 
and I haven't seen anything like that in my X11 work in d.


I guess I got confused by something... I don't know.  But what 
I'd really like is for it to be garbage colleceted when no 
references outside of that static array exist, as i mentioned 
at the bottom of my first post.  I illustrated my example with 
that specific class because when i looked up weak pointers on 
the site I found discussions getting caught up with how to 
avoid dangling pointers when weak pointers are used; and I 
wanted to illustrate that that's a non-issue in this case, 
because I wasn't sure how much that contributed to the 
solutions given.


I suppose it doesn't matter because this is based on something 
I do with multiple inheritance in C++, I felt like I may be 
able to get it to work in D because the only public members of 
those classes were always pure virtual functions.


As an aside, how does scope(success) work in the context of a 
constructor? given:


abstract class foo
{
this()
{
   scope(success) onAdd();
}
~this()
{
   onRemove();
}

onAdd();
onRemove();
}

class bar : foo
{
int _a;

this(int a)
{
   _a = a;
}

void onAdd(){ writeln(_a); }
void onRemove() { writeln(_a); }
}

is _a defined as anything in either of writes? or would it be 
called at the wrong time relative to setting _a?


As of yet their are no built in weak references/pointers, you can 
jerry rig them however.


constructors will implicitly call super at the top of the 
function if no super call is made within the function body, so


this( int a ) {
//  super(); is called here if not defined below
_a = a;
}

I'd really like is for it to be garbage colleceted when no 
references outside of that static array exist, as i mentioned 
at the bottom of my first post.


Can't easily do this yet, would require you writing your own list 
class, as std.container, does not have any way of passing an 
allocator to it.


They are coming, slowly but surely we will eventually have them.

Allocators would allow container classes to create objects(nodes 
and such) that are in memory that is not scanned by the garbage 
collector.


You can in fact allocate memory manually right now, via 
std.c.memory or std.c.stdlib (don't member which one has c malloc 
and free).


Just be sure to familiarize your self with the manual gc 
registration and deregistration functions in core.memory.


Re: Curiously Cyclic Template Pattern causes segfault?

2014-11-05 Thread bearophile via Digitalmars-d-learn

Justin Whear:


--any compiler crash is a bug
regardless of whether the source is valid D code or not.


I suspect that in some cases those compiler crashes are a way for 
the compiler to tell the programmer that the code was too much 
hairy and too much hard to understand ;-)


Bye,
bearophile


Re: UDA failling to build when using delegate

2014-11-05 Thread bioinfornatics via Digitalmars-d-learn

On Tuesday, 4 November 2014 at 22:06:03 UTC, Ali Çehreli wrote:

On 11/04/2014 01:58 PM, bioinfornatics wrote:

 test.d(40): Error: type Section!((letter) = letter == '',
 (letter) = letter == '\x0a') has no value

You have this line:

@Section!(/* ... */)

Although that is a type name, there is a bug somewhere and 
sometimes you have to use a 'value' as a UDA. (We talked about 
this recently but I don't remember the details.) So make it an 
object so that it is a 'value':


@Section!(/* ... */)()

(You have another instance of that.)

You will have to deal with the next set of error messages now. 
:-/


Ali


Thanks Ali

If i understand well, that is a dmdfe bug ?

i yes that is weird as using @Section!(/* ... */)() give to me
something type of void then I can't filter to the desired  uda


Re: UDA failling to build when using delegate

2014-11-05 Thread bioinfornatics via Digitalmars-d-learn

On Wednesday, 5 November 2014 at 21:57:42 UTC, bioinfornatics
wrote:

On Tuesday, 4 November 2014 at 22:06:03 UTC, Ali Çehreli wrote:

On 11/04/2014 01:58 PM, bioinfornatics wrote:

 test.d(40): Error: type Section!((letter) = letter == '',
 (letter) = letter == '\x0a') has no value

You have this line:

   @Section!(/* ... */)

Although that is a type name, there is a bug somewhere and 
sometimes you have to use a 'value' as a UDA. (We talked about 
this recently but I don't remember the details.) So make it an 
object so that it is a 'value':


   @Section!(/* ... */)()

(You have another instance of that.)

You will have to deal with the next set of error messages now. 
:-/


Ali


Thanks Ali

If i understand well, that is a dmdfe bug ?

i yes that is weird as using @Section!(/* ... */)() give to me
something type of void then I can't filter to the desired  uda


Oh that is ok, I replaced

static if(is(attr : Section!T, T...))
by
static if(is(Section!(T, T)))


undefined reference to `_D5xxxx6yyyyy12__ModuleInfoZ'

2014-11-05 Thread bioinfornatics via Digitalmars-d-learn

Dear,

maybe I'm too tired to see my errors or they are a bug. See below

I have this:
.
|-- fasta.d
`-- src
 `-- nicea
 |-- metadata.d
 |-- parser.d
 `-- range.d

when I try to build it:

$ dmd -I./src/  ./fasta.d 21
fasta.o:(.rodata+0x1f8): undefined reference to
`_D5nicea6parser12__ModuleInfoZ'
collect2: error: ld returned 1 exit status
--- errorlevel 1

If I merge all files in one that build!

What is it ?

I tried to minimize the problem with dustmite but it give to me 
at end an empty file …


thanks


Re: undefined reference to `_D5xxxx6yyyyy12__ModuleInfoZ'

2014-11-05 Thread Justin Whear via Digitalmars-d-learn
On Wed, 05 Nov 2014 23:48:21 +, bioinfornatics wrote:

 Dear,
 
 maybe I'm too tired to see my errors or they are a bug. See below
 
 I have this:
 .
 |-- fasta.d `-- src
   `-- nicea
   |-- metadata.d |-- parser.d `-- range.d
 
 when I try to build it:
 
 $ dmd -I./src/  ./fasta.d 21 fasta.o:(.rodata+0x1f8): undefined
 reference to `_D5nicea6parser12__ModuleInfoZ'
 collect2: error: ld returned 1 exit status --- errorlevel 1
 
 If I merge all files in one that build!
 
 What is it ?
 
 I tried to minimize the problem with dustmite but it give to me at end
 an empty file …
 
 thanks

You have dmd only building the fasta.d file and the linker doesn't know 
where
to find the other objects.  If you've compiled the contents of nicea to a
static library (.a) with -lib, then you need to link that library by 
tacking a
`-Llibnicea.a` onto your compilation command.


Re: undefined reference to `_D5xxxx6yyyyy12__ModuleInfoZ'

2014-11-05 Thread Ali Çehreli via Digitalmars-d-learn

On 11/05/2014 03:48 PM, bioinfornatics wrote:

Dear,

maybe I'm too tired to see my errors or they are a bug. See below

I have this:
.
|-- fasta.d
`-- src
  `-- nicea
  |-- metadata.d
  |-- parser.d
  `-- range.d

when I try to build it:

$ dmd -I./src/  ./fasta.d 21


Include all files no the command line:

$ dmd -I./src/  ./fasta.d ./src/nicea/metadata.d ./src/nicea/parser.d 
./src/nicea/range.d 21



fasta.o:(.rodata+0x1f8): undefined reference to
`_D5nicea6parser12__ModuleInfoZ'
collect2: error: ld returned 1 exit status
--- errorlevel 1

If I merge all files in one that build!

What is it ?

I tried to minimize the problem with dustmite but it give to me at end
an empty file …

thanks


Ali



Re: undefined reference to `_D5xxxx6yyyyy12__ModuleInfoZ'

2014-11-05 Thread bioinfornatics via Digitalmars-d-learn

On Wednesday, 5 November 2014 at 23:53:57 UTC, Ali Çehreli wrote:

On 11/05/2014 03:48 PM, bioinfornatics wrote:

Dear,

maybe I'm too tired to see my errors or they are a bug. See 
below


I have this:
.
|-- fasta.d
`-- src
 `-- nicea
 |-- metadata.d
 |-- parser.d
 `-- range.d

when I try to build it:

$ dmd -I./src/  ./fasta.d 21


Include all files no the command line:

$ dmd -I./src/  ./fasta.d ./src/nicea/metadata.d 
./src/nicea/parser.d ./src/nicea/range.d 21



fasta.o:(.rodata+0x1f8): undefined reference to
`_D5nicea6parser12__ModuleInfoZ'
collect2: error: ld returned 1 exit status
--- errorlevel 1

If I merge all files in one that build!

What is it ?

I tried to minimize the problem with dustmite but it give to 
me at end

an empty file …

thanks


Ali


Oh yes , …

I need to sleep thanks a lot guys


Re: druntime vararg implementation

2014-11-05 Thread Mike via Digitalmars-d-learn

On Wednesday, 5 November 2014 at 14:24:00 UTC, Sean Kelly wrote:

On Wednesday, 5 November 2014 at 09:45:50 UTC, Mike wrote:

Greetings,

In core.varar. 
(https://github.com/D-Programming-Language/druntime/blob/master/src/core/vararg.d), 
why is the X86 implementation singled out and written in D 
rather than leveraging the standard c library implementation 
like the others?


No idea.  It seems like a pointless duplication of code.  Maybe 
just to have some documented functions within the module?


In that case, a better question is Why use the standard C 
implementation if we have working D code?.


Re: rndtonl

2014-11-05 Thread Laeeth Isharc via Digitalmars-d-learn

Thanks, Adam.

Should we perhaps make a pull to suggest updating the docs/wiki?  
As the point below is not what one would infer from the dlang.org 
library reference page.


(If I say we, it's because I don't know what the protocol is, or 
whether my perception is right).


On Tuesday, 4 November 2014 at 18:39:29 UTC, Adam D. Ruppe wrote:
I think rndtonl is a C library function that isn't always 
present in the system.


It doesn't work on my computer either and I can't find any 
documentation about it. It is probably not meant to be called 
by end users.




Complexity guaranties of array append operator

2014-11-05 Thread Dmitriy via Digitalmars-d-learn
Hello, I'm in the middle of learning D. I can't find any 
definitive information about what is the complexity of operator 
~= when used for adding an element to an array. Is it amortized 
O(1) or is it implementation defined? (I hope it at worst O(n) 
though I haven't seen any information about that either).


Also documentation to std.array.Appender says that it is more 
efficient to use Appender when appending many elements. Does 
it imply that Appender.put has amortized O(1)?


Re: Complexity guaranties of array append operator

2014-11-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 06, 2014 03:48:26 Dmitriy via Digitalmars-d-learn wrote:
 Hello, I'm in the middle of learning D. I can't find any
 definitive information about what is the complexity of operator
 ~= when used for adding an element to an array. Is it amortized
 O(1) or is it implementation defined? (I hope it at worst O(n)
 though I haven't seen any information about that either).

 Also documentation to std.array.Appender says that it is more
 efficient to use Appender when appending many elements. Does
 it imply that Appender.put has amortized O(1)?

They should both be an amortized O(1). As I understand it, the problem with
~= over using Appender is the extra checks that the runtime has to do with
~= to see whether there's room to append anything without reallocating, and
because Appender is free to assume that the whole block of memory is for its
personal use rather than having to worry about other dynamic arrays which
are backed by slices of the same block of memory extending into that memory
first, it's able to check for available capacity much faster. So, it's the
coefficient that changes, not the overall complexity. For the complexity to
change, you'd have to get behavior like ~= _always_ reallocating (and thus
having to copy all of the elements every time) rather than just when there
isn't any extra capacity, and that's not the case at all.

- Jonathan M Davis



Re: scope exception do not rise

2014-11-05 Thread Suliman via Digitalmars-d-learn
Replace that with something like writeln(caught) and you will 
see that it is indeed caught. :) Printing the exception mimicks 
the default behavior and you (and I) think that the exception 
is not caught. :)


that's work, but I can not understand where I can to look at 
exception level. If I right understand every function have own 
exceptions. For example std.file.
Where I could look at what e will get? I mean catch(Exception 
e).