Re: Link error 42 (WinApi)

2016-02-15 Thread ref2401 via Digitalmars-d-learn
On Tuesday, 16 February 2016 at 06:22:33 UTC, Rikki Cattermole 
wrote:

Found the problem, you haven't linked against gdi.


Thank you It works. I should have done this:

set filesToUse=main.d gdi32.lib
dmd @filesToUse -ofconsole-app.exe -debug -unittest -wi


Re: How to Generate Entities from an Existing Database in D language ORM?

2016-02-15 Thread ZardoZ via Digitalmars-d-learn

On Monday, 15 February 2016 at 14:33:24 UTC, Eliatto wrote:
Hello! I've found the following C++/Qt project: 
http://www.treefrogframework.org/
It contains ORM. Treefrog can generate model stubs from the 
existing database.

Is it possible to do the same in any D language ORM library?
BTW, similar situation was discussed here: 
http://programmers.stackexchange.com/questions/299715/using-orms-in-two-separate-programs-which-share-a-db


Perhaps you can use liquidbase to generate an XML or json 
representation and use it to generate hibernated entities. I 
don't know yet enough about ddbc to say anything Bout 
his capacity to read the database structure. jDBC can do this, so 
I expect that DDBC have the same capacity.




Re: Link error 42 (WinApi)

2016-02-15 Thread Rikki Cattermole via Digitalmars-d-learn

On 16/02/16 7:13 PM, ref2401 wrote:

On Tuesday, 16 February 2016 at 05:39:26 UTC, Rikki Cattermole wrote:

Try compiling with 64bit.
If it works, its just the import libs not containing the symbol.


dmd main.d -ofconsole-app.exe -debug -unittest -wi -m64

That's what I'm getting now:

console-app.obj : error LNK2019: unresolved external symbol
ChoosePixelFormat referenced in function _Dmain
console-app.exe : fatal error LNK1120: 1 unresolved externals


Found the problem, you haven't linked against gdi.


Re: Link error 42 (WinApi)

2016-02-15 Thread ref2401 via Digitalmars-d-learn
On Tuesday, 16 February 2016 at 05:39:26 UTC, Rikki Cattermole 
wrote:

Try compiling with 64bit.
If it works, its just the import libs not containing the symbol.


dmd main.d -ofconsole-app.exe -debug -unittest -wi -m64

That's what I'm getting now:

console-app.obj : error LNK2019: unresolved external symbol 
ChoosePixelFormat referenced in function _Dmain

console-app.exe : fatal error LNK1120: 1 unresolved externals


Re: Link error 42 (WinApi)

2016-02-15 Thread Rikki Cattermole via Digitalmars-d-learn

On 16/02/16 6:36 PM, ref2401 wrote:

import core.sys.windows.windows;

void main(string[] args) {
 // I'm aware it would not work properly.
 int formatIndex = ChoosePixelFormat(null, null);
}

When I compile the code above I'm getting the following link error:

OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
console-app.obj(console-app)
  Error 42: Symbol Undefined _ChoosePixelFormat@8

OS: Win 8.1 Pro
DMD: v2.070.0

Maybe I have to install something. Any thoughts?
Thank you.


Try compiling with 64bit.
If it works, its just the import libs not containing the symbol.


Re: Confusion regarding struct lifecycle

2016-02-15 Thread Mike Parker via Digitalmars-d-learn

On Tuesday, 16 February 2016 at 03:39:00 UTC, Matt Elkins wrote:

On Tuesday, 16 February 2016 at 03:31:51 UTC, maik klein wrote:

In D you can always call Foo.init even with @disable this(),


Foo.init can be called implicitly (not just explicitly)? If so, 
why even have @disable this(), if it offers no guarantees?


IMO, this is a bug. It should have to be explicit, just as it is 
with a single struct instance.


Re: Confusion regarding struct lifecycle

2016-02-15 Thread Matt Elkins via Digitalmars-d-learn

On Tuesday, 16 February 2016 at 03:31:51 UTC, maik klein wrote:

In D you can always call Foo.init even with @disable this(),


Foo.init can be called implicitly (not just explicitly)? If so, 
why even have @disable this(), if it offers no guarantees?


The first 3 destructor calls are from the 3 Foo.inits in your 
static array.


But why only 3? There are 5 Foos in the array, and 4 were 
explicitly overwritten...




