Re: Properties don't work as expected

2016-07-05 Thread ketmar via Digitalmars-d-learn
On Wednesday, 6 July 2016 at 05:51:04 UTC, Ola Fosheim Grøstad 
wrote:
Maybe you could give me an useful example in D that does not 
involve «static if» or «string mixins» that would be difficult 
to represent in C++?


anything involving templates. c++ template syntax is awful.


Re: Properties don't work as expected

2016-07-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 22:03:43 UTC, ketmar wrote:
On Tuesday, 5 July 2016 at 21:58:39 UTC, Ola Fosheim Grøstad 
wrote:

On Tuesday, 5 July 2016 at 21:46:19 UTC, ketmar wrote:

C++ templates vs D templates. this alone is enough.


They are almost the same...


yep. just like C is *almost* the assembler.


Maybe you could give me an useful example in D that does not 
involve «static if» or «string mixins» that would be difficult to 
represent in C++?




Re: AA with dynamic array value

2016-07-05 Thread Craig Dillabaugh via Digitalmars-d-learn

On Wednesday, 6 July 2016 at 02:33:02 UTC, ketmar wrote:
On Wednesday, 6 July 2016 at 02:19:47 UTC, Craig Dillabaugh 
wrote:

[...]


this is true for any dynamic array, including AAs. until 
something is added to array, it actually a `null` pointer. i.e. 
arrays (and AAs) generally consisting of pointer to data and 
some length/info field. while array is empty, pointer to data 
is `null`. and when you passing your dynamic array slice/AA to 
function, it makes a copy of those internal fields. reallocing 
`null` doesn't affect the original variable.


generally speaking, you should use `ref` if you plan to make 
your dynamic array/AA grow. i.e.


 void insertValue (ref int[][string]aa, string key, int value)


Thanks for giving me the correct solution, and for the 
explanation.


Cheers,
Craig


Re: AA with dynamic array value

2016-07-05 Thread ketmar via Digitalmars-d-learn

On Wednesday, 6 July 2016 at 02:19:47 UTC, Craig Dillabaugh wrote:
Why doesn't my function allow me to insert elements into an 
empty associative array, but succeeds for an AA with some 
element in it?


this is true for any dynamic array, including AAs. until 
something is added to array, it actually a `null` pointer. i.e. 
arrays (and AAs) generally consisting of pointer to data and some 
length/info field. while array is empty, pointer to data is 
`null`. and when you passing your dynamic array slice/AA to 
function, it makes a copy of those internal fields. reallocing 
`null` doesn't affect the original variable.


generally speaking, you should use `ref` if you plan to make your 
dynamic array/AA grow. i.e.


 void insertValue (ref int[][string]aa, string key, int value)


Re: AA with dynamic array value

2016-07-05 Thread Craig Dillabaugh via Digitalmars-d-learn

On Wednesday, 6 July 2016 at 02:03:54 UTC, Adam D. Ruppe wrote:
On Wednesday, 6 July 2016 at 01:58:31 UTC, Craig Dillabaugh 
wrote:

*(keyvalue) ~ value;   // This line fails.


That should prolly be ~= instead of ~.


Ahh, I was so close.  Thank you that seems to do the trick.

However, now I have another issue.

For the following main function:

int main( string[] args) {

int[][string] myAA;

//int[] tmp;
//tmp ~= 7;
//myAA["world"] = tmp;

insertValue( myAA, "hello", 1 );
insertValue( myAA, "goodbye", 2 );
insertValue( myAA, "hello", 3 );

foreach (k; myAA.keys.sort)
{
writefln("%3s %d", k, myAA[k].length);
}

return 0;
}

If I run this, it prints out nothing.  However, if I uncomment 
adding an element for 'world' then it prints (as expected):


goodbye 1
hello 2
world 1

Why doesn't my function allow me to insert elements into an empty 
associative array, but succeeds for an AA with some element in it?




Re: AA with dynamic array value

2016-07-05 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 6 July 2016 at 01:58:31 UTC, Craig Dillabaugh wrote:

*(keyvalue) ~ value;   // This line fails.


That should prolly be ~= instead of ~.




AA with dynamic array value

2016-07-05 Thread Craig Dillabaugh via Digitalmars-d-learn
How can I create (and update) and associative array where the key 
is a string, and the value is a dynamic array of integers?


For example:

void insertValue( int[][string]aa, string key, int value )
{
int[]* keyvalue;

keyvalue = ( key in aa );
if ( keyvalue !is null )
{
*(keyvalue) ~ value;   // This line fails.
}
else {
int[] tmp;
tmp ~= value;
aa[key] = tmp;
}
}


int main( string[] args) {

int[][string] myAA;

insertValue( myAA, "hello", 1 );
insertValue( myAA, "goodbye", 2 );
insertValue( myAA, "hello", 3 );

return 0;
}

Fails with:
...(16): Error: ~ has no effect in expression (*keyvalue ~ value)

Thanks for any help.



Re: How to get current time as long or ulong?

2016-07-05 Thread Charles Hixson via Digitalmars-d-learn
Thank you for confirming the change.  It hasn't made any difference 
during the tests so far, but it sounds like it soon would have.


I don't really want a long...but an int rolls over too quickly, and 
there's no 48 bit time.  The time is basically for use over smaller 
intervals, but occasionally I may need to compare across multiple 
months, or even years.  So the reason is because I want one time unit to 
have multiple uses.  It's going to end up being stored on disk, but 
order of access is going to frequently be important, and occasionally 
the relative age of quite different entities is going to be important.  
For the second use I could use a much lower precision timer, but that 
would mean using two separate times for each item.



On 07/05/2016 05:10 PM, Jonathan M Davis via Digitalmars-d-learn wrote:

On Tuesday, July 05, 2016 16:18:19 Charles Hixson via Digitalmars-d-learn
wrote:

I guess I was expressing myself poorly, probably due to muddled thinking
about the representation of time.

Based on various hints from you and others my current guess is that I
should use:

longnow() { returnClock.currTime().stdTime;}

IIUC this should return the current system clock time offset to start at
the start of 1 C.E. (with a standard systematic error that common across
all machines allowing for drift since the last time their clocks were
updated by NTP).  And that this is the supported way to get this time.
(Which is probably about the same as MonoTime.currTime(), but *is*
updated when NTP updates the system clock.)  And which is standardly a
64 bit number.

MonoTime and stdTime have _nothing_ to do with each other. stdTime is the
number of hecto-nanoseconds since midnight, January 1st, 1 A.D. MonoTime
contains a timestamp in system ticks, and how many of those there are per
second as well as how long ago 0 was are completely system-dependent.

The monotonic time is used for timing things not for anything related to the
wall clock. If what you care about is the wall clock, then use SysTime. If
what you care about is timing stuff, then use MonoTime.

I don't know why you'd want a long for the system time. There's nothing
standard about stdTime (which is why it's a horrible name, but
unfortunately, there really isn't a good name for it like there is with unix
time). SysTime exposes stdTime for the rare code that actually needs it, but
in general, code should either be using SysTime or converting SysTime to
the ISO or ISO extended formats, because those are standard. But you
certainly can store the stdTime somewhere if you want to.

- Jonathan M Davis






Re: How to get current time as long or ulong?

