Re: Store any callable in an array

2018-05-04 Thread Neia Neutuladh via Digitalmars-d-learn

On Friday, 4 May 2018 at 19:12:16 UTC, ag0aep6g wrote:
If toDelegate isn't (always) @safe, how can you be sure that 
your wrapper is?


If it were @safe, the compiler would accept it.

Looking at the code, I believe there are several casts that the 
compiler can't verify but are used safely.



Also, TFunc may have an unsafe destructor.


If it's a delegate with an un-@safe destructor (how would that 
work? a captured context variable?), then it's already not @safe. 
If it's a function, it doesn't have a destructor. If it's a 
user-defined type with opCall, that's something to pay attention 
to, but it's beyond the scope of the original question.


Re: Error: module `hello` is in file 'hello.d' which cannot be read

2018-05-04 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 04, 2018 at 11:29:12PM +, Alex via Digitalmars-d-learn wrote:
> Hi
> 
> I just installed D on my windows 10 and want to try to compile a hello
> world. My source is a classical
> 
> import std.stdio;
> void main() {
> writeln("Hello, World!");
> }
> 
> And I try to compile and get
> 
> C:\D>dmd hello.d
> Error: module `hello` is in file 'hello.d' which cannot be read
> import path[0] = C:\D\dmd2\windows\bin\..\..\src\phobos
> import path[1] = C:\D\dmd2\windows\bin\..\..\src\druntime\import
> 
> What do I do wrong ?
> 
> D is installed at de root of C:, and the hello.d source code is at
> C:\D\dmd2\sources.
[...]

Where is your current directory?  If hello.d is in C:\D\dmd2\sources
then you need to:

C:
cd \D\dmd2\sources
dmd hello.d


T

-- 
Life begins when you can spend your spare time programming instead of
watching television. -- Cal Keegan


Error: module `hello` is in file 'hello.d' which cannot be read

2018-05-04 Thread Alex via Digitalmars-d-learn

Hi

I just installed D on my windows 10 and want to try to compile a 
hello world. My source is a classical


import std.stdio;
void main() {
writeln("Hello, World!");
}

And I try to compile and get

C:\D>dmd hello.d
Error: module `hello` is in file 'hello.d' which cannot be read
import path[0] = C:\D\dmd2\windows\bin\..\..\src\phobos
import path[1] = C:\D\dmd2\windows\bin\..\..\src\druntime\import

What do I do wrong ?

D is installed at de root of C:, and the hello.d source code is 
at C:\D\dmd2\sources.


Thank you to you

Alex



Re: Derelict on Ubuntu with CODE::BLOCKS

2018-05-04 Thread RegeleIONESCU via Digitalmars-d-learn

On Thursday, 3 May 2018 at 19:30:48 UTC, Mike Parker wrote:

On Thursday, 3 May 2018 at 18:36:04 UTC, RegeleIONESCU wrote:



[...]



So your app is compiling and executing. This is a runtime 
error. The SymbolLoadException means the SDL library was 
loaded, but a function Derelict expected to find was not there. 
This usually means that your version of Derelict by default 
supports a different version of SDL than you have on your 
system.


[...]


It works, even when loading all the libraries. I played with 
different versions and loaded libraries one by one to see how it 
works. I even managed to make a window - for me it is a big thing.


Thank you, thank you, thank you for your kind and detailed 
support!


Re: Is HibernateD dead?

2018-05-04 Thread Matthias Klumpp via Digitalmars-d-learn
I've written an email to Vadim, maybe we get a reply on the 
status of both projects.



On Friday, 4 May 2018 at 07:18:09 UTC, bauss wrote:

[...]
Would it maybe be easier for you to base on ddbc[1] or another 
existing abstraction layer for database abstraction?
Ddbc is pretty neat, and even has support for reading structs 
directly from the database.




Perhaps, but it'd have to be a forked version as I don't really 
want to depend on something that isn't updated regularly.


ddbc's last commit was a year ago.


Yes, at the moment using ddbc and relying on it would mean taking 
over some maintenance of it. Ddbc is fairly complete though and 
might save you a lot of work, because it already abstracts a lot 
of (relational) database systems.



I can't seem to find a license for it though?


It's Boost licensed (BSL-1.0), but probably needs an explicit 
LICENSE file.
Maybe we can move ddbc to dlang-community, so more people can 
easily commit changes to it (provided it gets accepted there, and 
Vadim agrees with that move as well).


Perhaps I will end up having another "optional" dependency to 
it as a temporary until I can have a better implementation or 
something.


Taking over maintenance of it might be easier than reimplementing 
the database abstraction again though.
For Postgres, ddbc worked really well for me, and I assume its 
SQLite, MySQL and ODBC drivers are also still working well, 
meaning less work for you.
Without ddbc, you'd have to write new abstraction on top of some 
other libraries, like dpq2.


The frontend part of postgresql is almost finished, it's just 
having the postgresql driver working properly, which is where 
it's frozen right now.


Hmm... Does any public code for that exist already that I 
could play around with?
Unfortunately, I have a few more unusual requirements for 
Postgres, like:

 * UUIDs as primary keys, instead of integers


As far as I remember the implementation of @DbId in Diamond, 
then it supports whatever type.


Native support for std.uuid.UUID would be neat :-) For Hibernated 
I use a mixin to convert a UUID into strings transparently, for 
database insertion.



Diamond doesn't care much about what type your primary key is.

I will make sure that's how it function of course, if it 
currently doesn't behave like it, but I'm pretty sure it does.


 * Ability to register custom datatypes with the ORM (version 
numbers in this case, the ORM can view them as text, but the 
database has a special type for them)


That could be done with some attribute that lets you handle 
columns yourself.


Do you have a good name for it?