Re: Confusion regarding struct lifecycle

2016-02-15 Thread maik klein via Digitalmars-d-learn

On Tuesday, 16 February 2016 at 02:09:15 UTC, Matt Elkins wrote:
I've been bitten again by my lack of understanding of the D 
struct lifecycle :-/. I managed to reduce my buggy program to 
the following example:


[...]


In D you can always call Foo.init even with @disable this(), The 
first 3 destructor calls are from the 3 Foo.inits in your static 
array. I guess because you disabled the copy constructor, the 
Foo's will be moved and then they also need to call the 
destructor of the Foo.inits. Just like std::move does.


Confusion regarding struct lifecycle

2016-02-15 Thread Matt Elkins via Digitalmars-d-learn
I've been bitten again by my lack of understanding of the D 
struct lifecycle :-/. I managed to reduce my buggy program to the 
following example:


[code]
import std.stdio;

struct Foo
{
@disable this();
@disable this(this);

this(int valueIn) {value = valueIn;}
~this() {writeln("Foo being destroyed: ", value);}

int value;
}

struct FooList
{
@disable this();
@disable this(this);

this(int)
{
writeln("Before 8");
foos[0] = Foo(8);
writeln("Before 1");
foos[1] = Foo(1);
writeln("Before 2");
foos[2] = Foo(2);
writeln("Before 3");
foos[3] = Foo(3);
writeln("After Foo construction");
}

Foo[5] foos;
}

unittest
{
auto fooList = FooList(0);
writeln("About to lose scope");
}
[/code]

[output]
Before 8
Before 1
Foo being destroyed: 0
Before 2
Foo being destroyed: 0
Before 3
Foo being destroyed: 0
After Foo construction
About to lose scope
Foo being destroyed: 0
Foo being destroyed: 3
Foo being destroyed: 2
Foo being destroyed: 1
Foo being destroyed: 8
[/output]

There are a few things which confuse me about this:
* Why does this code compile? In particular, I would have 
expected that with Foo[5] but initialization for only Foos 0 .. 3 
and with the @disabled constructors in Foo, there would be a 
compiler error.
* Where do those first three destroyed Foos come from? I thought 
there should have been no Foos existing since default 
construction is @disabled...
* Even if somehow the Foos are being created despite the 
@disabled default constructor, why are only three Foos being 
destroyed before the scope is lost?


So I guess what I'm wondering is:
* If I @disable a default constructor on a struct, does the 
language guarantee that I won't have default-constructed 
instances of that struct? If not, what is the point of @disable 
for default constructors? If so, is the above situation a 
compiler bug or something I am missing?
* Is the below the right general syntax for creating an instance 
of a struct so as to avoid creating more than one copy? If not, 
what is?


Stack variable: auto foo = Foo(5);
Member variable: Foo m_foo; this(/* args */) {m_foo = Foo(5);}

Thanks!


Re: What is the best way to stop App after exception?

2016-02-15 Thread Mike Parker via Digitalmars-d-learn

On Monday, 15 February 2016 at 15:38:07 UTC, Suliman wrote:

Since C's "exit" function is not liked, best thing you can do 
is to throw an Error when you want to close the program. You 
are not supposed to catch Errors. So, it eventually will stop 
the currently running thread.


but if I throw exception it's handled in instance of class 
Config and it's not go to main...




Either rethrow the original Exception:

catch(Exception e)
 {
  writeln(e.msg);
  throw e;
 }

In this case, if nothing else catches the exception, then it will 
go back to main. If anything else does catch it, it can rethrow.


Or you can do as suggested above throw a new Error:

catch(Exception e)
 {
  writeln(e.msg);
  throw new Error(e.msg);
 }

If nothing is catching Throwable or Error (and nothing should 
be), then the error will go all the way back to main just fine.




Re: What is the best way to stop App after exception?

2016-02-15 Thread Sean Campbell via Digitalmars-d-learn

On Monday, 15 February 2016 at 11:38:05 UTC, Suliman wrote:
I have got class Config with method parseconfig. I need 
terminate App if parsing of config was failed. The problem that 
I do not know how to do it better.


void parseconfig()
{
 try
 {
  //something go wrong
 }

catch(Exception e)
 {
  writeln(e.msg);
  // throw any exception here
 }
}