2016-07-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, July 05, 2016 12:51:54 Charles Hixson via Digitalmars-d-learn 
wrote:
> On 07/05/2016 11:43 AM, Jonathan M Davis via Digitalmars-d-learn wrote:
> > On Tuesday, July 05, 2016 11:16:31 Charles Hixson via Digitalmars-d-learn
> >
> > wrote:
> >> What I'm looking for is the opposite of the "FromUnixTime" function.
> >
> > SysTime has toUnixTime, which is right above fromUnixTime in the
> > documentation.
> >
> > But if what you want is a time_t, and you don't want to deal with SysTime,
> > there's no point in using std.datetime. Just use core.time to call C's
> > time
> > function.
> >
> > - Jonathan M Davis
>
> That's what I want, but I'm worried by the documentation saying:
> " This has no relation to the wall clock time, as the wall clock time
> can be adjusted (e.g. by NTP), whereas the monotonic clock always moves
> forward."
> What I want is the system clock time, which *is* adjusted by NTP.  I
> know it's not guaranteed monotonic, but different computers should have
> the same time (or be able to be synchronized to the same NTP time).  And
> it's "approximately monotonic".  time_t is fine, as 32 bit hardware is
> becoming scarce, and the application I'm working on will probably never
> encounter any.  (More than 32 bits of precision is required as I don't
> want it to roll over every 42.5 days.)
>
> I understand why some purposes would really want a monotonic time, but
> that's not a strong constraint for me.  But I do want it to be a long or
> ulong.  (I don't really care where 0 is.  What I'm using now is:
> aliaslongClockT;
> ClockTnow(){returnMonoTime.currTime();}
> And it's working fine during testing, but the documentation about the
> setting of MonoTime bothers me.

The Monotonic clock has nothing to do with the wall clock. It's giving the
number of system clock ticks which have occurred since some arbitrary time
that the system clock decided was 0, and the number of ticks per second is
completely system dependent. You wouldn't even want to share that number
between programs, let alone between runs of the same programe or between
computers. It's used for timing, not for knowing what time it is. e.g.

auto before = MonoTime.currTime;
// ... do a bunch of stuff
auto after = Monotime.currTime;

// The amount of time that that stuff took
auto diff = after - before;

It's the difference that becomes meaningful. The actual values of before and
after would be meaningless outside of this exact run of the program. What
makes the monotonic clock work for timing unlike the wall clock is that it
always moves forward by a fixed number of ticks per second. It's all about
timing and not at all about determing what time of day it is.

The wall clock time, on the other hand, is all about the time of day. It's
this particular hour, minute, second, etc. on this particular day of this
particular month of this particular year. And because the system's wall
clock time can be changed (be it because of NTP or someone manually changing
the time - or even because of a change in time zone if you're dealing with
the local time), it is not guaranteed to always move forward at a fixed
rate. It could change radically, which is why it does not work for timing.
It's all about knowing what time of day that something happened.

There really should never be a question of whether the monotonic time or the
wall clock time is appropriate. If you're ever asking that question, then
you almost certainly don't understand what they are.

If what you want is to time stuff (e.g. this happened x minutes into the run
of this program or this operation took y seconds), then you want the
monotonic time. If what you want is to know when something happens - i.e.
the time of day and/or date - then what you want is the wall clock time.
What you're using it for should make it obvious which you need.

But I would have to know more about what you're trying to do to have any
clue what you should be using. And I don't know why you would be so
interested in having the time as an integral value. That's usually a bad
idea. It's almost always better to use a time type that actually involves
units and context rather than a naked integral value.

- Jonathan M Davis



Re: How to get current time as long or ulong?

2016-07-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, July 05, 2016 16:18:19 Charles Hixson via Digitalmars-d-learn 
wrote:
> I guess I was expressing myself poorly, probably due to muddled thinking
> about the representation of time.
>
> Based on various hints from you and others my current guess is that I
> should use:
>
> longnow() { returnClock.currTime().stdTime;}
>
> IIUC this should return the current system clock time offset to start at
> the start of 1 C.E. (with a standard systematic error that common across
> all machines allowing for drift since the last time their clocks were
> updated by NTP).  And that this is the supported way to get this time.
> (Which is probably about the same as MonoTime.currTime(), but *is*
> updated when NTP updates the system clock.)  And which is standardly a
> 64 bit number.

MonoTime and stdTime have _nothing_ to do with each other. stdTime is the
number of hecto-nanoseconds since midnight, January 1st, 1 A.D. MonoTime
contains a timestamp in system ticks, and how many of those there are per
second as well as how long ago 0 was are completely system-dependent.

The monotonic time is used for timing things not for anything related to the
wall clock. If what you care about is the wall clock, then use SysTime. If
what you care about is timing stuff, then use MonoTime.

I don't know why you'd want a long for the system time. There's nothing
standard about stdTime (which is why it's a horrible name, but
unfortunately, there really isn't a good name for it like there is with unix
time). SysTime exposes stdTime for the rare code that actually needs it, but
in general, code should either be using SysTime or converting SysTime to
the ISO or ISO extended formats, because those are standard. But you
certainly can store the stdTime somewhere if you want to.

- Jonathan M Davis



Re: How to get current time as long or ulong?

2016-07-05 Thread Charles Hixson via Digitalmars-d-learn
I guess I was expressing myself poorly, probably due to muddled thinking 
about the representation of time.


Based on various hints from you and others my current guess is that I 
should use:


longnow() { returnClock.currTime().stdTime;}

IIUC this should return the current system clock time offset to start at 
the start of 1 C.E. (with a standard systematic error that common across 
all machines allowing for drift since the last time their clocks were 
updated by NTP).  And that this is the supported way to get this time.  
(Which is probably about the same as MonoTime.currTime(), but *is* 
updated when NTP updates the system clock.)  And which is standardly a 
64 bit number.



On 07/05/2016 11:53 AM, Jonathan M Davis via Digitalmars-d-learn wrote:

On Tuesday, July 05, 2016 11:43:32 Jonathan M Davis via Digitalmars-d-learn
wrote:

But if what you want is a time_t, and you don't want to deal with SysTime,
there's no point in using std.datetime. Just use core.time to call C's time
function.

Actually, I should qualify this. I keep forgetting that time_t is not
guaranteed to be unix time on non-POSIX systems. If what you want is time_t,
then use C's time function via core.time, but if what you want is actual
unix time, then just do Clock.currTime.toUnixTime, since that's the simplest
way to do it. If you're using Microsoft's runtime, then time_t is indeed
unix time, but it's not for the Digital Mars runtime (and the standard -
unfortunately - doesn't require it to be). Digital Mars uses someting that's
_close_ to time_t but isn't actually time_t. :(

- Jonathan M Davis






Re: Properties don't work as expected

2016-07-05 Thread ketmar via Digitalmars-d-learn
On Tuesday, 5 July 2016 at 21:58:39 UTC, Ola Fosheim Grøstad 
wrote:

On Tuesday, 5 July 2016 at 21:46:19 UTC, ketmar wrote:

C++ templates vs D templates. this alone is enough.


They are almost the same...


yep. just like C is *almost* the assembler.


Re: Properties don't work as expected

2016-07-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 21:46:19 UTC, ketmar wrote:

C++ templates vs D templates. this alone is enough.


They are almost the same...



Re: How to get current time as long or ulong?

2016-07-05 Thread Steven Schveighoffer via Digitalmars-d-learn

On 7/5/16 3:51 PM, Charles Hixson via Digitalmars-d-learn wrote:

On 07/05/2016 11:43 AM, Jonathan M Davis via Digitalmars-d-learn wrote:

On Tuesday, July 05, 2016 11:16:31 Charles Hixson via Digitalmars-d-learn
wrote:

What I'm looking for is the opposite of the "FromUnixTime" function.

SysTime has toUnixTime, which is right above fromUnixTime in the
documentation.

But if what you want is a time_t, and you don't want to deal with
SysTime,
there's no point in using std.datetime. Just use core.time to call C's
time
function.



That's what I want, but I'm worried by the documentation saying:
" This has no relation to the wall clock time, as the wall clock time
can be adjusted (e.g. by NTP), whereas the monotonic clock always moves
forward."


Clock.currTime.toUnixTime? 
https://dlang.org/library/std/datetime/clock.curr_time.html


SysTime is just a type. What you are looking at is documentation for 
clock sources, not the type. Clock should give you the wall time.


-Steve


Re: Properties don't work as expected

2016-07-05 Thread ketmar via Digitalmars-d-learn
On Tuesday, 5 July 2016 at 17:50:46 UTC, Ola Fosheim Grøstad 
wrote:

On Tuesday, 5 July 2016 at 16:20:52 UTC, ketmar wrote:
so, my PoV is: yes, D has it's warts, but they are much more 
tolerable than C++ warts, for example. and D has alot to offer 
which C++ simply won't be able to offer, ever.


D has «static if», but what else are you thinking of?


C++ templates vs D templates. this alone is enough.


Re: Asynchronous Programming and Eventhandling in D

2016-07-05 Thread Eugene Wissner via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 08:24:43 UTC, O/N/S wrote:

Hi ("Grüss Gott")

I like the asynchronous events in Javascript.
Is something similar possible in D?

Found Dragos Carp's asynchronous library 
(https://github.com/dcarp/asynchronous).
Are there any more integrated (in Phobos/in D) ways to work 
asynchronously?


An example: One server ask a second server to calculate 
something big.
The first server continues with his work, until the answer come 
back from the second.

And so on...

Using threads or fibers would be a way, but has not the same 
elegancy like the Javascript way. (To avoid discussions: D is 
better ;-)



Greetings from Munich,
Ozan

Servus,

I'm currently rewriting the base skeleton of libev in D (only for 
linux for now) for web development aswell. And the next step 
would be data structures, basic server, futures and yo on...
I was working with dcarp's asynchronous and i found it very very 
good. It is till now the best I've seen in D for async 
programming ( I mean its design and usability).


Can you describe what would you like to see more concretly. I 
know js but how is it supposed to work for D? Maybe you can give 
some example, kind of pseudo code? It would help me much to build 
a concept and maybe we will see someday something usable in this 
area :)