I was thinking @DbProxy and then the function would be 
something like:

[...]


Registering a new type with Postgres yields a new OID to identify 
the type, so I would need a function to tell the Postgres backend 
to treat OIDs of a certain number like "text" types. Ideally, I 
would also need to annotate entity to set a specific column type, 
like:


```
class Entity {
UUID uuid;

@ColumType("versionnumber")
string _version;
}
```
(With the result of CREATE TABLE not setting a "text" type for 
the new version column, but a "versionnumber" type instead)


That would do it. For Hibernated, I have Hibernated create the 
table initially, and then fire an ALTER TABLE at it afterwards to 
change the column type, while at the same time registering the 
new type OID with ddbc to be treated as text.
As said, this is a very specific requirement very few people will 
have ^^


Much more frequently people will ask for JSONB and JSON type 
support for a postgres driver though, I guess. For that, 
specifying the column type explicitly could be quite helpful as 
well, so switch between JSONB and JSON.


 * Obviously the usual ORM stuff, one-to-many, many-to-many, 
etc. relations




Yes, relations is one thing I haven't added and I have been 
wanting to do it for a while.


I will definitely look into having it added as well.


That's kind of key for an ORM :-) Handling relations manually was 
what made me abandon my "I just write raw SQL for everything" 
ways, because it gets quite complex and annoying in the long run.


(Obviously not a must-have list, I added support for custom 
datatypes to my ddbc fork as well, because it's not really a 
feature many people need)


Well, that's kind of the key to most of the development in 
Diamond.


I usually add functionality that isn't widely used and in most 
cases people implement it themselves ex. the whole diamond.seo 
is not usually something a framework has.


I keep an eye on it - at the moment, Vibe.d satisfies all 
requirements I have on a web framework, but that might change.
A well integrated ORM would certainly be a game changer, since 
Vibe.d is limited to Mongo and Redis only.


Diamond is a neat project, I played around with it about half 
a year ago, but didn't test the ORM part at all back then.


It wasn't that good back then and has improved a lot since, as 
well many other par

Re: Store any callable in an array

2018-05-04 Thread ag0aep6g via Digitalmars-d-learn

On 05/04/2018 06:33 PM, Neia Neutuladh wrote:

auto asDelegate(TFunc)(TFunc func) @trusted
{
     import std.functional : toDelegate;
     return toDelegate(func);
}

The "@trusted" means that you promise this thing is safe, even if the 
compiler can't be certain.


If toDelegate isn't (always) @safe, how can you be sure that your 
wrapper is? Also, TFunc may have an unsafe destructor.


That's not good use of `@trusted`.


Re: Windows to Linux Porting - timeCreated and timeLastAccessed

2018-05-04 Thread Kagamin via Digitalmars-d-learn
If you just want to clean logs, then use modification time on all 
oses:


auto clogClean (string LogDir ) {
Array!(Tuple!(string, SysTime)) dFiles;
 dFiles.insert(dirEntries(LogDir, SpanMode.shallow).filter!(a => 
a.isFile).map!(a => tuple(a.name, a.timeLastModified)));

 return dFiles;
}


Re: Store any callable in an array

2018-05-04 Thread Neia Neutuladh via Digitalmars-d-learn

On Friday, 4 May 2018 at 15:36:29 UTC, wjoe wrote:
I have a class that I want to be able to register callbacks and 
I'd like to be able to register any callable - functions, 
delegates, lambdas, anything.


Is there another way to do it besides converting those 
toDelegate, which states a bug with @safe functions?


Or better store each type in their own array ?

Cheers!


auto asDelegate(TFunc)(TFunc func) @trusted
{
import std.functional : toDelegate;
return toDelegate(func);
}

The "@trusted" means that you promise this thing is safe, even if 
the compiler can't be certain.


Re: Ambiguous template parameter names

2018-05-04 Thread jmh530 via Digitalmars-d-learn

On Thursday, 3 May 2018 at 13:30:03 UTC, bauss wrote:

On Thursday, 3 May 2018 at 02:51:18 UTC, Meta wrote:


If you want that, you might be able to do `int val = val` on 
the inner function, though I'm not sure that'll work.


It does not work and will do nothing.


Below compiles, but my guess is that the ASM is saying that the 
foo function only has a run-time argument.


template foo(int val)
{
int foo(int val = val)
{
return val;
}
}

void main()
{
assert(foo!1 == 1);
assert(foo!1(2) == 2);
}


Re: using Unsized Arrays in Structures from d?

2018-05-04 Thread NewUser via Digitalmars-d-learn

On Friday, 4 May 2018 at 15:37:28 UTC, ag0aep6g wrote:

On Friday, 4 May 2018 at 13:02:08 UTC, NewUser wrote:

How can I use the following c structure from d.

struct Item
{
  int id;
};

struct Group
{
  int i;
  int item_count;
  struct Item items[];
};

tried defining items[] as both "Item[] items" and "Item* 
items" in d, it compiles okay but gives an error when trying 
to access it.


Here is the error.
object.Error@(0): Access Violation


In the C code, the elements of `items` are directly part of the 
struct. There is no indirection. D doesn't have dedicated 
syntax for this, but you can hint at it with a zero-sized array:


struct Group
{
int i;
int item_count;
Item[0] items;
}

Then access an item with `group.items.ptr[index]`.


Hi ag0aep6g,

Thanks a lot for that.

I should have thought of that (i would still have missed the .ptr 
part), the old c syntax for the same thing used to be "Item 
items[0]".


Thanks,
NewUser





Re: Windows to Linux Porting - timeCreated and timeLastAccessed

2018-05-04 Thread wjoe via Digitalmars-d-learn

On Friday, 4 May 2018 at 15:30:26 UTC, Vino wrote:

On Friday, 4 May 2018 at 15:16:23 UTC, wjoe wrote:

[...]


Hi Wjoe,

  Thank you very much, but what i am expecting is something 
like OS switch, based of OS type switch the funciton eg:


If OS is windows use the funciton timeCreated else if the OS is 
linux use the function timeLastAccessed in the below example 
program, something similar as stated in the link


https://dlang.org/spec/declaration.html#alias

Eg1:
version (Win32)
{
alias myfoo = win32.foo;
}
version (linux)
{
alias myfoo = linux.bar;
}



auto clogClean (string LogDir ) {
Array!(Tuple!(string, SysTime)) dFiles;


version (Windows) {  alias sTimeStamp = 
std.file.DirEntry.timeCreated;} else version (linux) { alias 
sTimeStamp = std.file.DirEntry.timeLastAccessed; }



dFiles.insert(dirEntries(LogDir, SpanMode.shallow).filter!(a => 
a.isFile).map!(a => tuple(a.name, a.sTimeStamp)));

 return dFiles;
}

From,
Vino.B


I think that's not possible. You can't query information that 
hasn't been stored.


Your best bet in a Change-Function-Name-Port would probably be to 
use access time and mount the file system with options that won't 
touch that anymore after creation. But me thinks such a solution 
would be rather unreliable and not worth the time investment.


Store any callable in an array

2018-05-04 Thread wjoe via Digitalmars-d-learn
I have a class that I want to be able to register callbacks and 
I'd like to be able to register any callable - functions, 
delegates, lambdas, anything.


Is there another way to do it besides converting those 
toDelegate, which states a bug with @safe functions?


Or better store each type in their own array ?

Cheers!


Re: using Unsized Arrays in Structures from d?

2018-05-04 Thread ag0aep6g via Digitalmars-d-learn

On Friday, 4 May 2018 at 13:02:08 UTC, NewUser wrote:

How can I use the following c structure from d.

struct Item
{
  int id;
};

struct Group
{
  int i;
  int item_count;
  struct Item items[];
};

tried defining items[] as both "Item[] items" and "Item* items" 
in d, it compiles okay but gives an error when trying to access 
it.


Here is the error.
object.Error@(0): Access Violation


In the C code, the elements of `items` are directly part of the 
struct. There is no indirection. D doesn't have dedicated syntax 
for this, but you can hint at it with a zero-sized array:


struct Group
{
int i;
int item_count;
Item[0] items;
}

Then access an item with `group.items.ptr[index]`.


Re: Windows to Linux Porting - timeCreated and timeLastAccessed

2018-05-04 Thread Vino via Digitalmars-d-learn

On Friday, 4 May 2018 at 15:16:23 UTC, wjoe wrote:

On Friday, 4 May 2018 at 14:24:36 UTC, Vino wrote:

On Friday, 4 May 2018 at 14:02:24 UTC, Jonathan M Davis wrote:
On Friday, May 04, 2018 13:17:36 Vino via Digitalmars-d-learn 
wrote:

[...]


Linux does not keep track of the creation time of a file. So, 
it will not work to have a program on Linux ask a file how 
long it's been since the file was created. If you want that 
information, you'll have to store it elsewhere somehow (and 
that generally only works if you created the file in the 
first place).


The modification time of the file is the time that the file 
was last changed (which would be the creation time if it were 
only ever written to once, but in the general case, it has no 
relation to the creation time at all). So, you could use 
std.file.timeLastModified to find out if a file has been 
changed within the last x number of days, but there is no way 
to find out the creation time of a file by asking the 
filesystem.


- Jonathan M Davis


Hi Jonathan,

  Thank you,  i got your point from the other forum topic 
which was raised by me earlier, hence decided to use 
modification time, the request is on how and the best approach 
to port the code from windows to Linux eg program below


Example Code:
import std.stdio: writeln;
import std.container.array;
import std.file: dirEntries,isFile, SpanMode;
import std.algorithm: filter, map;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;


version (Windows) { alias sTimeStamp = timeCreated; } else 
version (linux) { alias sTimeStamp = timeLastAccessed; }


auto clogClean (string LogDir ) {
Array!(Tuple!(string, SysTime)) dFiles;
 dFiles.insert(dirEntries(LogDir, SpanMode.shallow).filter!(a 
=> a.isFile).map!(a => tuple(a.name, a.sTimeStamp)));

 return dFiles;
}

void main () {
string LogDir;
LogDir = "//DScript/Test";   //  Error: undefined 
identifier timeLastAccessed on Linux
LogDir = "C:\\DScript\\Others";  //  Error: undefined 
identifier timeCreated on Windows.

writeln(clogClean(LogDir));
}

From,
Vino.B


Unlike NTFS for Windows there's a plethora of different file 
systems available to use for Linux, one of which doesn't even 
support deletion of files. You also have to keep in mind that 
even if the same file system is used, there is no guarantee 
that you have the same set of metadata available for a mount 
point each and every time.
Consider a file system that's mounted with the 'noatime' 
option, for instance, which doesn't log access times.


As far as I understand you are globing files, check times and 
then act upon that.
If I were to port this to Linux, or any other OS for that 
matter, I wouldn't depend on a feature of an OS.
Instead, since you have to look at a file either way to get the 
meta data (which you query with the stat family of functions), 
I would build my own database or cache with that information.
Glob the directory and add files not yet present with the 
current date (and any other meta data you might need).
Then query all the files of interest and do whatever you want 
to do with them and remove the entry.


Downside is you have possibly another dependency. On the plus 
side you could easily query all files older than X days or 
whatever with a single select and batch process them.


Hi Wjoe,

  Thank you very much, but what i am expecting is something like 
OS switch, based of OS type switch the funciton eg:


If OS is windows use the funciton timeCreated else if the OS is 
linux use the function timeLastAccessed in the below example 
program, something similar as stated in the link


https://dlang.org/spec/declaration.html#alias

Eg1:
version (Win32)
{
alias myfoo = win32.foo;
}
version (linux)
{
alias myfoo = linux.bar;
}



auto clogClean (string LogDir ) {
Array!(Tuple!(string, SysTime)) dFiles;


version (Windows) {  alias sTimeStamp = 
std.file.DirEntry.timeCreated;} else version (linux) { alias 
sTimeStamp = std.file.DirEntry.timeLastAccessed; }



dFiles.insert(dirEntries(LogDir, SpanMode.shallow).filter!(a => 
a.isFile).map!(a => tuple(a.name, a.sTimeStamp)));

 return dFiles;
}

From,
Vino.B


Re: using Unsized Arrays in Structures from d?

2018-05-04 Thread NewUser via Digitalmars-d-learn

On Friday, 4 May 2018 at 14:55:18 UTC, Timoses wrote:

On Friday, 4 May 2018 at 13:27:03 UTC, NewUser wrote:

Hi Timoses,

The structure is being returned from c and I'd like use it 
from d.


What you have work perfectly when assigning from d.


Regards,
NewUser


Then you probably need some `extern(C)` statement introducing 
the C function and the struct type, right?


You could also try dstep to "translate" the C header file to D:
https://github.com/jacob-carlborg/dstep


Hi Timoses,

Thanks for the suggestion, i'll try it out.

Regards,
NewUser


Re: Windows to Linux Porting - timeCreated and timeLastAccessed

2018-05-04 Thread wjoe via Digitalmars-d-learn

On Friday, 4 May 2018 at 14:24:36 UTC, Vino wrote:

On Friday, 4 May 2018 at 14:02:24 UTC, Jonathan M Davis wrote:
On Friday, May 04, 2018 13:17:36 Vino via Digitalmars-d-learn 
wrote:

On Friday, 4 May 2018 at 12:38:07 UTC, Adam D. Ruppe wrote:
> What are you actually trying to do with it? These functions 
> are probably the wholly wrong approach.


Hi Adam,

  The existing program in Windows do few task's eg: Delete 
files
older that certain days, and now we are trying to port to 
Linux,
and above was just a example, hence asked the right approach 
for

porting.


Linux does not keep track of the creation time of a file. So, 
it will not work to have a program on Linux ask a file how 
long it's been since the file was created. If you want that 
information, you'll have to store it elsewhere somehow (and 
that generally only works if you created the file in the first 
place).


The modification time of the file is the time that the file 
was last changed (which would be the creation time if it were 
only ever written to once, but in the general case, it has no 
relation to the creation time at all). So, you could use 
std.file.timeLastModified to find out if a file has been 
changed within the last x number of days, but there is no way 
to find out the creation time of a file by asking the 
filesystem.


- Jonathan M Davis


Hi Jonathan,

  Thank you,  i got your point from the other forum topic which 
was raised by me earlier, hence decided to use modification 
time, the request is on how and the best approach to port the 
code from windows to Linux eg program below


Example Code:
import std.stdio: writeln;
import std.container.array;
import std.file: dirEntries,isFile, SpanMode;
import std.algorithm: filter, map;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;


version (Windows) { alias sTimeStamp = timeCreated; } else 
version (linux) { alias sTimeStamp = timeLastAccessed; }


auto clogClean (string LogDir ) {
Array!(Tuple!(string, SysTime)) dFiles;
 dFiles.insert(dirEntries(LogDir, SpanMode.shallow).filter!(a 
=> a.isFile).map!(a => tuple(a.name, a.sTimeStamp)));

 return dFiles;
}

void main () {
string LogDir;
LogDir = "//DScript/Test";   //  Error: undefined 
identifier timeLastAccessed on Linux
LogDir = "C:\\DScript\\Others";  //  Error: undefined 
identifier timeCreated on Windows.

writeln(clogClean(LogDir));
}

From,
Vino.B


Unlike NTFS for Windows there's a plethora of different file 
systems available to use for Linux, one of which doesn't even 
support deletion of files. You also have to keep in mind that 
even if the same file system is used, there is no guarantee that 
you have the same set of metadata available for a mount point 
each and every time.
Consider a file system that's mounted with the 'noatime' option, 
for instance, which doesn't log access times.


As far as I understand you are globing files, check times and 
then act upon that.
If I were to port this to Linux, or any other OS for that matter, 
I wouldn't depend on a feature of an OS.
Instead, since you have to look at a file either way to get the 
meta data (which you query with the stat family of functions), I 
would build my own database or cache with that information.
Glob the directory and add files not yet present with the current 
date (and any other meta data you might need).
Then query all the files of interest and do whatever you want to 
do with them and remove the entry.


Downside is you have possibly another dependency. On the plus 
side you could easily query all files older than X days or 
whatever with a single select and batch process them.




Re: using Unsized Arrays in Structures from d?

2018-05-04 Thread Timoses via Digitalmars-d-learn

On Friday, 4 May 2018 at 13:27:03 UTC, NewUser wrote:

Hi Timoses,

The structure is being returned from c and I'd like use it from 
d.


What you have work perfectly when assigning from d.


Regards,
NewUser


Then you probably need some `extern(C)` statement introducing the 
C function and the struct type, right?


You could also try dstep to "translate" the C header file to D:
https://github.com/jacob-carlborg/dstep


Re: LDC phobos2-ldc.lib(json.obj) : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86'

2018-05-04 Thread kinke via Digitalmars-d-learn
On Thursday, 3 May 2018 at 23:47:40 UTC, IntegratedDimensions 
wrote:

Maybe this is a cross compilation issue?


Looks like you simply didn't download the LDC multilib package.


Re: C++ / Wrong function signature generated for reference parameter

2018-05-04 Thread Timoses via Digitalmars-d-learn

On Thursday, 3 May 2018 at 11:29:59 UTC, Robert M. Münch wrote:

Not sure I understand this too. This is now what I get:

DMD: public: unsigned int __cdecl b2d::Context2D::_begin(class 
b2d::Image & __ptr64,class b2d::Context2D::InitParams const * 
__ptr64 const) __ptr64
LIB: public: unsigned int __cdecl b2d::Context2D::_begin(class 
b2d::Image & __ptr64,class b2d::Context2D::InitParams const * 
__ptr64) __ptr64


So I somehow get some more const from D. This is the code I 
used:


   final uint _begin(ref Image image, const(InitParams) 
initParams);


Any idea how to solve this?

I really like that I'm able to use C++ stuff from D but 
interfacing the tow is a bit tedious... it would be great to be 
able to write the C++ signature in the extern(C++) scope and 
have it translated to the D equivalent internally.


Just as a note:
Related (if not to say duplicate) topic: 
https://forum.dlang.org/post/pch39e$nt7$1...@digitalmars.com


Re: Coding Challenges at Dconf2018: Implement Needleman–Wunsch and Smith–Waterman algorithms

2018-05-04 Thread biocyberman via Digitalmars-d-learn

On Friday, 4 May 2018 at 14:13:19 UTC, Luís Marques wrote:

On Monday, 30 April 2018 at 18:47:21 UTC, biocyberman wrote:
I am attending Dconf 2018 and giving a talk there on May 4. 
Link: https://dconf.org/2018/talks/le.html. It will be very 
interesting to talk about the outcome of the following 
challenges. If we can't have at least 3 solutions by three 
individuals by 10:00 GMT+2 May 4, I will have to postpone the 
deadline one week. Please see below for more details.


Too bad this didn't go on announce. I'm looking forward to it. 
I'll try to send my solution if this is postponed.


Hi Louis,
I will wait :)



Re: Windows to Linux Porting - timeCreated and timeLastAccessed

2018-05-04 Thread Vino via Digitalmars-d-learn

On Friday, 4 May 2018 at 14:02:24 UTC, Jonathan M Davis wrote:
On Friday, May 04, 2018 13:17:36 Vino via Digitalmars-d-learn 
wrote:

On Friday, 4 May 2018 at 12:38:07 UTC, Adam D. Ruppe wrote:
> What are you actually trying to do with it? These functions 
> are probably the wholly wrong approach.


Hi Adam,

  The existing program in Windows do few task's eg: Delete 
files
older that certain days, and now we are trying to port to 
Linux,
and above was just a example, hence asked the right approach 
for

porting.


Linux does not keep track of the creation time of a file. So, 
it will not work to have a program on Linux ask a file how long 
it's been since the file was created. If you want that 
information, you'll have to store it elsewhere somehow (and 
that generally only works if you created the file in the first 
place).


The modification time of the file is the time that the file was 
last changed (which would be the creation time if it were only 
ever written to once, but in the general case, it has no 
relation to the creation time at all). So, you could use 
std.file.timeLastModified to find out if a file has been 
changed within the last x number of days, but there is no way 
to find out the creation time of a file by asking the 
filesystem.


- Jonathan M Davis


Hi Jonathan,

  Thank you,  i got your point from the other forum topic which 
was raised by me earlier, hence decided to use modification time, 
the request is on how and the best approach to port the code from 
windows to Linux eg program below


Example Code:
import std.stdio: writeln;
import std.container.array;
import std.file: dirEntries,isFile, SpanMode;
import std.algorithm: filter, map;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;


version (Windows) { alias sTimeStamp = timeCreated; } else 
version (linux) { alias sTimeStamp = timeLastAccessed; }


auto clogClean (string LogDir ) {
Array!(Tuple!(string, SysTime)) dFiles;
 dFiles.insert(dirEntries(LogDir, SpanMode.shallow).filter!(a => 
a.isFile).map!(a => tuple(a.name, a.sTimeStamp)));

 return dFiles;
}

void main () {
string LogDir;
LogDir = "//DScript/Test";   //  Error: undefined identifier 
timeLastAccessed on Linux
LogDir = "C:\\DScript\\Others";  //  Error: undefined identifier 
timeCreated on Windows.

writeln(clogClean(LogDir));
}

From,
Vino.B


Re: Coding Challenges at Dconf2018: Implement Needleman–Wunsch and Smith–Waterman algorithms

2018-05-04 Thread Luís Marques via Digitalmars-d-learn

On Monday, 30 April 2018 at 18:47:21 UTC, biocyberman wrote:
I am attending Dconf 2018 and giving a talk there on May 4. 
Link: https://dconf.org/2018/talks/le.html. It will be very 
interesting to talk about the outcome of the following 
challenges. If we can't have at least 3 solutions by three 
individuals by 10:00 GMT+2 May 4, I will have to postpone the 
deadline one week. Please see below for more details.


Too bad this didn't go on announce. I'm looking forward to it. 
I'll try to send my solution if this is postponed.


Re: LDC phobos2-ldc.lib(json.obj) : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'x86'

2018-05-04 Thread Johan Engelen via Digitalmars-d-learn
On Thursday, 3 May 2018 at 23:47:40 UTC, IntegratedDimensions 
wrote:
trying to compile a simple program in x86. Compiles fine in dmd 
and ldcx64.


Seems like ldc is using the wrong lib for some reason?


phobos2-ldc.lib(json.obj) : fatal error LNK1112: module machine 
type 'x64' conflicts with target machine type 'x86'