But my main.d also have try catch block and parseconfig() calls 
inside it. The problem that wen exception rise I do not know 
how to terminate app. Exception simply print on screen and app 
is continue.


void main()
 {
 try
  {
   parseconfig(); // exception was already handled inside:  
void parseconfig()

  }
 }

What is the best practice to stop app?


If it's an problem parsing config, it would be best practice to 
throw an exception or error, but for future reference, if you 
want to terminate execution use Runtime.terminate from 
core.runtime, followed by C's exit from core.stdc.stdlib. 
Runtime. terminate will do cleanup and allow the program to 
shutdown properly


Re: What is the best way to stop App after exception?

2016-02-15 Thread hjkl via Digitalmars-d-learn

On Monday, 15 February 2016 at 11:38:05 UTC, Suliman wrote:

What is the best practice to stop app ?


Iveseenthisnewlibtheotherday:https://github.com/John-Colvin/exitclean





Re: joiner: How to iterate over immutable ranges?

2016-02-15 Thread Bastiaan Veelo via Digitalmars-d-learn

On Monday, 15 February 2016 at 18:13:48 UTC, Ali Çehreli wrote:

On 02/15/2016 06:25 AM, Bastiaan Veelo wrote:

> I didn't even know about save... Its documentation is hidden 
> quite

> well, because I still cannot find it.

Heh. :) It is a part of the ForwardRange interface (more 
correctly, "concept"?). It looks like "the additional 
capability that one can save one's current position with the 
save primitive" under isForwardRange is its official 
documentation:


  http://dlang.org/phobos/std_range_primitives.html


Wow, thanks. I did search that page before, but that section 
didn't give an echo on my radar...


Re: joiner: How to iterate over immutable ranges?

2016-02-15 Thread Ali Çehreli via Digitalmars-d-learn

On 02/15/2016 06:25 AM, Bastiaan Veelo wrote:

> I didn't even know about save... Its documentation is hidden quite
> well, because I still cannot find it.

Heh. :) It is a part of the ForwardRange interface (more correctly, 
"concept"?). It looks like "the additional capability that one can save 
one's current position with the save primitive" under isForwardRange is 
its official documentation:


  http://dlang.org/phobos/std_range_primitives.html

> Seems it is about time I read the books.

Agreed. Ranges is a concept where a little bit of documentation up front 
makes the ideas very clear.


Ali



Re: What is the best way to stop App after exception?

2016-02-15 Thread Ali Çehreli via Digitalmars-d-learn

On 02/15/2016 03:38 AM, Suliman wrote:
> I have got class Config with method parseconfig. I need terminate App if
> parsing of config was failed. The problem that I do not know how to do
> it better.

As others said, exceptions inherited from Error indicate situations 
where the application cannot continue.


However, a function like parseconfig() does not sound like it would know 
whether the error that it detected is serious enough to terminate the 
whole application. It is conceivable that the caller can simply say 
"next file" and continue. So, I think parseconfig() should either 
propagate or throw an Exception and let the caller decide.


> void parseconfig()
> {
>   try
>   {
>//something go wrong
>   }
>
> catch(Exception e)
>   {

The way I see it, exceptions should be caught only if there is anything 
to be done with that error condition.


>writeln(e.msg);
>// throw any exception here

Needing to catch an exception just to log and then rethrow it is 
something that is against the whole spirit of exceptions mechanisms. It 
brings exceptions back to using error codes: Every function must do the 
same to leave behind a trail, presumably for debugging.


There are other options:

- Log before the error condition at a different logging level.

- Put a break point at the constructor of the exception. The back trace 
will show the backtrace.


- Automate the last two and call a library like libunwind and dump the 
backtrace from the constructor of exception. (However, you may not want 
to log every thrown exception.)


I know that sometimes the thrown exception does not carry enough 
information. Then it's ok to do what you're doing: catch and throw 
another exception.


>   }
> }
>
>
> But my main.d also have try catch block and parseconfig() calls inside
> it. The problem that wen exception rise I do not know how to terminate
> app. Exception simply print on screen and app is continue.

I don't know how that happens. I am presuming you do throw another 
exception where you say


   // throw any exception here

Then all you need to do is catch in main, log the problem and return 
non-zero from main.


> void main()
>   {
>   try
>{
> parseconfig(); // exception was already handled inside:

But it did rethrow, right? Then it should be fine.

>  void
> parseconfig()
>}
>   }
>
> What is the best practice to stop app?