Re: webfreak001: Request assist installing workspace-d on Windows

2016-07-05 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 19:58:03 UTC, Andrew Edwards wrote:

On Tuesday, 5 July 2016 at 19:43:02 UTC, WebFreak001 wrote:

On Tuesday, 5 July 2016 at 19:34:48 UTC, Andrew Edwards wrote:


It's more than that. Now, it fails because it can't find DMD.


As you can see in the build.bat from DCD it is hardcoded to 
DMD: https://github.com/Hackerpilot/DCD/blob/master/build.bat




Maybe I should have been a little clearer. Following your 
instructions from earlier (skip DCD by selecting 2,3) the 
process failed again:


'dmd' is not recognized as an internal or external command,
operable program or batch file.
Error while compiling Dscanner.
Program exited with code 1

But if DCD doesn't compile with LDC, I don't think there is a 
way other than getting both DMD and LDC right now except if 
you are on linux.


It's not that LDC cannot compile DCD in this case, it's that 
your build script is searching for DMD when it cannot use DMD.


in the .bat you can try to replace "dmd" with "ldmd2". ldmd2 
allows to compile with LDC but with DMD command line interface. I 
can't guarantee that it gonna work but this is the simpliest 
option.


Re: webfreak001: Request assist installing workspace-d on Windows

2016-07-05 Thread WebFreak001 via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 19:58:03 UTC, Andrew Edwards wrote:

On Tuesday, 5 July 2016 at 19:43:02 UTC, WebFreak001 wrote:

On Tuesday, 5 July 2016 at 19:34:48 UTC, Andrew Edwards wrote:


It's more than that. Now, it fails because it can't find DMD.


As you can see in the build.bat from DCD it is hardcoded to 
DMD: https://github.com/Hackerpilot/DCD/blob/master/build.bat




Maybe I should have been a little clearer. Following your 
instructions from earlier (skip DCD by selecting 2,3) the 
process failed again:


'dmd' is not recognized as an internal or external command,
operable program or batch file.
Error while compiling Dscanner.
Program exited with code 1

But if DCD doesn't compile with LDC, I don't think there is a 
way other than getting both DMD and LDC right now except if 
you are on linux.


It's not that LDC cannot compile DCD in this case, it's that 
your build script is searching for DMD when it cannot use DMD.


Oh right it runs the build.bat from the Dscanner repository which 
is also hardcoded to DMD. So easiest way to build workspace-d 
right now is just getting DMD and LDC.


Re: webfreak001: Request assist installing workspace-d on Windows

2016-07-05 Thread Andrew Edwards via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 19:43:02 UTC, WebFreak001 wrote:

On Tuesday, 5 July 2016 at 19:34:48 UTC, Andrew Edwards wrote:


It's more than that. Now, it fails because it can't find DMD.


As you can see in the build.bat from DCD it is hardcoded to 
DMD: https://github.com/Hackerpilot/DCD/blob/master/build.bat




Maybe I should have been a little clearer. Following your 
instructions from earlier (skip DCD by selecting 2,3) the process 
failed again:


'dmd' is not recognized as an internal or external command,
operable program or batch file.
Error while compiling Dscanner.
Program exited with code 1

But if DCD doesn't compile with LDC, I don't think there is a 
way other than getting both DMD and LDC right now except if you 
are on linux.


It's not that LDC cannot compile DCD in this case, it's that your 
build script is searching for DMD when it cannot use DMD.




Re: How to get current time as long or ulong?

2016-07-05 Thread Charles Hixson via Digitalmars-d-learn

On 07/05/2016 11:43 AM, Jonathan M Davis via Digitalmars-d-learn wrote:

On Tuesday, July 05, 2016 11:16:31 Charles Hixson via Digitalmars-d-learn
wrote:

What I'm looking for is the opposite of the "FromUnixTime" function.

SysTime has toUnixTime, which is right above fromUnixTime in the
documentation.

But if what you want is a time_t, and you don't want to deal with SysTime,
there's no point in using std.datetime. Just use core.time to call C's time
function.

- Jonathan M Davis


That's what I want, but I'm worried by the documentation saying:
" This has no relation to the wall clock time, as the wall clock time 
can be adjusted (e.g. by NTP), whereas the monotonic clock always moves 
forward."
What I want is the system clock time, which *is* adjusted by NTP.  I 
know it's not guaranteed monotonic, but different computers should have 
the same time (or be able to be synchronized to the same NTP time).  And 
it's "approximately monotonic".  time_t is fine, as 32 bit hardware is 
becoming scarce, and the application I'm working on will probably never 
encounter any.  (More than 32 bits of precision is required as I don't 
want it to roll over every 42.5 days.)


