Re: Getting the current datetime converted into a string for writing to stdout

2014-03-31 Thread Jonathan M Davis
On Sunday, March 30, 2014 08:25:42 Andre Artus wrote:
 Considering the international spread of D users I find it
 surprising that the date  time formatting functions in phobos
 are not localizable.

If could go back, there wouldn't even be anything to localize. toSimpleString 
is there because it was in Boost (and it's what toString uses), but by having 
_three_ different string functions for each type instead of just ISO and ISO 
Extended. So, that's arguably bad - certainly it overcomplicates things IMHO. 
And toSimpleString uses English names for the months which is _definitely_ 
bad, because it opens up the question of localization, which I see no reason 
to deal with in this context, especially because it opens up a huge can of 
worms. By sticking to ISO and ISO Extended, we'd be completely standards 
compliant and would avoid the whole localization issue entirely. As it stands, 
we just acknowledge that it's stupid that toSimpleString is there (thereby 
introducing the question of localization) and have agreed that localization is 
outside the scope of std.datetime.

Unfortunately, removing toSimpleString would obviously break code, and 
changing toString to do the same as toISOExtString (as it probably should) 
could also break code if there's code in the wild which relies on the exact 
format of toString. So, we're kind of stuck.

- Jonathan M Davis


Re: best D equivalent to C'stimeval

2014-03-31 Thread Jonathan M Davis
On Monday, March 31, 2014 05:09:22 ed wrote:
 Hi,
 
 Just wondering what the best replacement for C timeval is in D.
 I'm looking at std.datetime.SysTime, but std.datetime is huge so
 I'm not sure.

If you want an overview of std.datetime, read

http://dlang.org/intro-to-datetime.html

But yes, SysTime would be what you'd want to use instead of a timeval. SysTime 
is intended for representing the time of the system, whereas DateTime, Date, 
or TimeOfDay relate to specifically to calendar time (they have no time zones 
and therefore cannot be tied to a unique point in time - e.g. a DateTime for 
2014-03-30T12:00:00 could be one of over 24 different points in time, as it 
has no time zone to tie it down). SysTime holds its time internally in UTC and 
uses a TimeZone object to convert to to other time zones when required (e.g. 
when printing it out); it defaults to LocalTime, which represents the local 
time of your system.

SysTime also has a function called toTimeVal for converting to a timeval if 
you need to pass it to C code.

- Jonathan M Davis


Re: best D equivalent to C'stimeval

2014-03-31 Thread ed

On Monday, 31 March 2014 at 06:25:40 UTC, Jonathan M Davis wrote:

On Monday, March 31, 2014 05:09:22 ed wrote:

Hi,

Just wondering what the best replacement for C timeval is in D.
I'm looking at std.datetime.SysTime, but std.datetime is huge 
so

I'm not sure.


If you want an overview of std.datetime, read

http://dlang.org/intro-to-datetime.html

But yes, SysTime would be what you'd want to use instead of a 
timeval. SysTime
is intended for representing the time of the system, whereas 
DateTime, Date,
or TimeOfDay relate to specifically to calendar time (they have 
no time zones
and therefore cannot be tied to a unique point in time - e.g. a 
DateTime for
2014-03-30T12:00:00 could be one of over 24 different points in 
time, as it
has no time zone to tie it down). SysTime holds its time 
internally in UTC and
uses a TimeZone object to convert to to other time zones when 
required (e.g.
when printing it out); it defaults to LocalTime, which 
represents the local

time of your system.

SysTime also has a function called toTimeVal for converting to 
a timeval if

you need to pass it to C code.

- Jonathan M Davis


Great info, thank you.


Cheers,
ed


CTFE error, but I have no idea what it means.

2014-03-31 Thread Olav Lindekleiv
I've been experimenting with D for a little while now. For the 
most part, I've been able get help from the language/library 
reference and IRC. But not this time.


So here's the thing: http://dpaste.dzfl.pl/14680a8cec77

I've run it through Dustmite to reduce it to a smaller chunk of 
code. It runs just fine at runtime, but once I try to run 
parseTemplate during compile time/CTFE, it fails with this 
error:


/d815/f521.d(37): called from here: this.parser.parse() 
/d815/f521.d(77): called from here: parseTemplate(child2.html, 
genFileTable()) dmd: statement.c:293: 
ErrorStatement::ErrorStatement(): Assertion `global.gaggedErrors 
|| global.errors' failed.


Usually when running into CTFE limitations, I've been able to 
understand what I'm doing wrong from the error messages, but this 
one doesn't make any sense to me.


I hope someone with more D experience can tell me what's going on 
here, and how to fix it.


Thanks,
Olav.


Re: CTFE error, but I have no idea what it means.

2014-03-31 Thread bearophile

Olav Lindekleiv:

I hope someone with more D experience can tell me what's going 
on here, and how to fix it.


It's a compiler bug. I suggest to minimize manually the example 
code as much as possible, and then add it to Bugzilla.


Bye,
bearophile


Re: CTFE error, but I have no idea what it means.

2014-03-31 Thread Olav Lindekleiv

On Monday, 31 March 2014 at 11:02:24 UTC, bearophile wrote:

Olav Lindekleiv:

I hope someone with more D experience can tell me what's going 
on here, and how to fix it.


It's a compiler bug. I suggest to minimize manually the example 
code as much as possible, and then add it to Bugzilla.


Bye,
bearophile


I'm now down to 13 lines: http://dpaste.dzfl.pl/bbc84226a558

And it's the while(){} that causes the compiler to crash. It 
isn't just , but any string. I'll create an issue on Bugzilla 
for this.


Re: CTFE error, but I have no idea what it means.

2014-03-31 Thread Olav Lindekleiv
Here's the issue: 
http://d.puremagic.com/issues/show_bug.cgi?id=12498


Please ignore the last example above, and look at the one in 
Bugzilla.


On Monday, 31 March 2014 at 11:08:18 UTC, Olav Lindekleiv wrote:

On Monday, 31 March 2014 at 11:02:24 UTC, bearophile wrote:

Olav Lindekleiv:

I hope someone with more D experience can tell me what's 
going on here, and how to fix it.


It's a compiler bug. I suggest to minimize manually the 
example code as much as possible, and then add it to Bugzilla.


Bye,
bearophile


I'm now down to 13 lines: http://dpaste.dzfl.pl/bbc84226a558

And it's the while(){} that causes the compiler to crash. It 
isn't just , but any string. I'll create an issue on Bugzilla 
for this.




Re: Does anyone have an example of use of core.sync.Condition

2014-03-31 Thread Steven Schveighoffer

On Sun, 30 Mar 2014 12:09:35 -0400, Matt webwra...@fastmail.fm wrote:

I have little experience in multi-threading programming, and was digging  
into std.concurrency, but I don't really understand the Condition class  
as it was used there. Could someone provide a bare-bones use of this  
class? I would be much obliged, thanks.


Google thread condition variable. It's a very well-known pattern.

-Steve


Re: Avoiding Range Checks in Slice Expressions

2014-03-31 Thread Steven Schveighoffer

On Sun, 30 Mar 2014 15:40:43 -0400, Nordlöw per.nord...@gmail.com wrote:


Does DMD currently avoid range checks in array slice expressions such as

f(x[0..$/2])
f(x[$/2..$])

typically found in divide-and-conquer algorithms such as quicksort?


If they are range-checked, it would be a good addition to the optimizer to  
remove them. My guess is that it is range-checked.



If not, what would it require to implement it?


As a hack, you can use the pointer, which will not be range checked:

f(x.ptr[0..x.length/2]) // note you can't use $ because the pointer  
doesn't have length

f(x.ptr[x.length/2..x.length])

-Steve


Re: Getting the current datetime converted into a string for writing to stdout

2014-03-31 Thread Kagamin

On Sunday, 30 March 2014 at 08:25:43 UTC, Andre Artus wrote:

Considering the international spread of D users I find it
surprising that the date  time formatting functions in phobos
are not localizable.


Formatting should confined to presentation tier: GUI controls, 
web page generation and must not escape it the rest of code, 
localized formatting freely used in the whole codebase is a bad 
idea. Console output is often implied to be technical and even 
machine-readable, it's a bad idea to localize it. Deep 
integration of localization in e.g. .net causes lots of pain, the 
deeper it is, the more pain in the ass it causes, to the point of 
throwing exceptions with machine-translated error messages.


Re: destructor, postblit constructor --- force calling always

2014-03-31 Thread Benjamin Thaut

Am 31.03.2014 08:06, schrieb monarch_dodra:

On Monday, 31 March 2014 at 01:03:22 UTC, Carl Sturtivant wrote:

What about destructors, are they always called, or is this another
optimization if the struct is in it's default .init state?


In any case, there should be 1 destructor call for every object you
declared.

Except for thing on the heap. Those are just collected, not destroyed :/


The destructor is always called. There is never a instance that gets 
destroyed without the destructor beeing called. It can happen however 
that the destructor gets called on a .init state. This happens for 
example if you use std.algorithm.move. To be fully correct your struct 
should handle the .init state in the destructor (or assert at least so 
you can find and fix those occurences).


Kind Regards
Benjamin Thaut


Re: Parsing

2014-03-31 Thread Marco Leise
Am Mon, 31 Mar 2014 04:06:38 +
schrieb Joel joel...@gmail.com:

 I've got a program that uses user input, but I'm having trouble 
 with it.
 
 Here's an example, the unenclosed numbers (1 2 3 in example) add 
 entries:
 
 0 Achievement
 1 2 3 cWon! st4 5 6 - user input
 
 (create 3 entries all with st4 5 6)
 
 0 Achievement
 1 house [4, 5, 6]
 2 rock [4, 5, 6]
 3 mouse [4, 5, 6]
 
 cmud - user input
 
 0 Achievement
 1 house [4, 5, 6] mud
 2 rock [4, 5, 6] mud
 3 mouse [4, 5, 6] mud
 
 So add the entries and while they are still hot, you can edit 
 them.
 
 I don't know if this an impossible ask for help, but I though I 
 might get some help. I'll keep going over my code to work it out.
 
 Thanks.

So what is the question?

-- 
Marco



Re: best D equivalent to C'stimeval

2014-03-31 Thread Marco Leise
Am Mon, 31 Mar 2014 05:09:22 +
schrieb ed sillymong...@gmail.com:

 Hi,
 
 Just wondering what the best replacement for C timeval is in D. 
 I'm looking at std.datetime.SysTime, but std.datetime is huge so 
 I'm not sure.
 
 Thanks,
 ed

If you just need to time something, TickDuration from
core.time is an efficient cross-platform timer.

auto t1 = TickDuration.currentSystemTick;
...
auto t2 = TickDuration.currentSystemTick;
writefln(Took %s ms, (t2-t1).msecs);

-- 
Marco



How to foreach over a DList?

2014-03-31 Thread Jeroen Bollen
I am trying to foreach over a std.container.DList but it isn't 
working. I have tried the following code: 
https://gist.github.com/Binero/f30e56351baf05f1a2ec


I am getting the following errors:

/usr/include/dlang/dmd/std/container.d(1925): Error: template 
std.container.DList!ubyte.DList.insertBeforeNode cannot deduce 
function from argument types !()(typeof(null), int), candidates 
are:
/usr/include/dlang/dmd/std/container.d(2096):
std.container.DList!ubyte.DList.insertBeforeNode(Stuff)(Node* n, 
Stuff stuff) if (isInputRange!Stuff  
isImplicitlyConvertible!(ElementType!Stuff, T))
/usr/include/dlang/dmd/std/container.d(2155):
std.container.DList!ubyte.DList.insertBeforeNode(Stuff)(Node* n, 
Stuff stuff) if (isImplicitlyConvertible!(Stuff, T))
source/app.d(7): Error: template instance 
std.container.DList!ubyte.DList.insertBack!int error instantiating

source/app.d(11): Error: invalid foreach aggregate list1


Re: How to foreach over a DList?

2014-03-31 Thread H. S. Teoh
On Mon, Mar 31, 2014 at 05:50:16PM +, Jeroen Bollen wrote:
 I am trying to foreach over a std.container.DList but it isn't working. I
 have tried the following code:
[...]

Maybe try using opSlice:

DList myList;
foreach (e; myList[]) { ... }

?


T

-- 
Three out of two people have difficulties with fractions. -- Dirk Eddelbuettel


Getting the current datetime converted into a string for writing to stdout

2014-03-31 Thread Gary Miller
I've been reading through and trying various code fragments to 
pull the system date/time in and format it as a string for 
display on the console.


I only need it down to the second and from my current machine so 
I don't need to use any of the more accurate clocks used for 
benchmarking right now.


All the examples seem to be setting the date or date time to some 
predetermined value instead of pulling it from the system.


It seems like this would be a very common function to use so I 
know I must be making this a lot harder than it really is.


Oh and before I forget I'd like to thank everybody on the forum 
for their great support.


I'm still a newbie at D.  I've bought the book.  I've watched the 
YouTube videos and now I'm starting to get a lot more comfortable 
with the code but it feels like it's going to take me some time 
to figure out the tricks for using all the library functions.


I started out trying to use strings for everything but quickly 
found that my code is doing a lot of string modification 
concatenation and I had to switch to char[] instead to get around 
the immutability but now a lot of the library functions use the 
string data type so I am having to figure out how to convert 
between back and forth between all the different datatypes.


It would be nice if all the primitive datatypes had a consistent 
toString cast or function but since I'm not seeing those I guess 
writeFormatted must be the preferred way of getting values into 
string format.




Re: Getting the current datetime converted into a string for writing to stdout

2014-03-31 Thread Gary Willoughby

On Saturday, 29 March 2014 at 05:01:14 UTC, Gary Miller wrote:
I've been reading through and trying various code fragments to 
pull the system date/time in and format it as a string for 
display on the console.


I only need it down to the second and from my current machine 
so I don't need to use any of the more accurate clocks used for 
benchmarking right now.


This is the easiest way i know.

import std.stdio;
import std.datetime;

void main(string[] args)
{
writeln(Clock.currTime.toLocalTime.toSimpleString);
}

It would be nice if all the primitive datatypes had a 
consistent toString cast or function but since I'm not seeing 
those I guess writeFormatted must be the preferred way of 
getting values into string format.


See std.conv and the 'to' function.

data.to!(string)
data.to!(int)
etc...

http://dlang.org/phobos/std_conv.html#.to


Re: Getting the current datetime converted into a string for writing to stdout

2014-03-31 Thread Gary Willoughby

On Saturday, 29 March 2014 at 05:01:14 UTC, Gary Miller wrote:
I've been reading through and trying various code fragments to 
pull the system date/time in and format it as a string for 
display on the console.


Here's a good primer on the datetime module: 
http://dlang.org/intro-to-datetime.html




Re: How to foreach over a DList?

2014-03-31 Thread Jeroen Bollen

On Monday, 31 March 2014 at 19:26:23 UTC, Jeroen Bollen wrote:

On Monday, 31 March 2014 at 18:24:39 UTC, H. S. Teoh wrote:

On Mon, Mar 31, 2014 at 05:50:16PM +, Jeroen Bollen wrote:
I am trying to foreach over a std.container.DList but it 
isn't working. I

have tried the following code:

[...]

Maybe try using opSlice:

DList myList;
foreach (e; myList[]) { ... }

?


T


Can you explain that syntax?


nvm figured it out;

Are constant DLists supposed to be un-foreach-able?
Error: mutable method std.container.DList!(ubyte).DList.opSlice 
is not callable using a const object


template interface and delegates

2014-03-31 Thread anonymous

Hi,
I'm new to D and played a bit with templates and delegates.
Now i discovered some behaviore that i don't understand.
Can somebody explain me why i get two different outputs?


import std.stdio;


interface A(T){
bool GetBool();
T getT();
}

class C:A!(double){
override bool GetBool(){
return false;
}
override double getT(){
return 1;
}
}

void mwriteln(T)( A!T delegate() dg){
writeln(dg().getT());
}

void main()
{
auto c = new C();
writeln(c.getT());
mwriteln!double({return new C();});
}


Re: How to set JSON_TYPE in 2.0.65

2014-03-31 Thread Matt Soucy
On 03/31/2014 02:59 PM, nrgyzer wrote:
 Hi guys,
 
 I updated my dmd version from 2.0.63 to 2.0.65 and having some trouble
 with my JSON-definitions. The code below worked in 2.0.63 but not in
 2.0.65:
 
 JSONValue oJson = JSONValue();
 oJson.type = JSON_TYPE.OBJECT; // FAILS
 oJson.object[myEntry] = JSONValue();
 oJson.object[myEntry].type = JSON_TYPE.STRING; // FAILS
 oJSon.object[myEntry].str = MyText;
 
 Since the type property is a constant in 2.0.65, I've no idea how I can
 set the type for my JSON entries. I already tried the following:
 
 JSONValue oJson = JSONValue(JSON_TYPE.OBJECT);
 oJson.object[myEntry] = JSONValue(JSON_TYPE.STRING);
 oJSon.object[myEntry].str = MyText;
 
 But this gives me something like: JSONValue is not an object.
 
 Any idea how I can set the corresponding value type?
I believe that this was simplified in recent releases, so one only needs
to do the following:

JSONValue oJson;
oJson.object[myEntry] = MyText;

(Untested but I believe this is how it's supposed to be now)

-- 
Matt Soucy
http://msoucy.me/


Re: How to foreach over a DList?

2014-03-31 Thread Jeroen Bollen

On Monday, 31 March 2014 at 18:24:39 UTC, H. S. Teoh wrote:

On Mon, Mar 31, 2014 at 05:50:16PM +, Jeroen Bollen wrote:
I am trying to foreach over a std.container.DList but it isn't 
working. I

have tried the following code:

[...]

Maybe try using opSlice:

DList myList;
foreach (e; myList[]) { ... }

?


T


Can you explain that syntax?


Re: Parsing

2014-03-31 Thread Joel

Oops, the 'cWon!' shouldn't be there, I forgot to use it.

On Monday, 31 March 2014 at 19:23:17 UTC, Joel wrote:

On Monday, 31 March 2014 at 17:25:58 UTC, Marco Leise wrote:

Am Mon, 31 Mar 2014 04:06:38 +
schrieb Joel joel...@gmail.com:

I've got a program that uses user input, but I'm having 
trouble with it.


Here's an example, the unenclosed numbers (1 2 3 in example) 
add entries:


0 Achievement
1 2 3 cWon! st4 5 6 - user input

(create 3 entries all with st4 5 6)

0 Achievement
1 house [4, 5, 6]
2 rock [4, 5, 6]
3 mouse [4, 5, 6]

cmud - user input

0 Achievement
1 house [4, 5, 6] mud
2 rock [4, 5, 6] mud
3 mouse [4, 5, 6] mud

So add the entries and while they are still hot, you can edit 
them.


I don't know if this an impossible ask for help, but I though 
I might get some help. I'll keep going over my code to work 
it out.


Thanks.


So what is the question?


Oh, how do I parse the example? So that entries are added and 
values are set. I'm not sure how to explain it.




Re: How to set JSON_TYPE in 2.0.65

2014-03-31 Thread Justin Whear
On Mon, 31 Mar 2014 15:05:10 -0400, Matt Soucy wrote:

 I believe that this was simplified in recent releases, so one only needs
 to do the following:
 
 JSONValue oJson;
 oJson.object[myEntry] = MyText;
 
 (Untested but I believe this is how it's supposed to be now)

That's correct, the type field has been moved to a read-only property.  
JSONValue should derive the appropriate type via assignment:

JSONValue i = 2; // type == INTEGER
JSONValue s = s; // type == STRING
JSONValue a = [ JSONValue(1.0) ]; // type == ARRAY (of FLOAT)

Note that you can also use the constructor (calls opAssign internally).


Re: How to foreach over a DList?

2014-03-31 Thread Jeroen Bollen

Still not working:

https://gist.github.com/Binero/f30e56351baf05f1a2ec
/usr/include/dlang/dmd/std/container.d(1925): Error: template 
std.container.DList!ubyte.DList.insertBeforeNode cannot deduce 
function from argument types !()(typeof(null), int), candidates 
are:
/usr/include/dlang/dmd/std/container.d(2096):
std.container.DList!ubyte.DList.insertBeforeNode(Stuff)(Node* n, 
Stuff stuff) if (isInputRange!Stuff  
isImplicitlyConvertible!(ElementType!Stuff, T))
/usr/include/dlang/dmd/std/container.d(2155):
std.container.DList!ubyte.DList.insertBeforeNode(Stuff)(Node* n, 
Stuff stuff) if (isImplicitlyConvertible!(Stuff, T))
source/app.d(7): Error: template instance 
std.container.DList!ubyte.DList.insertBack!int error instantiating
source/app.d(11): Error: need upper and lower bound to slice 
pointer


How to set JSON_TYPE in 2.0.65

2014-03-31 Thread nrgyzer

Hi guys,

I updated my dmd version from 2.0.63 to 2.0.65 and having some 
trouble with my JSON-definitions. The code below worked in 2.0.63 
but not in 2.0.65:


JSONValue oJson = JSONValue();
oJson.type = JSON_TYPE.OBJECT; // FAILS
oJson.object[myEntry] = JSONValue();
oJson.object[myEntry].type = JSON_TYPE.STRING; // FAILS
oJSon.object[myEntry].str = MyText;

Since the type property is a constant in 2.0.65, I've no idea how 
I can set the type for my JSON entries. I already tried the 
following:


JSONValue oJson = JSONValue(JSON_TYPE.OBJECT);
oJson.object[myEntry] = JSONValue(JSON_TYPE.STRING);
oJSon.object[myEntry].str = MyText;

But this gives me something like: JSONValue is not an object.

Any idea how I can set the corresponding value type?


Re: Parsing

2014-03-31 Thread Joel

On Monday, 31 March 2014 at 17:25:58 UTC, Marco Leise wrote:

Am Mon, 31 Mar 2014 04:06:38 +
schrieb Joel joel...@gmail.com:

I've got a program that uses user input, but I'm having 
trouble with it.


Here's an example, the unenclosed numbers (1 2 3 in example) 
add entries:


0 Achievement
1 2 3 cWon! st4 5 6 - user input

(create 3 entries all with st4 5 6)

0 Achievement
1 house [4, 5, 6]
2 rock [4, 5, 6]
3 mouse [4, 5, 6]

cmud - user input

0 Achievement
1 house [4, 5, 6] mud
2 rock [4, 5, 6] mud
3 mouse [4, 5, 6] mud

So add the entries and while they are still hot, you can edit 
them.


I don't know if this an impossible ask for help, but I though 
I might get some help. I'll keep going over my code to work it 
out.


Thanks.


So what is the question?


Oh, how do I parse the example? So that entries are added and 
values are set. I'm not sure how to explain it.


Re: Avoiding Range Checks in Slice Expressions

2014-03-31 Thread Nordlöw
If they are range-checked, it would be a good addition to the 
optimizer to remove them. My guess is that it is range-checked.




$/n is of course always within range if n is positive integer = 
1.


But what about in the general indexing/slicing case? In that case 
it would be useful if we could reuse value range propagation 
(VRP) in DMD, to figure out which other expressions that don't 
need range checking.


Re: template interface and delegates

2014-03-31 Thread Justin Whear
On Mon, 31 Mar 2014 18:58:30 +, anonymous wrote:

 Hi,
 I'm new to D and played a bit with templates and delegates.
 Now i discovered some behaviore that i don't understand. Can somebody
 explain me why i get two different outputs?
 
 
 import std.stdio;
 
 
 interface A(T){
   bool GetBool();
   T getT();
 }
 
 class C:A!(double){
   override bool GetBool(){
   return false;
   }
   override double getT(){
   return 1;
   }
 }
 
 void mwriteln(T)( A!T delegate() dg){
   writeln(dg().getT());
 }
 
 void main()
 {
   auto c = new C(); writeln(c.getT()); mwriteln!double({return new
   C();});
 }

Looks like a bug.  Here's a cleaned-up test case:

---
interface A(T)
{
T getT();
}

class C : A!double
{
double getT(){ return 1; }
}

void mwriteln(T)(A!T delegate() dg)
{
import std.stdio;
auto a = dg();
writeln(Checkpoint 1);
assert(a !is null);
writeln(a);
writeln(Checkpoint 2);
}

void main()
{
import std.traits;
static assert(isImplicitlyConvertible!(C, A!double));
mwriteln!double({return new C();});
}
---

Backtrace:
---
Program received signal SIGSEGV, Segmentation fault.
#0  0x0042ac8c in _d_interface_cast ()
#1  0x00427ec6 in 
std.format.__T11formatValueTS3std5stdio4File17LockingTextWriterTC4test8__T1ATdZ1ATaZ.formatValue
() ()
#2  0x00427e23 in 
std.format.__T13formatGenericTS3std5stdio4File17LockingTextWriterTC4test8__T1ATdZ1ATaZ.formatGeneric
() ()
#3  0x00427d29 in 
std.format.__T14formattedWriteTS3std5stdio4File17LockingTextWriterTaTC4test8__T1ATdZ1AZ.formattedWrite
() ()
#4  0x00427871 in 
std.stdio.File.__T5writeTC4test8__T1ATdZ1ATaZ.write() ()
#5  0x004277d5 in std.stdio.__T7writelnTC4test8__T1ATdZ1AZ.writeln
() ()
#6  0x0042771f in test.__T8mwritelnTdZ.mwriteln() ()
#7  0x004276a9 in D main ()
#8  0x0042b61c in rt.dmain2._d_run_main() ()
#9  0x0042b576 in rt.dmain2._d_run_main() ()
#10 0x0042b5dc in rt.dmain2._d_run_main() ()
#11 0x0042b576 in rt.dmain2._d_run_main() ()
#12 0x0042b4f7 in _d_run_main ()
#13 0x00429c5f in main ()
---


Re: Avoiding Range Checks in Slice Expressions

2014-03-31 Thread Nordlöw



If not, what would it require to implement it?


That would be an interesting task to fix :)

DMD source references anyone?


tuple (TypeTuple kind) multi-initialization. Actually documented?

2014-03-31 Thread monarch_dodra
If you declare an instance of a tuple, eg TypeTuple!(int, int, 
int), you can initialize all members from a single argument. EG:


TypeTuple!(int, int, int) a = 5;

bearophile made a suggestion that we should deprecate this.
https://d.puremagic.com/issues/show_bug.cgi?id=6367

I'd like to know if this behavior even documented at all, or kind 
of just happens to work.


In particular, it doesn't work in CTFE at all:
https://d.puremagic.com/issues/show_bug.cgi?id=12499

I'd like to ask the spec guru's to know which direction to take 
in dealing with both these issues.


Re: template interface and delegates

2014-03-31 Thread Steven Schveighoffer

On Mon, 31 Mar 2014 14:58:30 -0400, anonymous n...@trash-mail.com wrote:


Hi,
I'm new to D and played a bit with templates and delegates.
Now i discovered some behaviore that i don't understand.
Can somebody explain me why i get two different outputs?


import std.stdio;


interface A(T){
bool GetBool();
T getT();
}

class C:A!(double){
override bool GetBool(){
return false;
}
override double getT(){
return 1;
}
}

void mwriteln(T)( A!T delegate() dg){
writeln(dg().getT());
}

void main()
{
auto c = new C();
writeln(c.getT());
mwriteln!double({return new C();});
}


This is definitely a bug.

Reduced case:

import std.stdio;

interface A{
void foo();
}

class C:A{
override void foo(){
writeln(here);
}
}

void x( A delegate() dg){
dg().foo();
}

void main()
{
A c = new C;
c.foo(); // prints here
x({A a = new C; return a;}); // prints here
x({return new C;}); // does not print
}

This is really an issue with delegate return type inferrence not working  
properly.


-Steve


Re: tuple (TypeTuple kind) multi-initialization. Actually documented?

2014-03-31 Thread bearophile

monarch_dodra:


bearophile made a suggestion that we should deprecate this.
https://d.puremagic.com/issues/show_bug.cgi?id=6367


It goes against the idea of tuple. No language that I know 
(Haskell, Rust, F#, Python, and more) that has tuples supports 
the initialization of a n-tuple with a scalar value. It's sloppy. 
And sloppy designs usually find a way to bite your rump later.


Bye,
bearophile


Re: tuple (TypeTuple kind) multi-initialization. Actually documented?

2014-03-31 Thread bearophile
No language that I know (Haskell, Rust, F#, Python, and more) 
that has tuples supports the initialization of a n-tuple with a 
scalar value.


In Python there is a way to build a n-tuple from a 1-tuple, but 
the seed is not a scalar, and this is an explicit syntax:



(5,) * 3

(5, 5, 5)

Bye,
bearophile


Re: tuple (TypeTuple kind) multi-initialization. Actually documented?

2014-03-31 Thread monarch_dodra

On Monday, 31 March 2014 at 21:05:11 UTC, bearophile wrote:

monarch_dodra:


bearophile made a suggestion that we should deprecate this.
https://d.puremagic.com/issues/show_bug.cgi?id=6367


It goes against the idea of tuple. No language that I know 
(Haskell, Rust, F#, Python, and more) that has tuples supports 
the initialization of a n-tuple with a scalar value. It's 
sloppy. And sloppy designs usually find a way to bite your rump 
later.


Yes, but at this point, I (we?) don't even know if it's intended 
behavior to begin with.


If it was an accident it worked to begin with, then it's fate 
should be sealed pretty fast.


The fact that CTFE doesn't seem to work with it seems (to me) an 
indication of that.


Re: How to foreach over a DList?

2014-03-31 Thread H. S. Teoh
On Mon, Mar 31, 2014 at 07:30:11PM +, Jeroen Bollen wrote:
 On Monday, 31 March 2014 at 19:26:23 UTC, Jeroen Bollen wrote:
 On Monday, 31 March 2014 at 18:24:39 UTC, H. S. Teoh wrote:
 On Mon, Mar 31, 2014 at 05:50:16PM +, Jeroen Bollen wrote:
 I am trying to foreach over a std.container.DList but it isn't
 working. I
 have tried the following code:
 [...]
 
 Maybe try using opSlice:
 
 DList myList;
 foreach (e; myList[]) { ... }
 
 ?
 
 
 T
 
 Can you explain that syntax?
 
 nvm figured it out;
 
 Are constant DLists supposed to be un-foreach-able?
 Error: mutable method std.container.DList!(ubyte).DList.opSlice is not
 callable using a const object

Argh, why is opSlice non-const? :-(  Please file a bug.

Not sure what you can do in the meantime... probably cast away const? Or
avoid using const for containers if you can. The last time I tried that,
I got stuck in a quagmire of partially-implemented const support with no
way out of the mess, and I decided that non-const is less painful to
work with. :-/


T

-- 
English is useful because it is a mess. Since English is a mess, it maps well 
onto the problem space, which is also a mess, which we call reality. Similarly, 
Perl was designed to be a mess, though in the nicests of all possible ways. -- 
Larry Wall


Re: How to foreach over a DList?

2014-03-31 Thread Ali Çehreli

On 03/31/2014 10:50 AM, Jeroen Bollen wrote:

I am trying to foreach over a std.container.DList but it isn't working.
I have tried the following code:
https://gist.github.com/Binero/f30e56351baf05f1a2ec

I am getting the following errors:

/usr/include/dlang/dmd/std/container.d(1925): Error: template
std.container.DList!ubyte.DList.insertBeforeNode cannot deduce function
from argument types !()(typeof(null), int), candidates are:
/usr/include/dlang/dmd/std/container.d(2096):
std.container.DList!ubyte.DList.insertBeforeNode(Stuff)(Node* n, Stuff
stuff) if (isInputRange!Stuff 
isImplicitlyConvertible!(ElementType!Stuff, T))
/usr/include/dlang/dmd/std/container.d(2155):
std.container.DList!ubyte.DList.insertBeforeNode(Stuff)(Node* n, Stuff
stuff) if (isImplicitlyConvertible!(Stuff, T))
source/app.d(7): Error: template instance
std.container.DList!ubyte.DList.insertBack!int error instantiating
source/app.d(11): Error: invalid foreach aggregate list1


Some notes:

1) DList is a struct. So, there is no need for 'new'. However, new is 
not an error but then the ~= syntax below cannot work on list1 without 
dereferencing. (You did not use ~=, I just liked it. :) )


(*list1) ~= cast(ubyte)3;// would work

2) For the same reason, list1[] becomes plain array slicing and the 
compiler is looking for upper and lower bound to slice pointer. This 
would work:


(*list1)[]

3) 1, 2, and 3 are ints. So, I had to cast them.

import std.container;
import std.stdio;

void main()
{
auto list1 = DList!ubyte();

list1.insertBack(cast(ubyte)1);
list1.insertBack(cast(ubyte)2);
list1 ~= cast(ubyte)3;// alternative syntax

foreach(ubyte item; list1[]) {
writeln(item);
}
}

Ali



Re: How to foreach over a DList?

2014-03-31 Thread monarch_dodra

On Monday, 31 March 2014 at 21:41:16 UTC, H. S. Teoh wrote:

Argh, why is opSlice non-const? :-(  Please file a bug.


If opSlice was const, then you'd get a const slice, with const 
reference. You wouldn't even be able to iterate on it.


With some extra code, you could create some sort of slice of 
immutable type, but you'd still only be able to get const items.


We *could* add a const *overload* but...


Or avoid using const for containers if you can.


That. D's turtles all the way down const doesn't work like 
C++'s head only const. As a general rule, don't use too much 
const in D, *especially* for containers-like objects...


At this point, adding a const overload would be nothing more that 
a still unusable mess, with extra maintenance overhead.


Trying Multiple Aggregate reduce

2014-03-31 Thread Nordlöw

I'm trying to figure out how to use reduce with multiply funs.

Here's my try on minmaxElement:


import std.typecons: tuple;

/** Returns: Tuple of Minmum and Maximum Element in X. */
auto minmaxElement(alias F = min, alias G = max, R)(in R range)
@safe pure nothrow if (isInputRange!R)
{
return reduce!(F, G)(tuple(ElementType!R.max,
   ElementType!R.min), range);
}

unittest { assert([1, 2, 3].minmaxElement == tuple(1, 3)); }


which errors as

/home/per/opt/x86_64-unknown-linux-gnu/dmd/bin/../include/d2/std/algorithm.d(774,29): 
Error: can only initialize const member _expand_field_0 inside 
constructor
/home/per/opt/x86_64-unknown-linux-gnu/dmd/bin/../include/d2/std/algorithm.d(774,29): 
Error: can only initialize const member _expand_field_1 inside 
constructor
algorithm_ex.d(157,25): Error: template instance 
std.algorithm.reduce!(min, max).reduce!(Tuple!(const(int), 
const(int)), const(int)[]) error instantiating
algorithm_ex.d(160,28):instantiated from here: 
minmaxElement!(min, max, const(int)[])



If I replace ElementType!R.min and ElementType!R.max with a 
values, say 0 and 1 it compiles. What is going on here?


This seems related:
http://forum.dlang.org/thread/bug-1040...@http.d.puremagic.com/issues/


Re: How to foreach over a DList?

2014-03-31 Thread Jos van Uden

On 31-3-2014 19:50, Jeroen Bollen wrote:

I am trying to foreach over a std.container.DList but it isn't working. I have 
tried the following code: https://gist.github.com/Binero/f30e56351baf05f1a2ec

I am getting the following errors:

/usr/include/dlang/dmd/std/container.d(1925): Error: template 
std.container.DList!ubyte.DList.insertBeforeNode cannot deduce function from 
argument types !()(typeof(null), int), candidates are:
/usr/include/dlang/dmd/std/container.d(2096): 
std.container.DList!ubyte.DList.insertBeforeNode(Stuff)(Node* n, Stuff stuff) if 
(isInputRange!Stuff  isImplicitlyConvertible!(ElementType!Stuff, T))
/usr/include/dlang/dmd/std/container.d(2155): 
std.container.DList!ubyte.DList.insertBeforeNode(Stuff)(Node* n, Stuff stuff) 
if (isImplicitlyConvertible!(Stuff, T))
source/app.d(7): Error: template instance 
std.container.DList!ubyte.DList.insertBack!int error instantiating
source/app.d(11): Error: invalid foreach aggregate list1


http://rosettacode.org/wiki/Strand_sort#D


Re: Trying Multiple Aggregate reduce

2014-03-31 Thread bearophile

Nordlöw:


I'm trying to figure out how to use reduce with multiply funs.


import std.algorithm: min, max, reduce;
import std.typecons: tuple, Unqual;
import std.range: isInputRange, ElementType;

/// Returns: Tuple of Minmum and Maximum Element in X.
auto minMax(alias F = min, alias G = max, R)(in R range)
@safe pure nothrow if (isInputRange!R) {
return reduce!(F, G)(tuple(Unqual!(ElementType!R).max,
   Unqual!(ElementType!R).min), 
range);

}

unittest {
assert([1, 2, 3].minMax == tuple(1, 3));
}

void main() {}


If I replace ElementType!R.min and ElementType!R.max with a 
values, say 0 and 1 it compiles. What is going on here?


This seems related:
http://forum.dlang.org/thread/bug-1040...@http.d.puremagic.com/issues/


You can't use reduce with a const seed.

Bye,
bearophile


Re: Trying Multiple Aggregate reduce

2014-03-31 Thread Ali Çehreli

On 03/31/2014 03:13 PM, bearophile wrote:

Nordlöw:


I'm trying to figure out how to use reduce with multiply funs.


Could someone please check the following. It looks like a compiler bug 
on git head (DMD64 D Compiler v2.066-devel-75159e4):


import std.algorithm;

int foo(int value)
{
return value;
}

void main()
{
reduce!(foo, foo)(tuple(0, 0), [ 1 ]);
}

statement.c:274: ErrorStatement::ErrorStatement(): Assertion 
`global.gaggedErrors || global.errors' failed.