Ali



Re: What is the best way to stop App after exception?

2016-02-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, February 15, 2016 15:38:07 Suliman via Digitalmars-d-learn wrote:
> On Monday, 15 February 2016 at 15:17:01 UTC, tcak wrote:
> > Since C's "exit" function is not liked, best thing you can do
> > is to throw an Error when you want to close the program. You
> > are not supposed to catch Errors. So, it eventually will stop
> > the currently running thread.
>
> but if I throw exception it's handled in instance of class Config
> and it's not go to main...
>
> And what the reason to not add support of C's "exit"?

You can call C's exit from D, but it won't shut down the app cleanly. It
_can't_ shut down the app cleanly. It can't even do that in C. For an
application to shut down cleanly, all of its threads must exit cleanly,
which requires that the programmer tell them to shut down cleanly (you can't
just have them magically exit cleanly when they're in the middle of
running), and of course, main has to exit properly so that the runtime has a
chance to shut things down properly. That can be by returning from main or
by having an Exception or Error bubble out of it, but simply calling exit()
would kill the program without letting the runtime - or anything in your
program - shut down cleanly.

- Jonathan M Davis



Re: What is the best way to stop App after exception?

2016-02-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, February 15, 2016 11:38:05 Suliman via Digitalmars-d-learn wrote:
> I have got class Config with method parseconfig. I need terminate
> App if parsing of config was failed. The problem that I do not
> know how to do it better.
>
> void parseconfig()
> {
>   try
>   {
>//something go wrong
>   }
>
> catch(Exception e)
>   {
>writeln(e.msg);
>// throw any exception here
>   }
> }
>
>
> But my main.d also have try catch block and parseconfig() calls
> inside it. The problem that wen exception rise I do not know how
> to terminate app. Exception simply print on screen and app is
> continue.
>
> void main()
>   {
>   try
>{
> parseconfig(); // exception was already handled inside:  void
> parseconfig()
>}
>   }
>
> What is the best practice to stop app?

If you want your app to exit cleanly, it must exit via main. If an Exception
or Error is thrown from main (or bubbles up passed main), then the runtime
will catch it and print it out before exiting the program with a non-zero
exit value. If you don't want your program to exit via exception, then you
need to catch it in main, and if you've caught it in main, then you can just
exit main normally - either by reaching the end of its body or by returning.

But if you're handling the exception inside of another function and not
letting it bubble up to main or throwing another exception for main to
catch, then you're going to have to figure out how to have your functions
return until they get back to main - either that or have the exception reach
main.

- Jonathan M Davis



Re: What is the best way to stop App after exception?

2016-02-15 Thread Messenger via Digitalmars-d-learn

On Monday, 15 February 2016 at 15:17:01 UTC, tcak wrote:

[...]
BUT (This is a big but with single t), in multithreaded 
process, throwing Error in a thread that is not the main thread 
won't stop your process still and you are still left with 
"exit" function.


Mind, if you're doing the normal message passing thread dance, 
you can do periodic checks for an OwnerTerminated message.


http://melpon.org/wandbox/permlink/jxAzU0fcsnouMa9z


Re: What is the best way to stop App after exception?

2016-02-15 Thread Suliman via Digitalmars-d-learn

On Monday, 15 February 2016 at 15:17:01 UTC, tcak wrote:

On Monday, 15 February 2016 at 11:38:05 UTC, Suliman wrote:
I have got class Config with method parseconfig. I need 
terminate App if parsing of config was failed. The problem 
that I do not know how to do it better.


void parseconfig()
{
 try
 {
  //something go wrong
 }

catch(Exception e)
 {
  writeln(e.msg);
  // throw any exception here
 }
}


But my main.d also have try catch block and parseconfig() 
calls inside it. The problem that wen exception rise I do not 
know how to terminate app. Exception simply print on screen 
and app is continue.


void main()
 {
 try
  {
   parseconfig(); // exception was already handled inside:  
void parseconfig()

  }
 }

What is the best practice to stop app?


Since C's "exit" function is not liked, best thing you can do 
is to throw an Error when you want to close the program. You 
are not supposed to catch Errors. So, it eventually will stop 
the currently running thread.


but if I throw exception it's handled in instance of class Config 
and it's not go to main...


And what the reason to not add support of C's "exit"?


Re: What is the best way to stop App after exception?