To help, we need more details, such as what code are you 
compiling, what version of LDC, and what commandline.


- Johan



Re: Windows to Linux Porting - timeCreated and timeLastAccessed

2018-05-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, May 04, 2018 13:17:36 Vino via Digitalmars-d-learn wrote:
> On Friday, 4 May 2018 at 12:38:07 UTC, Adam D. Ruppe wrote:
> > What are you actually trying to do with it? These functions are
> > probably the wholly wrong approach.
>
> Hi Adam,
>
>   The existing program in Windows do few task's eg: Delete files
> older that certain days, and now we are trying to port to Linux,
> and above was just a example, hence asked the right approach for
> porting.

Linux does not keep track of the creation time of a file. So, it will not
work to have a program on Linux ask a file how long it's been since the file
was created. If you want that information, you'll have to store it elsewhere
somehow (and that generally only works if you created the file in the first
place).

The modification time of the file is the time that the file was last changed
(which would be the creation time if it were only ever written to once, but
in the general case, it has no relation to the creation time at all). So,
you could use std.file.timeLastModified to find out if a file has been
changed within the last x number of days, but there is no way to find out
the creation time of a file by asking the filesystem.

- Jonathan M Davis



Re: How do you connect Python with D via socket, I'm still getting connection refused error

2018-05-04 Thread Andy Smith via Digitalmars-d-learn

On Thursday, 3 May 2018 at 23:58:24 UTC, Enjoys Math wrote:

Error
-

[...]



Haven't run it, but two things to try...

On D side try adding listen after bind.

On python side. Don't think you need to call bind the client 
socket ( this may cause problems).


Cheers,

A.





Re: using Unsized Arrays in Structures from d?

2018-05-04 Thread NewUser via Digitalmars-d-learn

On Friday, 4 May 2018 at 13:21:53 UTC, Timoses wrote:

On Friday, 4 May 2018 at 13:02:08 UTC, NewUser wrote:
tried defining items[] as both "Item[] items" and "Item* 
items" in d, it compiles okay but gives an error when trying 
to access it.


You were on the right track. D array notation is:

[] ;

For me this works:

```
struct Item
{
  int id;
};

struct Group
{
  int i;
  int item_count;
  Item[] items;
};

void main()
{
auto g = Group();
g.items ~= Item(3);
assert(g.items[0].id == 3);
}
```


Hi Timoses,

The structure is being returned from c and I'd like use it from d.

What you have work perfectly when assigning from d.


Regards,
NewUser



Re: using Unsized Arrays in Structures from d?

2018-05-04 Thread Timoses via Digitalmars-d-learn

On Friday, 4 May 2018 at 13:02:08 UTC, NewUser wrote:
tried defining items[] as both "Item[] items" and "Item* items" 
in d, it compiles okay but gives an error when trying to access 
it.


You were on the right track. D array notation is:

[] ;

For me this works:

```
struct Item
{
  int id;
};

struct Group
{
  int i;
  int item_count;
  Item[] items;
};

void main()
{
auto g = Group();
g.items ~= Item(3);
assert(g.items[0].id == 3);
}
```


Re: using Unsized Arrays in Structures from d?

2018-05-04 Thread Simen Kjærås via Digitalmars-d-learn

On Friday, 4 May 2018 at 13:02:08 UTC, NewUser wrote:

How can I use the following c structure from d.

struct Item
{
  int id;
};

struct Group
{
  int i;
  int item_count;
  struct Item items[];
};

tried defining items[] as both "Item[] items" and "Item* items" 
in d, it compiles okay but gives an error when trying to access 
it.


Here is the error.
object.Error@(0): Access Violation


The D equivalent is:

struct Item {
int id;
}

struct Group {
int i;
int item_count;
Item* items;
}

The error message you're getting makes me think items is null. 
The lack of function names in the stack trace makes it kinda hard 
to understand exactly what's happening - you can turn that on 
with -g for DMD. Seeing some of the code that uses these structs 
might also help.


--
  Simen


Re: Windows to Linux Porting - timeCreated and timeLastAccessed

2018-05-04 Thread Vino via Digitalmars-d-learn

On Friday, 4 May 2018 at 12:38:07 UTC, Adam D. Ruppe wrote:
What are you actually trying to do with it? These functions are 
probably the wholly wrong approach.


Hi Adam,

 The existing program in Windows do few task's eg: Delete files 
older that certain days, and now we are trying to port to Linux, 
and above was just a example, hence asked the right approach for 
porting.




From,
Vino.B



using Unsized Arrays in Structures from d?

2018-05-04 Thread NewUser via Digitalmars-d-learn

Hi,

How can I use the following c structure from d.

struct Item
{
  int id;
};

struct Group
{
  int i;
  int item_count;
  struct Item items[];
};

tried defining items[] as both "Item[] items" and "Item* items" 
in d, it compiles okay but gives an error when trying to access 
it.


Here is the error.
object.Error@(0): Access Violation

0x00BCA9D1
0x00BC104C
0x00BD01EB
0x00BD0169
0x00BD
0x00BCA827
0x74118654 in BaseThreadInitThunk
0x77534B17 in RtlGetAppContainerNamedObjectPath
0x77534AE7 in RtlGetAppContainerNamedObjectPath


Regards,
NewUser




Re: Windows to Linux Porting

2018-05-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, May 04, 2018 10:25:28 Russel Winder via Digitalmars-d-learn 
wrote:
> On Fri, 2018-05-04 at 08:47 +, Vino via Digitalmars-d-learn wrote:
>
> […]
>
> >   Was able to resolve the issue, the issue was the letter "L" in
> >
> > version (Linux) where is should be version (linux).
>
> It would have helped if I had read the code first rather than jumped to a
> conclusion.
>
> :-)