I understand why some purposes would really want a monotonic time, but 
that's not a strong constraint for me.  But I do want it to be a long or 
ulong.  (I don't really care where 0 is.  What I'm using now is:

aliaslongClockT;
ClockTnow(){returnMonoTime.currTime();}
And it's working fine during testing, but the documentation about the 
setting of MonoTime bothers me.




Re: webfreak001: Request assist installing workspace-d on Windows

2016-07-05 Thread WebFreak001 via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 19:34:48 UTC, Andrew Edwards wrote:

On Tuesday, 5 July 2016 at 19:25:50 UTC, WebFreak001 wrote:

On Tuesday, 5 July 2016 at 19:14:32 UTC, Andrew Edwards wrote:


There is on --config=client for the current version of dub so 
I went to the location of the source for 
experimental_allocator and ran dub build --build=release 
--config=library instead, which generated the missing file. 
Problem is I don't know how to fix this in your build 
instructions so that the compellation will resume or continue 
to completion. Please assist.


It fails on installing DCD. On the installation.bat just 
select 2,3 and get prebuilt DCD binaries from the project page 
or build them yourself.




It's more than that. Now, it fails because it can't find DMD. 
Now, I see no reason to use both DMD and LDC. Ultimately I'd 
like to use DMD because it is the simplest to install for a 
newcomer but your workspace-d/code-d requires LDC on windows 
platforms. If that's the case why would it now be failing 
because it cannot find DMD?


As you can see in the build.bat from DCD it is hardcoded to DMD: 
https://github.com/Hackerpilot/DCD/blob/master/build.bat


So I guess you would need to use some DMD argument wrapper for 
LDC (ldmd) to compile it but I can't guarantee that it will work. 
Though if you have LDC v1.0.0 it should most probably work.


I would love to support DMD on workspace-d for windows but there 
is some bug in DMD's phobos causing workspace-d to hang every 
time you want to start the auto completion service. We found 
where it hangs but we couldn't find the cause or how to reproduce 
it yet. My best guess would be some win32 I/O functions are 
somehow wrongly used in there.


The LDC phobos version doesn't have any issue there.

But if DCD doesn't compile with LDC, I don't think there is a way 
other than getting both DMD and LDC right now except if you are 
on linux.


Re: webfreak001: Request assist installing workspace-d on Windows

2016-07-05 Thread Andrew Edwards via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 19:25:50 UTC, WebFreak001 wrote:

On Tuesday, 5 July 2016 at 19:14:32 UTC, Andrew Edwards wrote:


There is on --config=client for the current version of dub so 
I went to the location of the source for 
experimental_allocator and ran dub build --build=release 
--config=library instead, which generated the missing file. 
Problem is I don't know how to fix this in your build 
instructions so that the compellation will resume or continue 
to completion. Please assist.


It fails on installing DCD. On the installation.bat just select 
2,3 and get prebuilt DCD binaries from the project page or 
build them yourself.




It's more than that. Now, it fails because it can't find DMD. 
Now, I see no reason to use both DMD and LDC. Ultimately I'd like 
to use DMD because it is the simplest to install for a newcomer 
but your workspace-d/code-d requires LDC on windows platforms. If 
that's the case why would it now be failing because it cannot 
find DMD?


Re: webfreak001: Request assist installing workspace-d on Windows

2016-07-05 Thread WebFreak001 via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 19:14:32 UTC, Andrew Edwards wrote:

I cloned the package and ran install.bat.

The result is

$ dub build --build=release --config=client
Performing "release" build using ldc2 for x86.
experimental_allocator 2.70.0-b1: building configuration 
"library"...
Using Visual Studio: C:\Program Files (x86)\Microsoft Visual 
Studio 14.0\
LINK : fatal error LNK1104: cannot open file 
'..\..\..\..\Roaming\dub\packages\experimental_allocator-2.70.0-b1\experimental_allocator\.dub\build\library-release-windows-x86-ldc_0-341F845AB271E17D9C62794DCB77B6FB\experimental_allocator.lib'
Error: `C:\WINDOWS\system32\cmd.exe /s /c 
"C:\D\ldc2\bin\amd64.bat lib.exe"` failed with status: 1104

ldc2 failed with exit code 1104.
Error while compiling DCD.
Program exited with code 1

There is on --config=client for the current version of dub so I 
went to the location of the source for experimental_allocator 
and ran dub build --build=release --config=library instead, 
which generated the missing file. Problem is I don't know how 
to fix this in your build instructions so that the compellation 
will resume or continue to completion. Please assist.


Thanks,
Andrew


It fails on installing DCD. On the installation.bat just select 
2,3 and get prebuilt DCD binaries from the project page or build 
them yourself.


I could maybe add an option to compile from source and instead 
ship pre-built binaries from the github repositories instead.


Re: webfreak001: Request assist installing workspace-d on Windows

2016-07-05 Thread WebFreak001 via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 19:25:50 UTC, WebFreak001 wrote:

On Tuesday, 5 July 2016 at 19:14:32 UTC, Andrew Edwards wrote:

[...]


It fails on installing DCD. On the installation.bat just select 
2,3 and get prebuilt DCD binaries from the project page or 
build them yourself.


I could maybe add an option to compile from source and instead 
ship pre-built binaries from the github repositories instead.


Actually DCD doesn't have any pre-built binaries yet. But 
following the compilation guide on the project page¹ should help 
you compile it. Not sure if it works with LDC but it definitely 
works with DMD*


¹: https://github.com/Hackerpilot/DCD
*: assuming its the newest version


webfreak001: Request assist installing workspace-d on Windows

2016-07-05 Thread Andrew Edwards via Digitalmars-d-learn

I cloned the package and ran install.bat.

The result is

$ dub build --build=release --config=client
Performing "release" build using ldc2 for x86.
experimental_allocator 2.70.0-b1: building configuration 
"library"...
Using Visual Studio: C:\Program Files (x86)\Microsoft Visual 
Studio 14.0\
LINK : fatal error LNK1104: cannot open file 
'..\..\..\..\Roaming\dub\packages\experimental_allocator-2.70.0-b1\experimental_allocator\.dub\build\library-release-windows-x86-ldc_0-341F845AB271E17D9C62794DCB77B6FB\experimental_allocator.lib'
Error: `C:\WINDOWS\system32\cmd.exe /s /c 
"C:\D\ldc2\bin\amd64.bat lib.exe"` failed with status: 1104

ldc2 failed with exit code 1104.
Error while compiling DCD.
Program exited with code 1

There is on --config=client for the current version of dub so I 
went to the location of the source for experimental_allocator and 
ran dub build --build=release --config=library instead, which 
generated the missing file. Problem is I don't know how to fix 
this in your build instructions so that the compellation will 
resume or continue to completion. Please assist.


Thanks,
Andrew


Re: How to get current time as long or ulong?

2016-07-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, July 05, 2016 11:43:32 Jonathan M Davis via Digitalmars-d-learn 
wrote:
> But if what you want is a time_t, and you don't want to deal with SysTime,
> there's no point in using std.datetime. Just use core.time to call C's time
> function.

Actually, I should qualify this. I keep forgetting that time_t is not
guaranteed to be unix time on non-POSIX systems. If what you want is time_t,
then use C's time function via core.time, but if what you want is actual
unix time, then just do Clock.currTime.toUnixTime, since that's the simplest
way to do it. If you're using Microsoft's runtime, then time_t is indeed
unix time, but it's not for the Digital Mars runtime (and the standard -
unfortunately - doesn't require it to be). Digital Mars uses someting that's
_close_ to time_t but isn't actually time_t. :(

- Jonathan M Davis



Re: How to get current time as long or ulong?

2016-07-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, July 05, 2016 18:25:17 John via Digitalmars-d-learn wrote:
> On Tuesday, 5 July 2016 at 18:16:31 UTC, Charles Hixson wrote:
> > I've been reading std.datetime documentation backwards and
> > forwards, but if the information is there, I've been missing it.
> >
> > How do I get the current time as a long?
> >
> > Clock.currTime() returns a SysTime, and while currently I can
> > convert that to a long, this is because I looked into the code.
> > What's the supported way?  All the documentation seems to be
> > based around auto, which is great if you don't need to store it
> > in memory with a defined number of bits allocated...but lousy
> > if you do.   (E.g., I don't want to store a time zone, just the
> > UTC time.
> >
> > What I'm looking for is the opposite of the "FromUnixTime"
> > function.
>
> Clock.currTime.stdTime

That would give you the badly named "std" time and not "unix" time. "std"
time is what SysTime uses internally and is the number of hecto-nanoseconds
since midnight, January 1st, 1 A.D., whereas unix time is the number of
seconds since midnight, January 1st, 1970. What SysTime uses is essentially
the same thing that C# uses with its DateTime type with the poor name of
"ticks", whereas unix time is what you normally get with C - though
technically, if you're not on a POSIX system, there is no guarantee that
time_t is equivalent to unix time - it just usually is.

- Jonathan M Davis



Re: How to get current time as long or ulong?

2016-07-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, July 05, 2016 11:16:31 Charles Hixson via Digitalmars-d-learn 
wrote:
> What I'm looking for is the opposite of the "FromUnixTime" function.

SysTime has toUnixTime, which is right above fromUnixTime in the
documentation.

But if what you want is a time_t, and you don't want to deal with SysTime,
there's no point in using std.datetime. Just use core.time to call C's time
function.

- Jonathan M Davis



Re: How to get current time as long or ulong?

2016-07-05 Thread ag0aep6g via Digitalmars-d-learn

On 07/05/2016 08:16 PM, Charles Hixson via Digitalmars-d-learn wrote:

What I'm looking for is the opposite of the "FromUnixTime" function.


That would be the "toUnixTime" method then, I suppose.

https://dlang.org/phobos/std_datetime.html#.SysTime.toUnixTime


Re: How to get current time as long or ulong?

2016-07-05 Thread John via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 18:16:31 UTC, Charles Hixson wrote:
I've been reading std.datetime documentation backwards and 
forwards, but if the information is there, I've been missing it.


How do I get the current time as a long?

Clock.currTime() returns a SysTime, and while currently I can 
convert that to a long, this is because I looked into the code. 
What's the supported way?  All the documentation seems to be 
based around auto, which is great if you don't need to store it 
in memory with a defined number of bits allocated...but lousy 
if you do.   (E.g., I don't want to store a time zone, just the 
UTC time.


What I'm looking for is the opposite of the "FromUnixTime" 
function.


Clock.currTime.stdTime


How to get current time as long or ulong?

2016-07-05 Thread Charles Hixson via Digitalmars-d-learn
I've been reading std.datetime documentation backwards and forwards, but 
if the information is there, I've been missing it.


How do I get the current time as a long?

Clock.currTime() returns a SysTime, and while currently I can convert 
that to a long, this is because I looked into the code. What's the 
supported way?  All the documentation seems to be based around auto, 
which is great if you don't need to store it in memory with a defined 
number of bits allocated...but lousy if you do.   (E.g., I don't want to 
store a time zone, just the UTC time.


What I'm looking for is the opposite of the "FromUnixTime" function.



Re: Properties don't work as expected

2016-07-05 Thread Ola Fosheim Grøstad via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 16:20:52 UTC, ketmar wrote:
so, my PoV is: yes, D has it's warts, but they are much more 
tolerable than C++ warts, for example. and D has alot to offer 
which C++ simply won't be able to offer, ever.


D has «static if», but what else are you thinking of? The only 
thing I can think of that is hard in C++ is to conditionally 
remove fields from a struct.




Re: Properties don't work as expected

2016-07-05 Thread ketmar via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 16:11:58 UTC, zabruk70 wrote:

On Tuesday, 5 July 2016 at 10:52:10 UTC, zodd wrote:

Property functions are used wrong by a compiler when it needs


i am sorry for my dumbness, what wrong with this code?


as OP said, this one won't call setter on "+=" and company.


Re: Properties don't work as expected

2016-07-05 Thread ketmar via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 14:07:25 UTC, zodd wrote:

http://forum.dlang.org/post/mailman.1463.1361561853.22503.digitalmars-d-le...@puremagic.com
 : "Don't use 'in', because it doesn't mean what it seems to mean, and it's not 
correctly implemented at the moment."


it is freakin' 2013! ;-)


http://forum.dlang.org/post/lgqcjiuigsseoazir...@forum.dlang.org - "cast `shared` 
away. yes, this is how you supposed to use it now: cast it away."


yes, `shared` need some love. it actually never moved from the 
concept to something really useful. alas.



I don't want to say that "D is unfinished"


actually, it is unfinished. ;-) but it already has alot to offer.


I'm just trying to figure out what D is and how can I use it.


sorry for overreacting. that "D is crap" thread makes me... 
nervous. ;-)


Answering your other question: I think that production ready 
language should have a "finished" design and its detailed 
description (not a basic overview of the features).


Andrei's book is fairly detailed. And Ali's book is excellent 
too. it's hard to expect a small, but complete descrion for 
modern multiparadigm language. ;-)


so, my PoV is: yes, D has it's warts, but they are much more 
tolerable than C++ warts, for example. and D has alot to offer 
which C++ simply won't be able to offer, ever.


Re: Properties don't work as expected

2016-07-05 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 05, 2016 at 04:11:58PM +, zabruk70 via Digitalmars-d-learn 
wrote:
> On Tuesday, 5 July 2016 at 10:52:10 UTC, zodd wrote:
> > Property functions are used wrong by a compiler when it needs
> 
> i am sorry for my dumbness, what wrong with this code?
> 
> import std.stdio;
> 
> struct A {
> @property ref int value() {
> return value_;
> }
> 
> @property void value(int v) {
>   value_ = v;
> }

This overload is redundant, now that the first overload is ref.


> private:
>   int value_;
> }
[...]


T

-- 
He who does not appreciate the beauty of language is not worthy to bemoan its 
flaws.


Re: Properties don't work as expected

2016-07-05 Thread zabruk70 via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 10:52:10 UTC, zodd wrote:

Property functions are used wrong by a compiler when it needs


i am sorry for my dumbness, what wrong with this code?

import std.stdio;

struct A {
@property ref int value() {
return value_;
}

@property void value(int v) {
value_ = v;
}

private:
int value_;
}

int main(string[] args) {
A a;
a.value = 10;
writeln(a.value);
a.value += 20;
writeln(a.value);
return 0;
}



Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-05 Thread Johannes Loher via Digitalmars-d-learn
Am 05.07.2016 um 17:22 schrieb Marc Schütz:
> auto concat(T : E[n], E, size_t n)(const E[][] args...) @nogc
> {
> size_t offset = 0;
> T result = void;
> foreach(arr; args) {
> result[offset .. offset+arr.length] = arr;
> offset += arr.length;
> }
> assert(offset == result.length);
> return result;
> }
> 
> static immutable ubyte[4] sigma0 = [101, 120, 112,  97];
> static immutable ubyte[4] sigma1 = [110, 100,  32,  51];
> static immutable ubyte[4] sigma2 = [ 50,  45,  98, 121];
> static immutable ubyte[4] sigma3 = [116, 101,  32, 107];
> 
> void func(in ref ubyte[32] key, in ref ubyte[16] n) @nogc
> {
> ubyte[64] buf;
> buf[0..4] = sigma0;
> buf[4..20] = key[0..16];
> buf[20..24] = sigma1;
> buf[24..40] = n;
> buf[40..44] = sigma2;
> buf[44..60] = key[16..$];
> buf[60..64] = sigma3;
> 
> auto buf2 = concat!(ubyte[64])(sigma0, key[0..16], sigma1, n,
> sigma2, key[16..$], sigma3);
> 
> assert(buf == buf2);
> }
> 
> void main() {
> ubyte[32] key =
> [0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1];
> ubyte[16] n   = key[0..16];
> func(key, n);
> }
> 
> 
> Some remarks:
> 
> * I added `ref` to `func`'s parameters, because the arrays are
> relatively large, so passing them by value might be costly (you should
> measure it if you care).
> 
> * The `void` initialization in `concat` is an optimization that is valid
> only for POD types.
> 
> * Returning the array is cheap because of NRVO.

This seems to be exactly what I was looking for. Thanks a lot!



Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-05 Thread Johannes Loher via Digitalmars-d-learn
Am 05.07.2016 um 17:12 schrieb Johannes Loher:
> Am 05.07.2016 um 16:39 schrieb Rene Zwanenburg:
>> On Tuesday, 5 July 2016 at 12:34:20 UTC, Johannes Loher wrote:
>>> I tried this, but it does not work correctly with slices.
>>
>> The length of a slice is a runtime value, which is why it can't be used
>> to set static array size. What were you trying to achieve? Avoid copying
>> the input arrays, or accepting any slice?
>>
>> In case of the first, you can put ref in front of the Args:
>> auto combineArrays(Args...)(ref Args args)
>>
>> The second case will be a bit harder to solve nicely..
> 
> I would like to be able, to accept any slice. In the example in my first
> post, I need this for key[0..16] and key[16..$] (which are slices).
> Strangely enough, the solution I am leaning towards at the moment also
> uses length, but it does work for slices of static arrays (i.e. key[0..16]):
> 
> template expand(alias A)
> {
> auto ref M(alias I)() @property { return A[I]; }
> mixin(q{alias expand = TypeTuple!(}
> ~ iota(A.length).map!(a => "M!" ~ a.to!string).join(",")
> ~ q{);});
> }
> 
> ubyte[64] buf = [expand!sigma0,
>  expand!key[0..16],
>  expand!sigma1,
>  expand!n,
>  expand!sigma2,
>  expand!key[16..$],
>  expand!sigma3];
> 
> I suppose this is because the length of those slices is actually known
> at copiletime, but it looks a bit strange to me...
> 
> I was trying to write another template that takes several arrays and
> expands all of them:
> 
> template expand(Args...)
> {
> mixin(q{alias expand = TypeTuple!(}
> ~ iota(Args.length).map!(a => "expand!(Args[" ~ a.to!string ~
> "])").join(",")
> ~ q{);});
> }
> 
> It works for static arrays, but not for slices, because the template
> parameters are not alias parameters, so the length is then not "known"
> at compile time (at least that's what I think why it fails). Is there a
> way to specify variadic templates taking any number of alias template
> parameters?
> 

Well, I just realized my method does not work in the case that I want to
use expand on static arrays, which are returned from template functions...



Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-05 Thread Marc Schütz via Digitalmars-d-learn

auto concat(T : E[n], E, size_t n)(const E[][] args...) @nogc
{
size_t offset = 0;
T result = void;
foreach(arr; args) {
result[offset .. offset+arr.length] = arr;
offset += arr.length;
}
assert(offset == result.length);
return result;
}

static immutable ubyte[4] sigma0 = [101, 120, 112,  97];
static immutable ubyte[4] sigma1 = [110, 100,  32,  51];
static immutable ubyte[4] sigma2 = [ 50,  45,  98, 121];
static immutable ubyte[4] sigma3 = [116, 101,  32, 107];

void func(in ref ubyte[32] key, in ref ubyte[16] n) @nogc
{
ubyte[64] buf;
buf[0..4] = sigma0;
buf[4..20] = key[0..16];
buf[20..24] = sigma1;
buf[24..40] = n;
buf[40..44] = sigma2;
buf[44..60] = key[16..$];
buf[60..64] = sigma3;

auto buf2 = concat!(ubyte[64])(sigma0, key[0..16], sigma1, n, 
sigma2, key[16..$], sigma3);


assert(buf == buf2);
}

void main() {
ubyte[32] key = 
[0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1];

ubyte[16] n   = key[0..16];
func(key, n);
}


Some remarks:

* I added `ref` to `func`'s parameters, because the arrays are 
relatively large, so passing them by value might be costly (you 
should measure it if you care).


* The `void` initialization in `concat` is an optimization that 
is valid only for POD types.


* Returning the array is cheap because of NRVO.


Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-05 Thread Johannes Loher via Digitalmars-d-learn
Am 05.07.2016 um 16:39 schrieb Rene Zwanenburg:
> On Tuesday, 5 July 2016 at 12:34:20 UTC, Johannes Loher wrote:
>> I tried this, but it does not work correctly with slices.
> 
> The length of a slice is a runtime value, which is why it can't be used
> to set static array size. What were you trying to achieve? Avoid copying
> the input arrays, or accepting any slice?
> 
> In case of the first, you can put ref in front of the Args:
> auto combineArrays(Args...)(ref Args args)
> 
> The second case will be a bit harder to solve nicely..

I would like to be able, to accept any slice. In the example in my first
post, I need this for key[0..16] and key[16..$] (which are slices).
Strangely enough, the solution I am leaning towards at the moment also
uses length, but it does work for slices of static arrays (i.e. key[0..16]):

template expand(alias A)
{
auto ref M(alias I)() @property { return A[I]; }
mixin(q{alias expand = TypeTuple!(}
~ iota(A.length).map!(a => "M!" ~ a.to!string).join(",")
~ q{);});
}

ubyte[64] buf = [expand!sigma0,
 expand!key[0..16],
 expand!sigma1,
 expand!n,
 expand!sigma2,
 expand!key[16..$],
 expand!sigma3];

I suppose this is because the length of those slices is actually known
at copiletime, but it looks a bit strange to me...

I was trying to write another template that takes several arrays and
expands all of them:

template expand(Args...)
{
mixin(q{alias expand = TypeTuple!(}
~ iota(Args.length).map!(a => "expand!(Args[" ~ a.to!string ~
"])").join(",")
~ q{);});
}

It works for static arrays, but not for slices, because the template
parameters are not alias parameters, so the length is then not "known"
at compile time (at least that's what I think why it fails). Is there a
way to specify variadic templates taking any number of alias template
parameters?



Re: Dynamic arrays, emplace and GC

2016-07-05 Thread Rene Zwanenburg via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 13:48:46 UTC, Claude wrote:
Ah ok. I tried using void[size] static array and it seems to 
work without having to use GC.addRange().


Correct. void[] means the type of the data is unknown, so the GC 
has to assume it can contain pointers.


This also means that _everything_ in any void buffer has to be 
treated as a potential pointer. In other words, if you allocate a 
void buffer and fill it with ints, and one of those ints happens 
to have a value equal to the address of a GC-allocated object, 
the GC will assume the int is a pointer to that object and not 
free it.


Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-05 Thread Rene Zwanenburg via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 12:34:20 UTC, Johannes Loher wrote:

I tried this, but it does not work correctly with slices.


The length of a slice is a runtime value, which is why it can't 
be used to set static array size. What were you trying to 
achieve? Avoid copying the input arrays, or accepting any slice?


In case of the first, you can put ref in front of the Args:
auto combineArrays(Args...)(ref Args args)

The second case will be a bit harder to solve nicely..


Re: Possible bug

2016-07-05 Thread Jack Applegame via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 13:48:50 UTC, ag0aep6g wrote:
Something is also going wrong in dmd. There should be a 
deprecation message.

Exactly.


Re: Properties don't work as expected

2016-07-05 Thread zodd via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 13:37:50 UTC, ketmar wrote:
you *can* workaround this limitation for now. it won't be the 
cleanest code in the world, but you can do it. hint: alias this 
+ returning temporary struct with pointer.


Of course, I can. I have been creating a lot of such workarounds 
with C++ for years. And this is one of the flaws of C++ - for 
every simple task (like a delegate or properties) you need to 
create a workaround because C++ standardization Committee thinks 
that it shouldn't be a part of the language.




Re: Error: incompatible types for 'shared(SysTime)' and 'shared(SysTime)'

2016-07-05 Thread ag0aep6g via Digitalmars-d-learn

On 07/05/2016 07:25 AM, ketmar wrote:

cast `shared` away. yes, this is how you supposed to use it now: cast it
away.


after having ensured thread safety that is


Re: Properties don't work as expected

2016-07-05 Thread zodd via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 13:37:50 UTC, ketmar wrote:
if this minor thing blocks you from using D... alas. otherwise, 
just make a workaroung and keep going. *eventually* this will 
be fixed, but you'd better don't wait for it.


No, this issue doesn't block me from using D. I'm asking because 
I encountered with a few things (like this one), which seems like 
they're a bit "unfinished".

For example:
http://forum.dlang.org/post/mailman.1463.1361561853.22503.digitalmars-d-le...@puremagic.com
 : "Don't use 'in', because it doesn't mean what it seems to mean, and it's not 
correctly implemented at the moment."
http://forum.dlang.org/post/lgqcjiuigsseoazir...@forum.dlang.org 
- "cast `shared` away. yes, this is how you supposed to use it 
now: cast it away."


Reading topics like these doesn't add confidence. But don't get 
me wrong, I don't want to say that "D is unfinished" or "D has a 
bad design". I don't know it good enough to make such loud 
statements. I'm just trying to figure out what D is and how can I 
use it.


Answering your other question: I think that production ready 
language should have a "finished" design and its detailed 
description (not a basic overview of the features).




Re: Possible bug

2016-07-05 Thread ag0aep6g via Digitalmars-d-learn

On 07/05/2016 12:47 PM, Jack Applegame wrote:

ttt.d

import std.string;

void main() {
lastIndexOf("aa","bb");
}


rdmd ttt.d
compiles successfully without any errors or warnings


rdmd -dw ttt.d
compiles successfully without any errors or warnings

rdmd -de ttt.d

/usr/include/dmd/phobos/std/string.d(1239): Error: template
std.algorithm.searching.endsWith cannot deduce function from argument
types !((a, b) => std.uni.toLower(a) ==
std.uni.toLower(b))(const(char)[], const(char)[]), candidates are:

[...]

There sure is at least one bug. I guess this has to do with recent 
changes to symbol lookup/visibility rules.


On the line from the error message there are fully qualified references 
to std.uni.toLower, but std.uni isn't imported as a module. This can 
easily be fixed in phobos. I've filed an issue:

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

Something is also going wrong in dmd. There should be a deprecation message.


Re: Dynamic arrays, emplace and GC

2016-07-05 Thread Claude via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 12:43:14 UTC, ketmar wrote:

On Tuesday, 5 July 2016 at 10:04:05 UTC, Claude wrote:

So here's my question: Is it normal???


yes. `ubyte` arrays by definition cannot hold pointers, so GC 
doesn't bother to scan 'em.


Ah ok. I tried using void[size] static array and it seems to work 
without having to use GC.addRange().


Re: Properties don't work as expected

2016-07-05 Thread ketmar via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 13:14:29 UTC, zodd wrote:

Why do you have so pessimistic opinion?


it is realistic.

Is D a perspective language to learn or it's stagnating and 
never be production ready?


what do you want here: "non-stagnating" or "production ready"? D 
is "production ready", and that means that D should be STABLE. we 
can't introduce features just 'cause they are cool. we can't even 
change the features without long and hard discussion. if we'll 
finalize property specs, we'll stick with it forever. and devs 
have many other things to do too, most of it for free and in 
their spare time. that's why finalizing properties is postponed, 
for undefined time.


you *can* workaround this limitation for now. it won't be the 
cleanest code in the world, but you can do it. hint: alias this + 
returning temporary struct with pointer.


and, of course, you can hire Walter or Andrei on a full time to 
implement the feature you want. otherwise -- this is minor thing, 
which, nevertheless, require a huge amout of design work. it is 
unlikely that language devs will drop all other things, and go 
design and implementing it. and DIP will not help much: W&A still 
should evaluate it, and it's almost as hard as writing it from 
scratch.


if this minor thing blocks you from using D... alas. otherwise, 
just make a workaroung and keep going. *eventually* this will be 
fixed, but you'd better don't wait for it.


Re: Properties don't work as expected

2016-07-05 Thread Steven Schveighoffer via Digitalmars-d-learn

On 7/5/16 6:52 AM, zodd wrote:


Is there a chance, that this weird behavior will be fixed in the near
future? What can I do to help fix it?


Properties do not support read-modify-write operations. You can return a 
reference, or return a wrapper type to enable the operations you want.


D does not support any of the normally-expected property rewrites that 
many languages do.


For example: a.b.c = 5 where b is a property may not do what you expect.

It has been suggested in the past to have this behavior, but I doubt it 
will happen. It's possible to write such mechanisms as a library, but 
I've never seen someone do it.


-Steve


Re: Properties don't work as expected

2016-07-05 Thread Leandro Motta Barros via Digitalmars-d-learn
D is being used productively by some companies, so I guess we can call it
production-ready. This doesn't meant there are not rough corners. The
language is being actively developed, and I see that some work is being
done on those rough corners. However, keep in mind that:

1) Maybe what you perceive as a strong deficiency isn't seen as a top
priority for the D developers. This issue with properties, for instance, is
annoying (I agree with you!), but most of the time (if not ever) it can be
easily circumvented (as Satoshi has shown).

2) Sometimes, changing language features have subtle side effects, and the
devs must take everything into account. A fix that looks obvious for us
mere mortals can actually open a can of worms and introduce many new issues.

Hope this answers your quesiton,

LMB


On Tue, Jul 5, 2016 at 10:14 AM, zodd via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> On Tuesday, 5 July 2016 at 12:45:33 UTC, ketmar wrote:
>
>> Is there a chance, that this weird behavior will be fixed in the near
>>> future? What can I do to help fix it?
>>>
>>
>> almost as much as you can expect snowfall in hell.
>>
>
> Why do you have so pessimistic opinion? Is D a perspective language to
> learn or it's stagnating and never be production ready?
>


Re: Implementing a cache

2016-07-05 Thread Steven Schveighoffer via Digitalmars-d-learn

On 7/2/16 8:10 AM, qznc wrote:

I want to implement some caching for HTTP GET requests. Basically a map
of URL to content. A cache needs some additional meta data (size, age,
etc).

There seem to be two basic data structures available: Associative array
(AA) or red black tree (RBT).

With AA cache eviction is inefficient. It requires to sort the keys of
the AA with respect to a field in the value. Stack overflow says "use
RBT instead" [0].

With RBT retrieving something is inefficient. To get an entry, we need
to create an fake entry with the key> and get a range of entries 'equal'
to the fake one?


Yes, it is annoying to have to deal with creating a fake element. In 
dcollections, I have a TreeMap wrapper which does this for you: 
https://github.com/schveiguy/dcollections/blob/master/dcollections/TreeMap.d#L881


We should probably add support for the searching functions that allows 
parameters other than full elements if the element supports comparison 
with that type.


In terms of using equalRange, it should be pretty efficient. If you are 
allowing duplicates, then it does 2 binary searches (one for the 
beginning node and one for the end). If no duplicates, one binary 
search, and the equalRange will be 0 or 1 element (depending on if the 
key is present).



Or can I exploit some "find on sorted range" algorithm
somewhere?


There is find on sorted range support in std.algorithm, but it must be a 
random-access range. RBTree range is not RA. What's wrong with the 
binary search support in the tree itself?


-Steve


Re: Properties don't work as expected

2016-07-05 Thread zodd via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 12:45:33 UTC, ketmar wrote:
Is there a chance, that this weird behavior will be fixed in 
the near future? What can I do to help fix it?


almost as much as you can expect snowfall in hell.


Why do you have so pessimistic opinion? Is D a perspective 
language to learn or it's stagnating and never be production 
ready?


Re: Properties don't work as expected

2016-07-05 Thread ketmar via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 10:52:10 UTC, zodd wrote:
It's a very inconvenient. Why don't just call a getter and then 
a setter functions in such cases?


'cause property specs aren't even finalized yet.

Is there a chance, that this weird behavior will be fixed in 
the near future? What can I do to help fix it?


almost as much as you can expect snowfall in hell.


Re: Dynamic arrays, emplace and GC

2016-07-05 Thread ketmar via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 10:04:05 UTC, Claude wrote:

So here's my question: Is it normal???


yes. `ubyte` arrays by definition cannot hold pointers, so GC 
doesn't bother to scan 'em.


Re: Initializing static array with contents of (static and dynamic) arrays

2016-07-05 Thread Johannes Loher via Digitalmars-d-learn
Am 05.07.2016 um 00:41 schrieb Rene Zwanenburg:
> On Monday, 4 July 2016 at 19:22:52 UTC, Johannes Loher wrote:
>> This looks really nice, but I have several occurences of this, with
>> different arrays (and lengths), so i would need to create several of
>> those structs. But it looks really clean :)
> 
> You can use a template to remove the boilerplate. Here's a quick example:
> 
> https://dpaste.dzfl.pl/43b379992648