2016-02-15 Thread tcak via Digitalmars-d-learn

On Monday, 15 February 2016 at 11:38:05 UTC, Suliman wrote:
I have got class Config with method parseconfig. I need 
terminate App if parsing of config was failed. The problem that 
I do not know how to do it better.


void parseconfig()
{
 try
 {
  //something go wrong
 }

catch(Exception e)
 {
  writeln(e.msg);
  // throw any exception here
 }
}


But my main.d also have try catch block and parseconfig() calls 
inside it. The problem that wen exception rise I do not know 
how to terminate app. Exception simply print on screen and app 
is continue.


void main()
 {
 try
  {
   parseconfig(); // exception was already handled inside:  
void parseconfig()

  }
 }

What is the best practice to stop app?


Since C's "exit" function is not liked, best thing you can do is 
to throw an Error when you want to close the program. You are not 
supposed to catch Errors. So, it eventually will stop the 
currently running thread.


BUT (This is a big but with single t), in multithreaded process, 
throwing Error in a thread that is not the main thread won't stop 
your process still and you are still left with "exit" function.


Re: joiner: How to iterate over immutable ranges?

2016-02-15 Thread Bastiaan Veelo via Digitalmars-d-learn

On Monday, 15 February 2016 at 01:42:30 UTC, Mike Parker wrote:
On Sunday, 14 February 2016 at 19:32:31 UTC, Bastiaan Veelo 
wrote:


Maybe this [1] will help shed some light.

[1] https://www.packtpub.com/books/content/understanding-ranges


Good idea. I have your book, but it is very nice to have this 
particular chapter freely online.


Thanks,
Bastiaan.


How to Generate Entities from an Existing Database in D language ORM?

2016-02-15 Thread Eliatto via Digitalmars-d-learn
Hello! I've found the following C++/Qt project: 
http://www.treefrogframework.org/
It contains ORM. Treefrog can generate model stubs from the 
existing database.

Is it possible to do the same in any D language ORM library?
BTW, similar situation was discussed here: 
http://programmers.stackexchange.com/questions/299715/using-orms-in-two-separate-programs-which-share-a-db


Re: joiner: How to iterate over immutable ranges?

2016-02-15 Thread Bastiaan Veelo via Digitalmars-d-learn

On Monday, 15 February 2016 at 01:14:10 UTC, Ali Çehreli wrote:

On 02/14/2016 11:32 AM, Bastiaan Veelo wrote:

If it's acceptable for you, the following code calls .save on 
the elements and it works:


import std.algorithm.iteration;
import std.stdio;
import std.array;// <-- ADDED

void main()
{
immutable(string[])[] icycles;
icycles ~= ["one", "two"];
icycles ~= ["three", "four"];
foreach (number; icycles.map!(r => r.save).joiner)
writeln(number);
}

Again, .save on an array is cheap. What will happen is that the 
original immutable arrays will be untouched but their proxies 
returned by .save will be consumed.


Great, thanks. I didn't even know about save... Its documentation 
is hidden quite well, because I still cannot find it. Seems it is 
about time I read the books.


Re: Photoshop programming

2016-02-15 Thread thedeemon via Digitalmars-d-learn

On Sunday, 14 February 2016 at 09:48:54 UTC, Patience wrote:
Photoshop has the ability to be controlled by scripts and 
programming languages. For example, C# can be used to access 
photoshop by adding the appropriate reference and using 
directives. I believe it is COM based but I am not totally sure.


I've tried reading the docs but it's not making much sense.

http://www.lunesu.com/uploads/ModernCOMProgramminginD.pdf

links at the bottom are down.

It says one has to create a wrapper, but then talks like it can 
be done automatically. I assume that is what project does? But 
then one has to create an idl, not sure what that is ;\


Any info on how to do this stuff properly?


Unfortunately the project mentioned in that presentation seems to 
be unavailable.


In order to work with COM objects from D you need to have 
definitions of their interfaces translated to D. Initially they 
are often described in IDL files (Interface Definition Language) 
or TLB files (type library), and there are nice tools like 
tlb2idl.exe and idl2d.exe that can convert them to .d files. You 
can find them in the VisualD project tree. And if original 
definitions are in C++, in many cases Ctrl-C-Ctrl-V is all you 
need to convert to D. ;)