It happens to us all from time to time, and the casing of the version
identifiers can be easy to screw up and easy to miss the mistakes -
especially since many of them are based on the names that get used with
#ifdef in C/C++ rather than having consistent casing across the various
version identifiers.

- Jonathan M Davis




Re: Windows to Linux Porting - timeCreated and timeLastAccessed

2018-05-04 Thread Adam D. Ruppe via Digitalmars-d-learn
What are you actually trying to do with it? These functions are 
probably the wholly wrong approach.


Windows to Linux Porting - timeCreated and timeLastAccessed

2018-05-04 Thread Vino via Digitalmars-d-learn

Hi All,

  Request your help, I have a D program written on Windows 
platform and the program is working as expected, now i am trying 
to port the same program to Linux, my program use the function 
"timeCreated" from std.file for Windows hugely where as in Linux 
we do not have the same function hence planned to use the 
function "timeLastAccessed" from std.file, so what is the best 
approach to port the program. I tried the below code but not 
working, so can you one please guide me on the right method to 
port the program to linux, below is the example code.


Example Code:
import std.stdio: writeln;
import std.container.array;
import std.file: dirEntries,isFile, SpanMode;
import std.algorithm: filter, map;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;


version (Windows) { alias sTimeStamp = timeCreated; } else 
version (linux) { alias sTimeStamp = timeLastAccessed; }


auto clogClean (string LogDir ) {
Array!(Tuple!(string, SysTime)) dFiles;
 dFiles.insert(dirEntries(LogDir, SpanMode.shallow).filter!(a => 
a.isFile).map!(a => tuple(a.name, a.sTimeStamp)));

 return dFiles;
}

void main () {
string LogDir;
LogDir = "//DScript/Test";   //  Error: undefined identifier 
timeLastAccessed on Linux
LogDir = "C:\\DScript\\Others";  //  Error: undefined identifier 
timeCreated on Windows.

writeln(clogClean(LogDir));
}

From,
Vino.B




Re: Windows to Linux Porting

2018-05-04 Thread Vino via Digitalmars-d-learn

On Friday, 4 May 2018 at 09:25:28 UTC, Russel Winder wrote:
On Fri, 2018-05-04 at 08:47 +, Vino via Digitalmars-d-learn 
wrote:



[…]
  Was able to resolve the issue, the issue was the letter "L" 
in

version (Linux) where is should be version (linux).


It would have helped if I had read the code first rather than 
jumped to a conclusion.


:-)


Hi Russel,
 No issue, and thank you for your help.

From,
Vino.B




could someone test support for Asian languages in nanogui port?

2018-05-04 Thread drug via Digitalmars-d-learn
I port nanogui, but besides porting I'd like to improve it using great 
capabilities of D language provides. One of them is utf support, so I 
added support for Asian languages to nanogui.TextBox. But I'm not sure 
I've did it well and so I'd like to ask someone to test it using the 
following:

```
git clone --recursive https://github.com/drug007/nanogui.git
cd nanogui
git checkout textbox # TextBox exists in this branch only
dub --config=sdl # Keyboard events provided only by SDL2 backend only
```

On the right side there will be a window with four text boxes with 
russian, english, japanese and chinese text respectively. It would be 
nice to get some feedback from users - probably I did something totally 
wrong. Also I'm curious does it worth efforts?


Re: Windows to Linux Porting

2018-05-04 Thread Russel Winder via Digitalmars-d-learn
On Fri, 2018-05-04 at 08:47 +, Vino via Digitalmars-d-learn wrote:
> 
[…]
>   Was able to resolve the issue, the issue was the letter "L" in 
> version (Linux) where is should be version (linux).

It would have helped if I had read the code first rather than jumped to a
conclusion.

:-)



-- 
Russel.
==
Dr Russel Winder  t: +44 20 7585 2200
41 Buckmaster Roadm: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk


signature.asc
Description: This is a digitally signed message part


Re: Windows to Linux Porting

2018-05-04 Thread Vino via Digitalmars-d-learn

On Friday, 4 May 2018 at 07:43:39 UTC, Russel Winder wrote:
On Fri, 2018-05-04 at 03:30 +, Vino via Digitalmars-d-learn 
wrote:

[...]


`./nasconfig.txt`

perhaps: Linux uses / (as does Windows in fact) for directory 
separator.



[...]


Hi Russel,

 Was able to resolve the issue, the issue was the letter "L" in 
version (Linux) where is should be version (linux).



From,
Vino.B


Re: Windows to Linux Porting