Ali



Re: Trying Multiple Aggregate reduce

2014-03-31 Thread Nordlöw

You can't use reduce with a const seed.



This, surely, must be a compiler bug right?

/Per


Re: How to foreach over a DList?

2014-03-31 Thread anonymous

On Monday, 31 March 2014 at 21:55:03 UTC, monarch_dodra wrote:
If opSlice was const, then you'd get a const slice, with const 
reference. You wouldn't even be able to iterate on it.


const opSlice does not mean it returns a const(Range).

With some extra code, you could create some sort of slice of 
immutable type, but you'd still only be able to get const 
items.


Iterating over const items is the goal.


We *could* add a const *overload* but...


Or avoid using const for containers if you can.


That. D's turtles all the way down const doesn't work like 
C++'s head only const. As a general rule, don't use too much 
const in D, *especially* for containers-like objects...


At this point, adding a const overload would be nothing more 
that a still unusable mess, with extra maintenance overhead.


Gotta disagree violently here. Asking for a const overload of
opSlice isn't too much const. std.container is just in a sorry
state regarding const compatibility. That can and should be fixed.


Re: Trying Multiple Aggregate reduce

2014-03-31 Thread bearophile

Ali Çehreli:

statement.c:274: ErrorStatement::ErrorStatement(): Assertion 
`global.gaggedErrors || global.errors' failed.


It's a little compiler bug, that should go in Bugzilla (even if 
perhaps it was recently added).


Bye,
bearophile


Re: Trying Multiple Aggregate reduce

2014-03-31 Thread Ali Çehreli

On 03/31/2014 04:01 PM, bearophile wrote:

Ali Çehreli:


statement.c:274: ErrorStatement::ErrorStatement(): Assertion
`global.gaggedErrors || global.errors' failed.


