Ddoc and struct members

2017-12-13 Thread n00nb via Digitalmars-d-learn

Hi all!

How do I generate documentation for struct members using ddoc?

I don't understand if there is a way to generate documentation 
for all the members without putting a '///' over every member


Re: Ddoc and struct members

2017-12-13 Thread rikki cattermole via Digitalmars-d-learn

On 14/12/2017 3:16 AM, n00nb wrote:

Hi all!

How do I generate documentation for struct members using ddoc?

I don't understand if there is a way to generate documentation for all 
the members without putting a '///' over every member


There isn't.


Re: How to catch line number of exception without catching it ?

2017-12-13 Thread codephantom via Digitalmars-d-learn

On Wednesday, 13 December 2017 at 18:24:09 UTC, Thomas wrote:
Or is there a better solution for tracing the error position 
from root till the branch ?




Speaking of tracing exceptions, here's my favourite one .. so far 
;-)

(I mean come on.. debugging is great fun!)

btw. If you compile/run this code on Windows, using LDC, you'll 
get a nice little beep from the speaker (when it runs).


// 
module test;

import std.stdio;

void main()
{
auto str = "hello";
string * ptr = 
writeln(ptr[1]);   //compile without using the -O option
// writeln(ptr.ptr[1]); // the above line was meant to be 
this line.

}
// 


Re: `Socket.receive` providing arbitrary packet sizes and hanging without sending EOF

2017-12-13 Thread Ali Çehreli via Digitalmars-d-learn