I tried this, but it does not work correctly with slices.


Re: Probably trivial Linux link problem that I've spent hours on.

2016-07-05 Thread Johannes Pfau via Digitalmars-d-learn
Am Tue, 5 Jul 2016 00:37:54 -0700
schrieb Ali Çehreli :

> On 07/04/2016 08:32 PM, WhatMeWorry wrote:
> 
>  > /usr/bin/ld: cannot find -lsqlite3
>  > collect2: error: ld returned 1 exit status  
> 
> I had the same issue when building Button with dub on Ubuntu 16.04.
> My hack was to create the following symlink to the already existing 
> libsqlite3.so.0:
> 
>sudo ln -s /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 
> /usr/lib/x86_64-linux-gnu/libsqlite3.so
> 
> Ali
> 

Some time ago Debian (and therefore Ubuntu as well) moved the
unversioned .so symlinks into the -dev packages. This means you'll
always need the -dev packages now when linking with a C library, even if
you only use the dynamic library.



Re: Properties don't work as expected

2016-07-05 Thread zodd via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 11:02:11 UTC, Satoshi wrote:

On Tuesday, 5 July 2016 at 10:52:10 UTC, zodd wrote:
Property functions are used wrong by a compiler when it needs 
to get and set a value at the same time:


[...]




Try
 @property ref int value() {
return value_;
}