Then you may work with them directly or you might want a wrapper 
that will call Release() for you when appropriate. I'm using a 
wrapper like this:

https://gist.github.com/thedeemon/3c2989b76004fafe9aa0
Originally taken from VisualD source but then modified to my 
needs.


For example, I need to use IAMVfwCompressDialogs interface from 
Microsoft SDK. It's defined in axextend.idl file in the SDK and 
looks like this:


[
object,
local,
uuid(D8D715A3-6E5E-11D0-B3F0-00AA003761C5),
pointer_default(unique)
]
interface IAMVfwCompressDialogs : IUnknown
{

// Bring up a dialog for this codec
HRESULT ShowDialog(
[in]  int iDialog,   // VfwCompressDialogs enum
[in]  HWND hwnd
);

// Calls ICGetState and gives you the result
HRESULT GetState(
[out, size_is(*pcbState), 
annotation("__out_bcount_part(*pcbState, *pcbState)")] LPVOID 
pState,

[in, out, annotation("__inout")]  int *pcbState
);

// Calls ICSetState
HRESULT SetState(
[in, size_is(cbState), 
annotation("__in_bcount(cbState)")] LPVOID pState,

[in]  int cbState
);

// Send a codec specific message
HRESULT SendDriverMessage(
[in]  int uMsg,
[in]  long dw1,
[in]  long dw2
);
}

I use idl2d.exe and get following D code (minus some comments):

const GUID IID_IAMVfwCompressDialogs = IAMVfwCompressDialogs.iid;

interface IAMVfwCompressDialogs : IUnknown
{
static const GUID iid = { 0xD8D715A3,0x6E5E,0x11D0,[ 
0xB3,0xF0,0x00,0xAA,0x00,0x37,0x61,0xC5 ] };


// Bring up a dialog for this codec
HRESULT ShowDialog(
   in  int iDialog,   // VfwCompressDialogs 
enum

   in  HWND hwnd
   );

// Calls ICGetState and gives you the result
HRESULT GetState(
 LPVOID pState,
 int *pcbState
 );

// Calls ICSetState
HRESULT SetState(
 in LPVOID pState,
 in  int cbState
 );

// Send a codec specific message
HRESULT SendDriverMessage(
  in  int uMsg,
  in  int dw1,
  in  int dw2
  );
}

Then in my D code I just write

enum { VfwCompressDialog_Config = 0x01, 
VfwCompressDialog_About =  0x02 }

...
auto vfw = ComPtr!IAMVfwCompressDialogs(pg.vcodec);
if (vfw) vfw.ShowDialog(VfwCompressDialog_Config, hwnd);

where pg.vcodec is my variable of type ComPtr!IBaseFilter I 
created earlier. Here the ComPtr wrapper uses internally 
QueryInterface() to get pointer to desired interface, and when my 
vfw variable goes out of scope, Release() will be called 
automatically. Moreover, if ShowDialog here returns a bad value a 
COMException will be generated automatically (this is my own 
addition to ComPtr behavior).


To create some COM object in the first place, knowing its CLSID, 
I do like this:


auto CLSID_NullRenderer = 
Guid!("C1F400A4-3F08-11D3-9F0B-006008039E37"); //qedit.dll
auto pNullRendr = ComPtr!IBaseFilter(CLSID_NullRenderer, 
"null renderer");


Here IBaseFilter is just some COM interface from Microsoft SDK I 
need.
ComPtr constructor understands what to do depending on whether 
it's given some GUID or a pointer to some object.