On 12/13/2017 11:39 AM, Unazed Spectaculum wrote:
> ubyte[] receiveBytes(T)(T socket, size_t receiveCount)
> {
>  ubyte[] buffer = new ubyte[receiveCount];
>  size_t count = socket.receive(buffer);

Don't trust code you find on newsgroups. :o) You have to check the 
returned value first. According to documentation, it can return 
Socket.ERROR:


  https://dlang.org/phobos/std_socket.html#.Socket.receive

> there is always a superfluous chunk
> which is awaiting data.

Can you show with complete code? Perhaps the stream is in blocking mode?

> No matter what way I try; my code doesn't seem to know when to quit
> regardless of the check. Also for the arbitrary packet sizes, I would've
> expected that if I received N bytes X times, the first X-1 times would
> be perfectly N not some unusual integer.
> Simply put, say I'm receiving 1024 bytes 5 times. The length of each
> item on the stack looks like:
>
> [720,
>   490,
>   1024,
>   103
> ]

Posix read(2) man page says

"It is not an error if this number is smaller than the number of bytes
requested; this may happen for example because fewer bytes are actually
available right now (maybe because we were close to end-of-file, or because
we are reading from a pipe, or from a terminal), or because read() was
interrupted by a signal."

Ali



Re: Global variable type does not match previous declaration

2017-12-13 Thread Satoshi via Digitalmars-d-learn

On Wednesday, 13 December 2017 at 21:38:49 UTC, Satoshi wrote:

What means this error and how to solve it?

object.d-mixin-1072(1112): Error: Global variable type does not 
match previous declaration with same mangled name: 
_D10TypeInfo_m6__initZ


Actually, I'm working on OS with minimal D runtime and I'm 
unable to compile object.d


source code:
https://github.com/Rikarin/Trinix/blob/a42a6e1fb4b87374b3e5ad8b9be501b080655ccd/Kernel/object.d

Thanks


Compiling with
ldc2 -debuglib= -defaultlib= -code-model=kernel -disable-red-zone 
-w -wi -de -O3 -mattr=-sse -I../ -of=obj-amd64/object.d.o -c 
-deps=obj-amd64/object.d.o.o.dep object.d


Global variable type does not match previous declaration

2017-12-13 Thread Satoshi via Digitalmars-d-learn

What means this error and how to solve it?

object.d-mixin-1072(1112): Error: Global variable type does not 
match previous declaration with same mangled name: 
_D10TypeInfo_m6__initZ


Actually, I'm working on OS with minimal D runtime and I'm unable 
to compile object.d


source code:
https://github.com/Rikarin/Trinix/blob/a42a6e1fb4b87374b3e5ad8b9be501b080655ccd/Kernel/object.d

Thanks


How to statically link Derelict SDL2 satellite libs

2017-12-13 Thread eskaypee via Digitalmars-d-learn
I'm on Linux 64 bit, all SDL libraries (-dev versions) are 
installed, dub is set up with:


"dependencies": {
"derelict-sdl2": "~>3.0.0-beta"
},
"subConfigurations": {
"derelict-sdl2": "derelict-sdl2-static"
},
"libs":
["sdl2"]

All the SDL core library functions work fine but when I try to 
use SDL_image library's IMG_Load() or IMG_LoadTexture() I get a 
linker error, for example:


undefined reference to `IMG_LoadTexture'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
dmd failed with exit code 1.

I have:
import derelict.sdl2.image;

at the top of my program. I'm guessing that the "libs" section of 
my dub subConfiguration needs to include the name of the image 
satellite library?




Re: Understanding how dub works

2017-12-13 Thread datboi via Digitalmars-d-learn
On Wednesday, 13 December 2017 at 00:43:31 UTC, rikki cattermole 
wrote:


1. Does dub compile dependencies as separate binaries? And if 
yes how to specify where should be they placed?


Object/static files, but yes.

Where they go:

Windows: %APPDATA%/roaming/dub
Posix: ~/.dub

You don't need to change this and if you think you do, you're 
wrong :)


2. It is possible to compile subpackage as a dynamic or static 
library and link it to main binary file? Or just better create 
separate dub package and use it as dependency?


Static yes, dynamic it won't link against (some bug last I 
heard).

Have to do that manually.

"dependencies": { "mypackage:subpackage": "*" }

Change as required for SDL.


At first thanks for answers.
So going back to my first question. Code from dependencies is 
compiled with mine project to one single executable?




Re: How to catch line number of exception without catching it ?

2017-12-13 Thread Nathan S. via Digitalmars-d-learn

On Wednesday, 13 December 2017 at 18:24:09 UTC, Thomas wrote:
So my question is: Is there a way to catch that line where the 
exception has happened without a catch ?


Yes: use a debugger.


Re: How to catch line number of exception without catching it ?

2017-12-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, December 13, 2017 18:24:09 Thomas via Digitalmars-d-learn 
wrote:
> Hi forks!
>
> I wanted to ask if there is a way to catch the line position on
> an exception without setting a try + catch block ?
> What I want is something like this:
>
>
> module main;
>
> import std.stdio;
> import std.conv;
>
> void foo()
> {
>   scope(failure)
>   {
>   writeln("Got a failure in ", __FILE__, " ", __FUNCTION__, "!" );
>   // what I miss is the line position with __LINE__
>   }
>
>   int x = to!int("1x");  // <-- here is the exception throwing
>
> }
>
> int main()
> {
>   foo();
>   return 0;
> }
>
>
> My goal is to trace the failure from the branch back to the root
> like this:
>
> (error) in "module2" at "foo2()" on line "..."
> (error) in "module1" at "foo1()" on line "..."
> (error) in "main" at "main()" on line "..."
>
> I don't want to set on every function a try + catch functionality
> because I think it is not a good coding style. Also I dont want
> to send on every possible position where an exception/error could
> happen (even when catched) the line position into an error log
> function. So I got the idea of writing out modulename and
> function with scope(failure) on the beginning of each function,
> which works great recursive, but only the line position is
> missing.
> So my question is: Is there a way to catch that line where the
> exception has happened without a catch ?
>
> Or is there a better solution for tracing the error position from
> root till the branch ?

If you want access to an exception in flight, you must catch it and rethrow
it. There is no other way.

But normally, if you want to see the stack when an exception was thrown,
you'd either use a debugger, or you'd look at the stack trace that gets
printed when the exception exits main (though unfortunately, as I understand
it, there's currently a regression, and the line numbers don't show up in
stack traces on Linux anymore, even when you compile with -g).

- Jonathan M Davis



`Socket.receive` providing arbitrary packet sizes and hanging without sending EOF

2017-12-13 Thread Unazed Spectaculum via Digitalmars-d-learn

ubyte[] receiveBytes(T)(T socket, size_t receiveCount)
{
ubyte[] buffer = new ubyte[receiveCount];
size_t count = socket.receive(buffer);
return buffer[0 .. count];
}

string receiveAll(T)(T socket, size_t segmentSize = 1024)
{
ubyte[][] data;
size_t count = 0;

do
{
debug(1) writefln("Chunk %s", count);
data ~= receiveBytes(socket, segmentSize);
writeln(data[count]);
if (!data)
break;

} while(data[count++]);

char[] stringData;

foreach (elem; data)
stringData ~= elem;

debug(1) writeln(`Exiting "receiveAll"`);

return to!string(stringData);
}


I've tried many variations of the above code; both with the 
retrieve integrated into the do-while loop in receiveAll; however 
I was just seeing whether abstracting the code would let me spot 
my issues a bit faster because it won't require me to make two 
variables for the buffer and amount of bytes received, more like 
the typical interface you get.


Issue is; when receiving any size buffer from the end-point 
(tested with >1024 byte and <1024 byte buffers); there is always 
a superfluous chunk which is awaiting data.



Listening: 0.0.0.0:6969
Client: somebody:58769
Chunk 0
[123, 34, 109, 101, 116, 104, 111, 100, 34, 58, 32, 34, 114, 101, 
116, 114, 105, 101, 118, 101, 34, 44, 32, 34, 102, 105, 108, 101, 
110, 97, 109, 101, 34, 58, 32, 34, 51, 48, 50, 54, 57, 50, 48, 
49, 55, 50, 51, 54, 56, 54, 57, 49, 50, 49, 95, 97, 97, 97, 97, 
97, 34, 44, 32, 34, 100, 97, 116, 97, 34, 58, 32, 34, 34, 125]

Chunk 1
[PAUSE]


Listening: 0.0.0.0:6969
Client: somebody:58767
Chunk 0
[123, 34, 109, 101, 116, 104, 111, 100, 34, 58, 32, 34, 114, 101, 
116, 114, 105, 101, 118, 101, 34, 44, 32, 34, 102, 105, 108, 101, 
110, 97, 109, 101, 34, 58, 32, 34, ... 97]

Chunk 1
[97, ... 125]
Chunk 2
[PAUSE]


No matter what way I try; my code doesn't seem to know when to 
quit regardless of the check. Also for the arbitrary packet 
sizes, I would've expected that if I received N bytes X times, 
the first X-1 times would be perfectly N not some unusual integer.
Simply put, say I'm receiving 1024 bytes 5 times. The length of 
each item on the stack looks like:


[720,
 490,
 1024,
 103
]

Although I'd assume it'd be more like:

[1024,
 1024,
 289
]

What's up with this? It makes working with sockets so damn 
tedious since there's no room for assumptions; can anybody 
suggest an abstracted library for sockets in D or help with my 
former issue?


How to catch line number of exception without catching it ?

2017-12-13 Thread Thomas via Digitalmars-d-learn

Hi forks!

I wanted to ask if there is a way to catch the line position on 
an exception without setting a try + catch block ?

What I want is something like this:


module main;

import std.stdio;
import std.conv;

void foo()
{
scope(failure)
{
writeln("Got a failure in ", __FILE__, " ", __FUNCTION__, "!" );
// what I miss is the line position with __LINE__
}

int x = to!int("1x");  // <-- here is the exception throwing

}

int main()
{
foo();
return 0;
}


My goal is to trace the failure from the branch back to the root 
like this:


(error) in "module2" at "foo2()" on line "..."
(error) in "module1" at "foo1()" on line "..."
(error) in "main" at "main()" on line "..."

I don't want to set on every function a try + catch functionality 
because I think it is not a good coding style. Also I dont want 
to send on every possible position where an exception/error could 
happen (even when catched) the line position into an error log 
function. So I got the idea of writing out modulename and 
function with scope(failure) on the beginning of each function, 
which works great recursive, but only the line position is 
missing.
So my question is: Is there a way to catch that line where the 
exception has happened without a catch ?


Or is there a better solution for tracing the error position from 
root till the branch ?


Thank you for your time!


Re: Tuple Array Sorting

2017-12-13 Thread Vino via Digitalmars-d-learn

On Tuesday, 12 December 2017 at 19:00:01 UTC, Biotronic wrote:

On Tuesday, 12 December 2017 at 15:19:35 UTC, Vino wrote:

import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writefln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;

void main () {
auto FFs =  ["C:\\Temp\\sapnas2\\BACKUP", 
"C:\\Temp\\sapnas2\\EXPORT", "C:\\Temp\\sapnas2\\PROD_TEAM"];

Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
	auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => 
tuple(a.name, a.timeCreated)));

foreach(e; dFiles) { Result ~= e; } }
writefln("%(%-(%-63s %.20s %)\n%)", Result[].sort!((a, b) 
=> a[1] < b[1]));

}


Since there's little need to extract timeCreated and name 
before sorting, here's a version that doesn't:


import std.algorithm : map, filter, sort;
import std.array : array;
import std.range : join;
import std.file : SpanMode, dirEntries, isDir;
import std.stdio : writefln;
import std.typecons : tuple;

void main() {
auto folders = [`C:\Windows`, `C:\Program Files`, 
`C:\Users`];


auto sorted = folders
.map!(f => f.dirEntries(SpanMode.shallow))
.join
.filter!(e => e.isDir)
.array
.sort!((a,b) => a.timeCreated < b.timeCreated)
.map!(e => tuple(e.name, e.timeCreated.toSimpleString[0 
.. 20]));


writefln("%(%-(%-63s %s %)\n%)", sorted);
}

And a version with normal loops, since the heavily range-based 
version above can be a bit dense. These programs do essentially 
the same thing:


import std.algorithm : sort;
import std.array : array;
import std.file : SpanMode, dirEntries, DirEntry, isDir;
import std.stdio : writefln;
import std.typecons : tuple, Tuple;

void main() {
auto folders = [`C:\Windows`, `C:\Program Files`, 
`C:\Users`];


DirEntry[] subFolders;

foreach (folder; folders) {
auto children = dirEntries(folder, SpanMode.shallow);
foreach (child; children) {
if (child.isDir) subFolders ~= child;
}
}

subFolders.sort!((a,b) => a.timeCreated < b.timeCreated);
Tuple!(string, string)[] interestingParts;

foreach (subFolder; subFolders) {
interestingParts ~= tuple(subFolder.name, 
subFolder.timeCreated.toSimpleString[0..20]);

}

writefln("%(%-(%-63s %s %)\n%)", interestingParts);
}

As you can see, I'm just chopping off the parts I don't like 
from toSimpleString. It seems a good format function for dates 
does not exist in Phobos.


--
  Biotronic


Hi Biotronic,

 I was able to find a solution using container array and also 
date formatting, below is the code, please do let me know if you 
find any issue, as i have tested the script and it is working as 
expected.


Program:
import std.algorithm: filter, map, sort, each;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln,writefln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;
import std.conv;
void main () {
auto FFs =  ["C:\\Temp\\sapnas2\\BACKUP", 
"C:\\Temp\\sapnas2\\EXPORT"];

Array!(Tuple!(string, SysTime)) Sorted;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated)));

foreach(i; dFiles[]){ Sorted ~= i; }
Sorted[].sort!((a,b) => a[1] > b[1]).each!(e => writefln!"%-63s 
%.20s"(e[0], e[1].to!string));

}
}

From,
Vino.B


Re: Container Array or tuples Sorting

2017-12-13 Thread Vino via Digitalmars-d-learn

On Wednesday, 13 December 2017 at 15:58:40 UTC, Vino wrote:

On Wednesday, 13 December 2017 at 15:16:50 UTC, Vino wrote:

Hi All,

 Request your help, on how to sort a tuple container array, I 
have raised the same topic in one of the other thread "Tuple 
Array Sorting" and was addressed to use standard array rather 
than container array, and i am not able to find any document 
or example in the library for the same.


Eg: Program.
import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;

void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT"];
Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir)

.sort!((a,b) => a.timeCreated > b.timeCreated)
.map!(a => tuple(a.name, a.timeCreated)));
writeln(dFiles[]);
} }

From,
Vino.B


HI All,

  As per the message from the below forum  I understand that 
that we cannot perform a sorting on filtered result a container 
array but the same can be performed form the standard array, so 
i adjusted the above code as below and getting a different 
error than what is discussed in the forum.


Forum:
 
"https://forum.dlang.org/post/mcteinnryudlqvbkq...@forum.dlang.org;


Program:
void main () {
auto FFs =  ["C:\\Temp\\sapnas2\\BACKUP", 
"C:\\Temp\\sapnas2\\EXPORT"];

Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated)))[]

.sort!((a,b) => a[1] > b[1]);
writeln(dFiles[]);
} }

Error:
Message.d(14): Error: function 
Message.main.SortedRange!(RangeT!(Array!(Tuple!(string, 
SysTime))), __lambda3).SortedRange.opSlice (uint a, uint b) is 
not callab

le using argument types ()
Failed: ["dmd", "-v", "-o-", "Message.d", "-I."]

From,
Vino.B


Hi All,

 Was able to find a solution and it is working as expected

import std.algorithm: filter, map, sort, each;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln,writefln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;
import std.conv;
void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT"];
Array!(Tuple!(string, SysTime)) Sorted;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated)));

foreach(i; dFiles[]){ Sorted ~= i; }
Sorted[].sort!((a,b) => a[1] > b[1]).each!(e => writefln!"%-63s 
%.20s"(e[0], e[1].to!string));

}
}

From,
Vino.B


Re: Date Formating

2017-12-13 Thread Vino via Digitalmars-d-learn

On Wednesday, 13 December 2017 at 17:16:46 UTC, Vino wrote:
On Wednesday, 13 December 2017 at 08:32:34 UTC, codephantom 
wrote:

[...]


Hi All,

[...]


Hi All, Thank you very much , was able to resolve the issue by 
changing the writefln line as below.


Sorted[].sort!((a,b) => a[1] > b[1]).each!(e => writefln!"%-63s 
%.20s"(e[0], e[1].to!string));


From,
Vino.B


Re: Date Formating

2017-12-13 Thread Vino via Digitalmars-d-learn

On Wednesday, 13 December 2017 at 08:32:34 UTC, codephantom wrote:
On Wednesday, 13 December 2017 at 07:35:40 UTC, Jonathan M 
Davis wrote:
In general, you probably want to cast the SysTime to a 
DateTime if you're going to do something like that.


yes, I would agree ;-)

Of course the intention was not really to just format it the 
same way as Clock.currTime() does it, but rather to provide a 
way to more easily customise the format, however one likes, 
whenever one likes..


e.g.the following small change to the format string would make 
it return: 20171213_1924_41


(that's more like something I'd use)

  return
format("%04s%02s%02s_%02s%02s_%02s",
(d.year),
to!(int)(d.month),
(d.day),
(d.hour),
(d.minute),
(d.second)
);


Hi All,

 Request your help on below program on how to format or cast 
SysTime to DateTime


import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln,writefln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;
void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\\EXPORT"];
Array!(Tuple!(string, SysTime)) Sorted;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated)));

foreach(i; dFiles[]){ Sorted ~= i; }
writefln("%(%-(%-63s %s %)\n%)", Sorted[].sort!((a,b) => a[1] < 
b[1]));

}
}

Output:
C:\Temp\BACKUP\DND3 
2017-Sep-05 14:31:00.7037169
C:\Temp\BACKUP\DND5 
2017-Sep-05 14:31:00.750517
C:\Temp\EXPORT\DND6 
2017-Sep-05 14:31:00.8909172
C:\Temp\BACKUP\dir1 
2017-Sep-06 16:06:42.7223837
C:\Temp\EXPORT\dir2 
2017-Sep-06 16:06:43.1435864
C:\Temp\BACKUP\dir2 
2017-Sep-09 22:44:11.7604069
C:\Temp\BACKUP\dir3 
2017-Dec-10 06:56:07.5122231
C:\Temp\BACKUP\t1   
2017-Dec-11 04:10:02.6413853


Required Output
C:\Temp\BACKUP\DND3 
2017-Sep-05 14:31:00
C:\Temp\BACKUP\DND5 
2017-Sep-05 14:31:00
C:\Temp\EXPORT\DND6 
2017-Sep-05 14:31:00
C:\Temp\BACKUP\dir1 
2017-Sep-06 16:06:42
C:\Temp\EXPORT\dir2 
2017-Sep-06 16:06:43
C:\Temp\BACKUP\dir2 
2017-Sep-09 22:44:11
C:\Temp\BACKUP\dir3 
2017-Dec-10 06:56:07
C:\Temp\BACKUP\t1   
2017-Dec-11 04:10:02


From,
Vino.B



Re: GUI program on Mac OS in D?

2017-12-13 Thread mrphobby via Digitalmars-d-learn
On Wednesday, 13 December 2017 at 15:17:59 UTC, Jacob Carlborg 
wrote:
I forgot to mention that there have been several discussions 
around adding support for reference counted classes. Several of 
the mentioning interfacing with Objective-C is important/a 
requirement.


Ok, good to know!

I have another question about your Webkit test example... I see 
that you are doing some elaborate setup in order to bind the 
application delegate methods. Can you explain a bit about why you 
are doing it in this way instead of using the @selector attribute 
in a class?


The thing is that I'm currently attempting to get it to work 
using the "easy" way using @selector but the methods in my 
AppDelegate class are not called. Not sure why that is, but I 
probably screwed something up :)




Re: Container Array or tuples Sorting

2017-12-13 Thread Vino via Digitalmars-d-learn

On Wednesday, 13 December 2017 at 15:16:50 UTC, Vino wrote:

Hi All,

 Request your help, on how to sort a tuple container array, I 
have raised the same topic in one of the other thread "Tuple 
Array Sorting" and was addressed to use standard array rather 
than container array, and i am not able to find any document or 
example in the library for the same.


Eg: Program.
import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;

void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT"];
Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir)

.sort!((a,b) => a.timeCreated > b.timeCreated)
.map!(a => tuple(a.name, a.timeCreated)));
writeln(dFiles[]);
} }

From,
Vino.B


HI All,

  As per the message from the below forum  I understand that that 
we cannot perform a sorting on filtered result a container array 
but the same can be performed form the standard array, so i 
adjusted the above code as below and getting a different error 
than what is discussed in the forum.


Forum:
 
"https://forum.dlang.org/post/mcteinnryudlqvbkq...@forum.dlang.org;


Program:
void main () {
auto FFs =  ["C:\\Temp\\sapnas2\\BACKUP", 
"C:\\Temp\\sapnas2\\EXPORT"];

Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated)))[]

.sort!((a,b) => a[1] > b[1]);
writeln(dFiles[]);
} }

Error:
Message.d(14): Error: function 
Message.main.SortedRange!(RangeT!(Array!(Tuple!(string, 
SysTime))), __lambda3).SortedRange.opSlice (uint a, uint b) is 
not callab

le using argument types ()
Failed: ["dmd", "-v", "-o-", "Message.d", "-I."]

From,
Vino.B


Re: GUI program on Mac OS in D?

2017-12-13 Thread Jacob Carlborg via Digitalmars-d-learn

On 2017-12-13 16:07, Jacob Carlborg wrote:

On 2017-12-13 13:18, mrphobby wrote:


Would it be possible to somehow hook this up automatically to the D 
destructor perhaps? Interested in hearing your thoughts on this!


As far as I know, the destructor is only called (automatically by the 
GC). Since the Objective-C objects are not created using the GC the 
destructor will never be called. I don't think it's possible to 
implement reference counting (that would call retain/release) for 
classes in D, since it's not possible to overload the assignment 
operator for classes [2] or implement a postblit [3]. The only option, 
as far as I know, would be to wrap the class in a struct that calls 
retain/release automatically. But then you need to box/unbox the wrapped 
class constantly and all the method signatures would probably need to 
use this wrapper as well.


I forgot to mention that there have been several discussions around 
adding support for reference counted classes. Several of the mentioning 
interfacing with Objective-C is important/a requirement.


https://wiki.dlang.org/Language_design_discussions#Automatic_Reference_Counting_.28ARC.29_as_an_alternative_to_D.27s_Garbage_Collector

http://forum.dlang.org/post/n0nnu0$1tth$1...@digitalmars.com

https://wiki.dlang.org/FatPointer#Interfacing_with_Objective-C

--
/Jacob Carlborg


Container Array or tuples Sorting

2017-12-13 Thread Vino via Digitalmars-d-learn

Hi All,

 Request your help, on how to sort a tuple container array, I 
have raised the same topic in one of the other thread "Tuple 
Array Sorting" and was addressed to use standard array rather 
than container array, and i am not able to find any document or 
example in the library for the same.


Eg: Program.
import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;

void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT"];
Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir)

.sort!((a,b) => a.timeCreated > b.timeCreated)
.map!(a => tuple(a.name, a.timeCreated)));
writeln(dFiles[]);
} }

From,
Vino.B



Re: GUI program on Mac OS in D?

2017-12-13 Thread Jacob Carlborg via Digitalmars-d-learn

On 2017-12-13 13:18, mrphobby wrote:

I have been taking a look at your example. Looks pretty neat! Some 
advanced mixin stuff there that looks pretty useful.


They're pretty basic ;)

However, as far as 
I can tell there is no handling of retain/release.


No, that's correct.

How would you 
incorporate this into your mixin system without having to put "release" 
in all the interface definitions?


You can add methods for retain/release in the ClassTrait template [1].

Would it be possible to somehow hook 
this up automatically to the D destructor perhaps? Interested in hearing 
your thoughts on this!


As far as I know, the destructor is only called (automatically by the 
GC). Since the Objective-C objects are not created using the GC the 
destructor will never be called. I don't think it's possible to 
implement reference counting (that would call retain/release) for 
classes in D, since it's not possible to overload the assignment 
operator for classes [2] or implement a postblit [3]. The only option, 
as far as I know, would be to wrap the class in a struct that calls 
retain/release automatically. But then you need to box/unbox the wrapped 
class constantly and all the method signatures would probably need to 
use this wrapper as well.


[1] 
https://github.com/jacob-carlborg/d_webkit_test/blob/master/source/foundation/util.d#L28


[2] https://dlang.org/spec/operatoroverloading.html#assignment
[3] https://dlang.org/spec/struct.html#struct-postblit

--
/Jacob Carlborg


Re: GUI program on Mac OS in D?

2017-12-13 Thread mrphobby via Digitalmars-d-learn
On Thursday, 23 November 2017 at 17:28:43 UTC, Jacob Carlborg 
wrote:
I have a simple example [2] of an application that shows a 
window with a WebKit view, i.e. and embedded browser. This 
works with the upstream DMD and LDC compilers. It basically 
only contains bindings for what I needed for that sample 
application. As you'll see there you need to use some parts of 
the Objective-C runtime to create class instances and 
subclasses. Also some gymnastics are required for class/static 
methods.


I have been taking a look at your example. Looks pretty neat! 
Some advanced mixin stuff there that looks pretty useful. 
However, as far as I can tell there is no handling of 
retain/release. How would you incorporate this into your mixin 
system without having to put "release" in all the interface 
definitions? Would it be possible to somehow hook this up 
automatically to the D destructor perhaps? Interested in hearing 
your thoughts on this!




Re: AssocArray to string is ok,but how to get the AssocArray from string? Thanks

2017-12-13 Thread Nicholas Wilson via Digitalmars-d-learn

On Tuesday, 12 December 2017 at 17:32:15 UTC, Frank Like wrote:

Hi,everyone,
who can help me,about the "AssocArray to string is ok,but how 
to get the AssocArray from string? ".


For example:

SysTime[][string] AATimes;
AATimes["a1"] =[SysTime(DateTime(2017, 1, 1, 12, 33, 
33)),SysTime(DateTime(2017, 1, 2, 12, 33, 33))];
AATimes["a2"] =[SysTime(DateTime(2017, 1, 2, 12, 33, 
33)),SysTime(DateTime(2017, 1, 3, 12, 33, 33))];


  ubyte[] ua = cast(ubyte[])AATimes.to!string;
  writeln("ua is ",ua);

  string strTimes = cast(string)ua;
   writeln("strTimes is ",strTimes);

But now,how to get the AATimes from string?

Thanks.

Frank.


Have a look at std.conv.parse




Re: What's the proper way to use std.getopt?

2017-12-13 Thread bauss via Digitalmars-d-learn
On Wednesday, 13 December 2017 at 07:37:17 UTC, Jonathan M Davis 
wrote:
On Wednesday, December 13, 2017 06:55:46 bauss via 
Digitalmars-d-learn wrote:

[...]


If it works, it's a bug related to code lowering (since scope 
statements are always lowered to try-catch-finally blocks). 
You're not supposed to have access to the exception in a scope 
statement.


- Jonathan M Davis


Yeah that's what I thought.

Just tested and it doesn't allow you to.


Re: Date Formating

2017-12-13 Thread codephantom via Digitalmars-d-learn
On Wednesday, 13 December 2017 at 07:35:40 UTC, Jonathan M Davis 
wrote:
In general, you probably want to cast the SysTime to a DateTime 
if you're going to do something like that.


yes, I would agree ;-)

Of course the intention was not really to just format it the same 
way as Clock.currTime() does it, but rather to provide a way to 
more easily customise the format, however one likes, whenever one 
likes..


e.g.the following small change to the format string would make it 
return: 20171213_1924_41


(that's more like something I'd use)

  return
format("%04s%02s%02s_%02s%02s_%02s",
(d.year),
to!(int)(d.month),
(d.day),
(d.hour),
(d.minute),
(d.second)
);