What if I need a setter function? I would never bother with 
properties and just used the field itself otherwise.


Re: Properties don't work as expected

2016-07-05 Thread Satoshi via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 10:52:10 UTC, zodd wrote:
Property functions are used wrong by a compiler when it needs 
to get and set a value at the same time:


[...]




Try
 @property ref int value() {
return value_;
}


Properties don't work as expected

2016-07-05 Thread zodd via Digitalmars-d-learn
Property functions are used wrong by a compiler when it needs to 
get and set a value at the same time:


import std.stdio;

struct A {
@property int value() const {
return value_;
}

@property ref int value(int v) {
value_ = v;
return value_;
}

private:
int value_;
}

int main(string[] args) {
A a;
a.value += 20; // < Error: a.value() is not an lvalue
return 0;
}


It's a very inconvenient. Why don't just call a getter and then a 
setter functions in such cases?
I found the D language specification and it doesn't bother to 
explain how properties should behave in such cases. Is there a 
full language specification somewhere?
Also, I've googled a little and found a similar topic from 2012 
(http://forum.dlang.org/thread/srhwzxgpiqucknche...@forum.dlang.org). So, since 2012 nobody cared about it? What a shame!
Even a D Wiki page with properties discussion 
(https://wiki.dlang.org/Property_Discussion_Wrap-up) gives an 
example of property usage, which can't be compiled by the latest 
version of dmd:


a.weeks++;
a.weeks -=2;

Is there a chance, that this weird behavior will be fixed in the 
near future? What can I do to help fix it?


Possible bug

2016-07-05 Thread Jack Applegame via Digitalmars-d-learn

ttt.d

import std.string;

void main() {
lastIndexOf("aa","bb");
}


rdmd ttt.d
compiles successfully without any errors or warnings


rdmd -dw ttt.d
compiles successfully without any errors or warnings

rdmd -de ttt.d
/usr/include/dmd/phobos/std/string.d(1239): Error: template 
std.algorithm.searching.endsWith cannot deduce function from 
argument types !((a, b) => std.uni.toLower(a) == 
std.uni.toLower(b))(const(char)[], const(char)[]), candidates 
are:
/usr/include/dmd/phobos/std/algorithm/searching.d(981): 
std.algorithm.searching.endsWith(alias pred = "a == b", Range, 
Needles...)(Range doesThisEnd, Needles withOneOfThese) if 
(isBidirectionalRange!Range && Needles.length > 1 && 
is(typeof(.endsWith!pred(doesThisEnd, withOneOfThese[0])) : 
bool) && is(typeof(.endsWith!pred(doesThisEnd, 
withOneOfThese[1..__dollar])) : uint))
/usr/include/dmd/phobos/std/algorithm/searching.d(1048): 
std.algorithm.searching.endsWith(alias pred = "a == b", R1, 
R2)(R1 doesThisEnd, R2 withThis) if (isBidirectionalRange!R1 && 
isBidirectionalRange!R2 && 
is(typeof(binaryFun!pred(doesThisEnd.back, withThis.back)) : 
bool))
/usr/include/dmd/phobos/std/algorithm/searching.d(1076): 
std.algorithm.searching.endsWith(alias pred = "a == b", R, E)(R 
doesThisEnd, E withThis) if (isBidirectionalRange!R && 
is(typeof(binaryFun!pred(doesThisEnd.back, withThis)) : bool))
/usr/include/dmd/phobos/std/algorithm/searching.d(1086): 
std.algorithm.searching.endsWith(alias pred, R)(R doesThisEnd) 
if (isInputRange!R && ifTestable!(typeof(doesThisEnd.front), 
unaryFun!pred))
ttt.d(4): Error: template instance 
std.string.lastIndexOf!(char, char) error instantiating


Dynamic arrays, emplace and GC

2016-07-05 Thread Claude via Digitalmars-d-learn

Hello,

I've been working on some kind of allocator using a dynamic array 
as a memory pool. I used emplace to allocate class instances 
within that array, and I was surprised to see I had to use 
GC.addRange() to avoid the GC to destroy stuff referenced in that 
array.


Here's a chunk of code[1]:

struct Pool(T)
{
public:
T alloc(Args...)(Args args)
{
mData.length++;
import core.memory : GC;
//GC.addRange(mData[$ - 1].data.ptr, mData[$ - 
1].data.length);

import std.conv : emplace;
auto t = emplace!T(mData[$ - 1].data, args);
return t;
}

private:
struct Storage
{
ubyte[__traits(classInstanceSize, T)] data;
}

Storage[] mData;
}