2018-05-04 Thread Russel Winder via Digitalmars-d-learn
On Fri, 2018-05-04 at 03:30 +, Vino via Digitalmars-d-learn wrote:
> Hi All,
> 
>Request you help on the below code, the below code always state 
> the file does not exist even if the file do exist.
> 
> Code:
> 
> import core.stdc.stdlib: exit;
> import std.stdio;
> import std.file;
> import std.path;
> 
> auto osSwitch () {
> string ConfigFile;
> version (Windows) { ConfigFile = absolutePath(`.\nasconfig.txt`); 

`./nasconfig.txt`

perhaps: Linux uses / (as does Windows in fact) for directory separator. 

> } else version (Linux) { ConfigFile = 
> absolutePath(`nasconfig.txt`); }
> return ConfigFile;
> }
> void main () {
> auto ConfigFile = osSwitch;
> if (!ConfigFile.exists) { writeln("The Configuration File ", 
> buildNormalizedPath(ConfigFile), " do to exist, Terminating the 
> execution.."); exit(-1);}
> else { writeln(ConfigFile); }
> }
> 
> From,
> Vino.B
> 
-- 
Russel.
==
Dr Russel Winder  t: +44 20 7585 2200
41 Buckmaster Roadm: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk


signature.asc
Description: This is a digitally signed message part


Re: C++ / const class pointer signature / unable to find correct D syntax

2018-05-04 Thread Uknown via Digitalmars-d-learn

On Friday, 4 May 2018 at 07:49:02 UTC, Robert M. Münch wrote:
I have a static C++ and can't make it to get a correct binding 
for one function:


DMD: public: unsigned int __cdecl b2d::Context2D::_begin(class 
b2d::Image & __ptr64,class b2d::Context2D::InitParams const * 
__ptr64 const) __ptr64
LIB: public: unsigned int __cdecl b2d::Context2D::_begin(class 
b2d::Image & __ptr64,class b2d::Context2D::InitParams const * 
__ptr64) __ptr64


So I somehow get some more const from D. This is the code I 
used:


   final uint _begin(ref Image image, const(InitParams) 
initParams);


Which creates a const pointer to a const class signature. But 
it should only be a const pointer. Any idea how to solve this?


The problem is that const in D is transitive. That means T * 
const from C++ is not expressible in D. Any reference through a 
const becomes const. To use it, IMO your best bet is to make a 
wrapper function on the C++ side like this:


unsigned int __cdecl b2d::Context2D::_begin(class b2d::Image & 
im,class b2d::Context2D::InitParams const * const InitParams)

{
return //the call to the original c++ function
}

Alternatively you can use dpp, or dstep or some similar tool to 
try and let the tool create bindings. As a last ditch, you can 
force the mangle to match by using pragma(mangle, ...) like this:


pragma(mangle, _ZactualMangleFromC++Compiler)
final uint _begin(ref Image image, const(InitParams) initParams);


C++ / const class pointer signature / unable to find correct D syntax

2018-05-04 Thread Robert M. Münch via Digitalmars-d-learn
I have a static C++ and can't make it to get a correct binding for one 
function:


DMD: public: unsigned int __cdecl b2d::Context2D::_begin(class 
b2d::Image & __ptr64,class b2d::Context2D::InitParams const * __ptr64 
const) __ptr64
LIB: public: unsigned int __cdecl b2d::Context2D::_begin(class 
b2d::Image & __ptr64,class b2d::Context2D::InitParams const * __ptr64) 
__ptr64


So I somehow get some more const from D. This is the code I used:

   final uint _begin(ref Image image, const(InitParams) initParams);

Which creates a const pointer to a const class signature. But it should 
only be a const pointer. Any idea how to solve this?


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



Re: Is HibernateD dead?

2018-05-04 Thread bauss via Digitalmars-d-learn

On Thursday, 3 May 2018 at 23:05:02 UTC, Matthias Klumpp wrote:

On Thursday, 3 May 2018 at 21:28:18 UTC, bauss wrote:

On Thursday, 3 May 2018 at 18:01:07 UTC, Matthias Klumpp wrote:
DiamondMVC looks nice, but I would need PostgreSQL support 
for sure.

Therefore, I think there are three options:
 1) Extend the DiamondMVC ORM to support missing features 
that Hibernated has (maybe make it use ddbc as backend?)
 2) Revive Hibernated - contacting Vadim Lopatin would be key 
for that, and maybe the project could be maintained in the 
dlang-community organization (although there are competing 
projects for it...)
 3) Find a different D ORM that does the job and expand it to 
include missing features.


Yes, I completely agree with PostgreSQL support. It's really 
important to me getting that working, as well MSSQL. I was 
hoping I could find time this weekend to actually do that.


Would it maybe be easier for you to base on ddbc[1] or another 
existing abstraction layer for database abstraction?
Ddbc is pretty neat, and even has support for reading structs 
directly from the database.




Perhaps, but it'd have to be a forked version as I don't really 
want to depend on something that isn't updated regularly.


ddbc's last commit was a year ago.

I can't seem to find a license for it though?



[1]: https://github.com/buggins/ddbc

Perhaps I will end up having another "optional" dependency to 
it as a temporary until I can have a better implementation or 
something.


The frontend part of postgresql is almost finished, it's just 
having the postgresql driver working properly, which is where 
it's frozen right now.


Hmm... Does any public code for that exist already that I could 
play around with?
Unfortunately, I have a few more unusual requirements for 
Postgres, like:

 * UUIDs as primary keys, instead of integers


As far as I remember the implementation of @DbId in Diamond, then 
it supports whatever type.


Diamond doesn't care much about what type your primary key is.

I will make sure that's how it function of course, if it 
currently doesn't behave like it, but I'm pretty sure it does.


 * Ability to register custom datatypes with the ORM (version 
numbers in this case, the ORM can view them as text, but the 
database has a special type for them)


That could be done with some attribute that lets you handle 
columns yourself.


Do you have a good name for it?

I was thinking @DbProxy and then the function would be something 
like:


@DbProxy(functionName) string field;

...

auto functionName(RawDbType type)
{
return the new datatype that matches the field with the 
@DbProxy attribute.

}

 * Obviously the usual ORM stuff, one-to-many, many-to-many, 
etc. relations




Yes, relations is one thing I haven't added and I have been 
wanting to do it for a while.


I will definitely look into having it added as well.

(Obviously not a must-have list, I added support for custom 
datatypes to my ddbc fork as well, because it's not really a 
feature many people need)




Well, that's kind of the key to most of the development in 
Diamond.


I usually add functionality that isn't widely used and in most 
cases people implement it themselves ex. the whole diamond.seo is 
not usually something a framework has.


Diamond is a neat project, I played around with it about half a 
year ago, but didn't test the ORM part at all back then.


It wasn't that good back then and has improved a lot since, as 
well many other parts of Diamond. Over the past half year it has 
grown rapidly, both in stability and functionality.