Moral of this story, if you have the COM interfaces defined in D, 
you can have wrappers to do resource management, interface 
querying and error checking automatically, but first you need to 
translate (often using 

Re: Customizing printing of structs (writeln / to!sth behavior).

2016-02-15 Thread cym13 via Digitalmars-d-learn

On Monday, 15 February 2016 at 12:03:44 UTC, ciechowoj wrote:
It there a way to change how writeln converts structs to 
strings? I read in the documentation it uses to!string to 
convert the struct. Is there a way to overload to!string for my 
own type?


Let say I have:

struct Point {
int x, y;
}

and I want writeln(Point(3, 4)); to print "[3, 4]" instead of 
"Point(3, 4)".


Just define a toString method, it will be used by .to!string

struct Point {
int x;
int y;

string toString() {
import std.format: format;
return format("[%d, %d]", x, y);
}
}

void main(string[] args) {
import std.stdio: writeln;

auto p = Point(3, 4);
p.writeln; // [3, 4]
}



Customizing printing of structs (writeln / to!sth behavior).

2016-02-15 Thread ciechowoj via Digitalmars-d-learn
It there a way to change how writeln converts structs to strings? 
I read in the documentation it uses to!string to convert the 
struct. Is there a way to overload to!string for my own type?


Let say I have:

struct Point {
int x, y;
}

and I want writeln(Point(3, 4)); to print "[3, 4]" instead of 
"Point(3, 4)".




Re: Scala Spark-like RDD for D?

2016-02-15 Thread data pulverizer via Digitalmars-d-learn
On Monday, 15 February 2016 at 11:09:10 UTC, data pulverizer 
wrote:
Are there are any plans to create a scala spark-like RDD class 
for D 
(https://www.cs.berkeley.edu/~matei/papers/2012/nsdi_spark.pdf)? This is a powerful model that has taken the data science world by storm; it would be useful to have something like this in the D world. Most of the algorithms in statistics/data science are iterative in nature which fits well with this kind of data model.


I read through the Kind Of Container thread which has some 
relationship with this issue 
(https://forum.dlang.org/thread/n07rh8$dmb$1...@digitalmars.com). 
It looks like Immutability would be the way to go for an RDD 
data structure. But I am not wedded to any model as long as we 
can have something that performs the same functionality as the 
RDD.


As an alternative are there plans for parallel/cluster 
computing frameworks for D?


Apologies if I am kicking a hornet's nest. It is not my 
intention.


Thanks


Perhaps the question is too prescriptive. Another way is: Does D 
have a big data strategy? But I tried to anchor it to some 
currently functioning framework which is why I suggested RDD.




What is the best way to stop App after exception?

2016-02-15 Thread Suliman via Digitalmars-d-learn
I have got class Config with method parseconfig. I need terminate 
App if parsing of config was failed. The problem that I do not 
know how to do it better.


void parseconfig()
{
 try
 {
  //something go wrong
 }

catch(Exception e)
 {
  writeln(e.msg);
  // throw any exception here
 }
}


But my main.d also have try catch block and parseconfig() calls 
inside it. The problem that wen exception rise I do not know how 
to terminate app. Exception simply print on screen and app is 
continue.


void main()
 {
 try
  {
   parseconfig(); // exception was already handled inside:  void 
parseconfig()

  }
 }

What is the best practice to stop app?


Scala Spark-like RDD for D?

2016-02-15 Thread data pulverizer via Digitalmars-d-learn
Are there are any plans to create a scala spark-like RDD class 
for D 
(https://www.cs.berkeley.edu/~matei/papers/2012/nsdi_spark.pdf)? 
This is a powerful model that has taken the data science world by 
storm; it would be useful to have something like this in the D 
world. Most of the algorithms in statistics/data science are 
iterative in nature which fits well with this kind of data model.


I read through the Kind Of Container thread which has some 
relationship with this issue 
(https://forum.dlang.org/thread/n07rh8$dmb$1...@digitalmars.com). It 
looks like Immutability would be the way to go for an RDD data 
structure. But I am not wedded to any model as long as we can 
have something that performs the same functionality as the RDD.


As an alternative are there plans for parallel/cluster computing 
frameworks for D?


Apologies if I am kicking a hornet's nest. It is not my intention.

Thanks


Re: D Book page 402 Concurrency FAIL

2016-02-15 Thread thedeemon via Digitalmars-d-learn

On Sunday, 14 February 2016 at 22:54:36 UTC, Brother Bill wrote:

Please provide full replacement of this toy program that works 
with D version 2.070.0


This one works fine for me in Windows with VisualD and DMD 
2.070.0:

--
import std.concurrency, std.stdio, std.exception;

void main() {
auto low = 0,
high = 100;
auto tid = spawn();

foreach (i; low .. high) {
writeln("Main thread: ", i);
tid.send(thisTid, i);
enforce(receiveOnly!Tid() == tid);
}
}

void writer() {
scope(failure) return;
for (;;) {
auto msg = receiveOnly!(Tid, int)();
writeln("secondary thread: ", msg[1]);
msg[0].send(thisTid);
}
}

--

Just one line added to writer() in order to catch OwnerTerminated 
exception and end the thread silently. Original version produced 
an error when main thread finished before the writer thread.