class Foo
{
this(int a)
{
aa = a;
}
~this()
{
import std.stdio; writefln("DTOR");
aa = 0;
}
int aa;
}

class Blob
{
this(int b)
{
foo = new Foo(b);
}

Foo foo;
}

void main()
{
Pool!Blob pool;

Blob blob;
foreach(a; 0 .. 1)
{
blob = pool.alloc(6);
}
while(true){}
import std.stdio; writefln("END");
}

Basically Blob instances are allocated in the array using 
emplace. And Blob creates references to Foo. If I comment out 
GC.addRange(), I see that Foo destructor is called by the GC[2]. 
If I leave it uncommented, the GC leaves the array alone.


So here's my question: Is it normal???
I thought that allocating memory in a dynamic array using 
"mData.length++;" was GC-compliant (unlike 
core.stdc.stdlib.malloc()), and I did not have to explictly use 
GC.addRange().



[1] I left out alignment management code. It's not the issue here.
[2] I used the helpful destructor tracker function of p0nce 
there: https://p0nce.github.io/d-idioms/#GC-proof-resource-class


Re: Asynchronous Programming and Eventhandling in D

2016-07-05 Thread chmike via Digitalmars-d-learn

Hello, It looks interesting.

This is now my current list of asynchronous libraries written in 
D (not a C lib wrapper).