It's a little compiler bug, that should go in Bugzilla (even if perhaps
it was recently added).


  https://d.puremagic.com/issues/show_bug.cgi?id=12501

Ali



Re: How to set JSON_TYPE in 2.0.65

2014-03-31 Thread Colden Cullen

On Monday, 31 March 2014 at 19:05:11 UTC, Matt Soucy wrote:

On 03/31/2014 02:59 PM, nrgyzer wrote:

Hi guys,

I updated my dmd version from 2.0.63 to 2.0.65 and having some 
trouble
with my JSON-definitions. The code below worked in 2.0.63 but 
not in

2.0.65:

JSONValue oJson = JSONValue();
oJson.type = JSON_TYPE.OBJECT; // FAILS
oJson.object[myEntry] = JSONValue();
oJson.object[myEntry].type = JSON_TYPE.STRING; // FAILS
oJSon.object[myEntry].str = MyText;

Since the type property is a constant in 2.0.65, I've no idea 
how I can
set the type for my JSON entries. I already tried the 
following:


JSONValue oJson = JSONValue(JSON_TYPE.OBJECT);
oJson.object[myEntry] = JSONValue(JSON_TYPE.STRING);
oJSon.object[myEntry].str = MyText;

But this gives me something like: JSONValue is not an object.

Any idea how I can set the corresponding value type?
I believe that this was simplified in recent releases, so one 
only needs