Collie : https://github.com/putao-dev/collie
libasync : https://github.com/etcimon/libasync
eventcore : https://github.com/vibe-d/eventcore
asynchronous: https://github.com/dcarp/asynchronous

A benchmarking test suite is still missing. We need a reference 
to compare performance of the libraries.


Re: Most elegant way for split array of struct into components

2016-07-05 Thread Ali Çehreli via Digitalmars-d-learn

On 07/05/2016 01:10 AM, Miguel L wrote:

> could it be possible to implement some class or
> struct method that works on an array of objects of that class or method?
>
> class A
> {
> void Y(A[] a){...}
> }
>
> A[] array;
> array.Y();
>

Yes, but that normally belongs outside the type. Luckily, D's UFCS 
feauter lets one call a non-member function as if it's a member function:


import std.stdio;
import std.algorithm;
import std.range;

class A {
int i;
this(int i) {
this.i = i;
}
}

// Not a member:
void Y(A[] a){
foreach (e; a) {
writefln("working with %s", e.i);
}
}

void main() {
A[] array = iota(5).map!(i => new A(i)).array;

// Can be called like a member:
array.Y();
}

Still, it's debatable whether an array-processing functions should be 
executed with the member function syntax. I would write Y(array). When 
you discover the ranges, you will realize that instead of defining 
functions like Y that contain explicit loops, combining functions that 
work with just a single A is more maintainable, scalable, and almost 
always faster (sometimes you won't need to hold actual arrays of anything).


void y(A a) {
writefln("working with %s", a.i);
}

void main() {
// Objects are created but not a single array is in sight:
iota(5)
.map!(i => new A(i))
.each!y;
}

The output is the same:

working with 0
working with 1
working with 2
working with 3
working with 4

Ali



Asynchronous Programming and Eventhandling in D

2016-07-05 Thread O/N/S via Digitalmars-d-learn

Hi ("Grüss Gott")

I like the asynchronous events in Javascript.
Is something similar possible in D?

Found Dragos Carp's asynchronous library 
(https://github.com/dcarp/asynchronous).
Are there any more integrated (in Phobos/in D) ways to work 
asynchronously?


An example: One server ask a second server to calculate something 
big.
The first server continues with his work, until the answer come 
back from the second.

And so on...

Using threads or fibers would be a way, but has not the same 
elegancy like the Javascript way. (To avoid discussions: D is 
better ;-)



Greetings from Munich,
Ozan




Re: Most elegant way for split array of struct into components

2016-07-05 Thread Miguel L via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 07:33:40 UTC, Ali Çehreli wrote:

On 07/04/2016 11:07 PM, Miguel L wrote:

> [...]

> [...]
my_array?

The simplest is to pick the element by std.algorithm.map:

[...]


Thank you Ali, that works.
On the same subject, could it be possible to implement some class 
or struct method that works on an array of objects of that class 
or method?


class A
{
void Y(A[] a){...}
}

A[] array;
array.Y();

Sorry for my ignorance, i am just starting to work in D.


Re: Probably trivial Linux link problem that I've spent hours on.

2016-07-05 Thread Ali Çehreli via Digitalmars-d-learn

On 07/04/2016 08:32 PM, WhatMeWorry wrote:

> /usr/bin/ld: cannot find -lsqlite3
> collect2: error: ld returned 1 exit status

I had the same issue when building Button with dub on Ubuntu 16.04. My 
hack was to create the following symlink to the already existing 
libsqlite3.so.0:


  sudo ln -s /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 
/usr/lib/x86_64-linux-gnu/libsqlite3.so


Ali



Re: Most elegant way for split array of struct into components

2016-07-05 Thread Ali Çehreli via Digitalmars-d-learn

On 07/04/2016 11:07 PM, Miguel L wrote:

> struct A
> {
> int x;
> int y;
> }

> would be the best way to get an array of x or y component of my_array?

The simplest is to pick the element by std.algorithm.map:

import std.stdio;
import std.range;
import std.array;
import std.algorithm;

struct A {
int x;
int y;
}

void main() {
A[] my_array = iota(3)
   .map!(i => A(i, 11 * i))
   .array;

writeln("The whole array:");
writeln(my_array);

writeln("Just the x members");
auto xs = my_array.map!(a => a.x);
writeln(xs);

writeln("Just the y members");
auto ys = my_array.map!(a => a.y);
writeln(ys);
}

Prints

The whole array:
[A(0, 0), A(1, 11), A(2, 22)]
Just the x members
[0, 1, 2]
Just the y members
[0, 11, 22]

map has a shortcut: If there is a function foo that takes A, then you 
can do just this:


writeln(my_array.map!foo);

(foo can be a member function or a non-member function.)

With the great risk of polluting the namespace, here is a draft of 
creating non-member accessor functions automatically:


string memberAccessors(T)() {
import std.string;
string accessors;

foreach(m; __traits(allMembers, T)) {
accessors ~= format("auto %s(%s a) { return a.%s; }\n", m, 
T.stringof, m);

}

return accessors;
}

mixin(memberAccessors!A);

That generates and mixes in accessor functions for each member. A 
pragma(msg) can show what is generated:


pragma(msg, memberAccessors!A);

Prints at compile time:

auto x(A a) { return a.x; }
auto y(A a) { return a.y; }

(Crazy idea. :) )

But then, it's as simple as the following:

writeln(my_array.map!y);

Ali



Re: Probably trivial Linux link problem that I've spent hours on.

2016-07-05 Thread Andrea Fontana via Digitalmars-d-learn

On Tuesday, 5 July 2016 at 03:32:25 UTC, WhatMeWorry wrote:
Just learning Linux. Got my first vibe/dub project which dies 
at:


Compiling diet template 'index.dt'...
Linking...
/usr/bin/ld: cannot find -lsqlite3
collect2: error: ld returned 1 exit status


I downloaded DUB's d2sqlite3 and built it fine.
I've got sqlite3 on my system by default (came with Xununtu) I


You need *-dev package probabily. Something like:

sudo apt-get install libsqlite3-dev

Andrea