to do the following:

JSONValue oJson;
oJson.object[myEntry] = MyText;

(Untested but I believe this is how it's supposed to be now)


I believe for this case you would want this:
JSONValue oJson = [ myEntry: MyText ];



Re: How to set JSON_TYPE in 2.0.65

2014-03-31 Thread Tolga Cakiroglu


I believe for this case you would want this:
JSONValue oJson = [ myEntry: MyText ];


Yeah, and unfortunately, there is no that easy way to create an 
empty object type json value though. (Yes, I had a need for 
that). I needed to work around of that.


Kitchen Designer Hertfordshire

2014-03-31 Thread singsing
Kitchen Designer Hertfordshire. Thirty Ex Display Kitchens To 
Clear. w.w.w-e.x.d.i.s.p.l.a.y.k.i.t.c.h.e.n.s.1-c.o-u.k.  .£  
5.9.5.  Each with appliances.


Re: How to foreach over a DList?

2014-03-31 Thread H. S. Teoh
On Mon, Mar 31, 2014 at 09:55:01PM +, monarch_dodra wrote:
 On Monday, 31 March 2014 at 21:41:16 UTC, H. S. Teoh wrote:
 Argh, why is opSlice non-const? :-(  Please file a bug.
 
 If opSlice was const, then you'd get a const slice, with const
 reference.  You wouldn't even be able to iterate on it.
[...]

Um... wat?

I didn't say opSlice should return a const object (that would be
ridiculous, as you point out). Rather, it should return a tail-const
range that iterates over the const items in the const list.

A const container that cannot be iterated over makes no sense at all.
Iterating over something doesn't modify anything!!


T

-- 
Ruby is essentially Perl minus Wall.


Why is SysTime.init invalid?

2014-03-31 Thread ed

Hi All,


I'm trying to use SysTime in a struct but I've noticed the 
following:


(A) SysTime.init leads to a crash.
---
void main()
{
SysTime t;
writefln(t:%s, t);
}

% ./dtest
zsh: segmentation fault (core dumped) ./dtest
---

(B) Initialising a SysTime member directly fails
---
struct T
{
SysTime t=SysTime(0);
}
datetime.d (28538) Error: static variable _lowLock cannot be read 
at compile time

---

Which means I have to provide a default ctor for my struct but do 
not know how.



1. Is this by design or is it a bug?
2. Is there a way to provide a default struct ctor so I can init 
the SysTime member?


If this is by design I don't think it should crash. A Date/Time 
error is often something user code can safely recover from.


Thanks,
ed


Re: How to foreach over a DList?

2014-03-31 Thread Jeroen Bollen

Still no luck:

import std.container;
import std.stdio;

void main()
{
DList!ubyte list1 = DList!ubyte();
list1 ~= cast(ubyte) 1;
list1 ~= cast(ubyte) 2;
list1 ~= cast(ubyte) 3;

foreach(ubyte item; list1[]) {
writeln(item);
}
}

/usr/include/dlang/dmd/std/container.d(1874): Error: no property 
'_first' for type 'ubyte'
/usr/include/dlang/dmd/std/container.d(1875): Error: no property 
'_first' for type 'ubyte'
/usr/include/dlang/dmd/std/container.d(1875): Error: undefined 
identifier rhs_, did you mean variable rhs?
source/app.d(7): Error: template instance 
std.container.DList!ubyte.DList.opOpAssign!(~, ubyte) error 
instantiating
source/app.d(7): Error: cannot append type ubyte to type 
DList!ubyte


Re: Why is SysTime.init invalid?

2014-03-31 Thread ed


OK, lazy me just read the std.satetime article again. It appears 
the design is for no invalid values and it is currently a known 
limitation due to CTFE.


---
d_time_nan	There is no equivalent. SysTime.init, which has a null 
TimeZone object, would be the closest, but once CTFE advances to 
the point that you can new up class objects with it, 
SysTime.init's timezone will be LocalTime, so don't rely on 
SysTime.init being invalid. std.datetime in general tries to 
avoid having any invalid states for any of its types. It's 
intended that creating such values be impossible.

---

I would still like to know if there is a way around this so I can 
have my struct default init.


Thanks,
ed



Re: template interface and delegates

2014-03-31 Thread anonymous
Ok, thought i did something wrong or got some wrong idea how it 
should work.