Re: How to use std.bind?

2011-01-18 Thread Lars T. Kyllingstad
On Mon, 17 Jan 2011 17:03:15 +, Sean Eskapp wrote:

 I used to use boost::bind all the time, but std.bind has me stumped, as
 I keep getting static asserts with a cryptic argument has no
 parameters message. At this point, the code is just:
 
 class Foo
 {
   void bar(int i) { writeln(i); }
 }
 
 void main()
 {
   auto foobar = new Foo;
   bind(foobar.bar, 5)();
 }
 
 I've tried a myriad of different ways, but keep coming up with the same
 error. Using bindAlias gives me an error that std.bind.bindAlias(alias
 FT) is not a function template.
 
 I'm using DMD v2.051 on a Windows platform. Help anybody?

Like BlazingWhitester said, std.bind is scheduled for deprecation.  (It 
will be marked as such starting with the next DMD release.)  It is a 
relic from D1, and I don't think it has worked well with D2 for quite a 
while.

Luckily, you don't need it at all.  You can do the same thing with D2's 
built-in features, such as nested functions and lambdas.

  // Lambda example
  int add2(int i) { return i + 2; }

  void main()
  {
  auto seven = () { return add2(5); };
  assert (seven() == 7);
  }

-Lars


Re: std.container.Array/RefCounted(T) leaking memory?

2011-01-18 Thread Lars T. Kyllingstad
On Tue, 18 Jan 2011 01:16:51 +, %u wrote:

 I find it very hard to believe that struct dtors are never called.
 
 Sorry, that part was my bad -- last time I checked, they didn't get
 called, but maybe my example was too complicated, since they did get
 called for a *simple* example.
 
 However, here's a situation in which no postblit or destructor is called
 whatsoever:
 
 import std.stdio;
 struct S
 {
this(int dummy) { writeln(ctor); }
this(this) { writeln(postblit); }
~this() { writeln(dtor); }
 }
 S test(int depth) { return depth  0 ? test(depth - 1) : S(0); } int
 main(string[] argv) { test(3); }


That would be bug 3516, wouldn't it?

  http://d.puremagic.com/issues/show_bug.cgi?id=3516

-Lars


std.date / std.datetime

2011-01-18 Thread Richard Chamberlain

Hello,

I'm in the process of learning D, and to do so I'm converting some older code.

I need to print out the current local date and time, which is causing 
some difficulties because std.date doesn't seem adequate in this 
respect. I understand there is soon to be a replacement, std.datetime, 
which I suspect will be much easier.


When are we likely to see a new release which includes std.datetime?

If not relatively soon I presume the easiest thing to do is to download 
it myself and recompile the phobos library to include it. In which case 
there seems to be already a std.datetime with different functionality, 
is this used elsewhere in phobos? i.e. if I replace it with the new 
std.datetime is that OK?


Many thanks,

Richard



Re: std.date / std.datetime

2011-01-18 Thread Jonathan M Davis
On Tuesday 18 January 2011 03:34:06 Richard Chamberlain wrote:
 Hello,
 
 I'm in the process of learning D, and to do so I'm converting some older
 code.
 
 I need to print out the current local date and time, which is causing
 some difficulties because std.date doesn't seem adequate in this
 respect. I understand there is soon to be a replacement, std.datetime,
 which I suspect will be much easier.
 
 When are we likely to see a new release which includes std.datetime?
 
 If not relatively soon I presume the easiest thing to do is to download
 it myself and recompile the phobos library to include it. In which case
 there seems to be already a std.datetime with different functionality,
 is this used elsewhere in phobos? i.e. if I replace it with the new
 std.datetime is that OK?

std.datetime is currently in Phobos' svn repository and will be in the next 
release.

- Jonathan M Davis


Re: std.date / std.datetime

2011-01-18 Thread %fil
Hi Jonathan,

I'm also stuck with the existing std.date and would want to try out your new
module std.datetime. Do you have any sense when the next release of Phobos is
going to be?

If not, what is the procedure to get a development snapshot of the latest
version of Phobos installed?

thanks,

fil


Re: std.date / std.datetime

2011-01-18 Thread Jonathan M Davis
On Tuesday 18 January 2011 04:15:20 %fil wrote:
 Hi Jonathan,
 
 I'm also stuck with the existing std.date and would want to try out your
 new module std.datetime. Do you have any sense when the next release of
 Phobos is going to be?

I don't know. The last release was about a month ago, and the one before that 
was about a month and a half before that. I'm not aware of there being any hard 
and fast rules or plan about when releases are done. However, they tend to be a 
month or two apart.

 If not, what is the procedure to get a development snapshot of the latest
 version of Phobos installed?

The latest code can be found here: http://www.dsource.org/projects/phobos

However, you're going to have to have the latest druntime as well:  
http://www.dsource.org/projects/druntime

- Jonathan M Davis


enum of struct not calling constructor

2011-01-18 Thread Andrej Mitrovic
Example 1:

import std.stdio;

enum WindowSizes : QSize
{
Minimum = QSize(10)
}

struct QSize
{
int store;
this(int x)
{
store = x + 10;
}
}

void main()
{
auto foo = WindowSizes.Minimum;
assert(foo.store == 10);  // What?

auto bar = QSize(10);
assert(bar.store == 20);
}

It appears the constructor is never called for the enum. It does field by field 
assignments instead, just take a look at this case:

import std.stdio;

enum WindowSizes : Inverted
{
Minimum = Inverted(10, 20)
}

struct Inverted
{
int x;
int y;
this(int in_x, int in_y)
{
x = in_y;
y = in_x;
}
}

void main()
{
auto foo = WindowSizes.Minimum;
assert(foo.x == 10);
assert(foo.y == 20);

auto bar = Inverted(10, 20);
assert(bar.x == 20);
assert(bar.y == 10);
}

As can be seen, this could be a potential source of bugs. Should I file it?


Re: enum of struct not calling constructor

2011-01-18 Thread Jonathan M Davis
On Tuesday, January 18, 2011 08:44:02 Andrej Mitrovic wrote:
 Example 1:
 
 import std.stdio;
 
 enum WindowSizes : QSize
 {
 Minimum = QSize(10)
 }
 
 struct QSize
 {
 int store;
 this(int x)
 {
 store = x + 10;
 }
 }
 
 void main()
 {
 auto foo = WindowSizes.Minimum;
 assert(foo.store == 10);  // What?
 
 auto bar = QSize(10);
 assert(bar.store == 20);
 }
 
 It appears the constructor is never called for the enum. It does field by
 field assignments instead, just take a look at this case:
 
 import std.stdio;
 
 enum WindowSizes : Inverted
 {
 Minimum = Inverted(10, 20)
 }
 
 struct Inverted
 {
 int x;
 int y;
 this(int in_x, int in_y)
 {
 x = in_y;
 y = in_x;
 }
 }
 
 void main()
 {
 auto foo = WindowSizes.Minimum;
 assert(foo.x == 10);
 assert(foo.y == 20);
 
 auto bar = Inverted(10, 20);
 assert(bar.x == 20);
 assert(bar.y == 10);
 }
 
 As can be seen, this could be a potential source of bugs. Should I file it?

Absolutely.

- Jonathan M Davis


Re: std.date / std.datetime

2011-01-18 Thread Richard Chamberlain

On 2011-01-18 16:34:53 +, Jonathan M Davis said:


On Tuesday 18 January 2011 04:15:20 %fil wrote:

Hi Jonathan,

I'm also stuck with the existing std.date and would want to try out your
new module std.datetime. Do you have any sense when the next release of
Phobos is going to be?


I don't know. The last release was about a month ago, and the one before that
was about a month and a half before that. I'm not aware of there being any hard
and fast rules or plan about when releases are done. However, they tend to be a
month or two apart.


If not, what is the procedure to get a development snapshot of the latest
version of Phobos installed?


The latest code can be found here: http://www.dsource.org/projects/phobos

However, you're going to have to have the latest druntime as well:
http://www.dsource.org/projects/druntime

- Jonathan M Davis


Thanks Jonathan.

I think I'll hang around for the official update.



Re: enum of struct not calling constructor

2011-01-18 Thread Andrej Mitrovic
http://d.puremagic.com/issues/show_bug.cgi?id=5460


Re: std.date / std.datetime

2011-01-18 Thread Russel Winder
On Tue, 2011-01-18 at 08:34 -0800, Jonathan M Davis wrote:
[ . . . ]
 I don't know. The last release was about a month ago, and the one before that 
 was about a month and a half before that. I'm not aware of there being any 
 hard 
 and fast rules or plan about when releases are done. However, they tend to be 
 a 
 month or two apart.
[ . . . ]
 The latest code can be found here: http://www.dsource.org/projects/phobos
 
 However, you're going to have to have the latest druntime as well:  
 http://www.dsource.org/projects/druntime

Might it be worth putting in some infrastructure whereby people can use
a distributed DMD or GDC but have a current snapshot or perhaps latest
build of Phobos (where there is consistency between DMD/GDC on the one
hand and Phobos on the other).  This is actually one thing Go does
supremely well, you can pull the Mercurial snapshot and build the entire
system within about 5 minutes.  It makes it very easy to test new
stuff. 

-- 
Russel.
=
Dr Russel Winder  t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder


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


Re: How to use std.bind?

2011-01-18 Thread Andrej Mitrovic
On 1/18/11, Lars T. Kyllingstad public@kyllingen.nospamnet wrote:
 On Mon, 17 Jan 2011 17:03:15 +, Sean Eskapp wrote:

 I used to use boost::bind all the time, but std.bind has me stumped, as
 I keep getting static asserts with a cryptic argument has no
 parameters message. At this point, the code is just:

 class Foo
 {
  void bar(int i) { writeln(i); }
 }

 void main()
 {
  auto foobar = new Foo;
  bind(foobar.bar, 5)();
 }

 I've tried a myriad of different ways, but keep coming up with the same
 error. Using bindAlias gives me an error that std.bind.bindAlias(alias
 FT) is not a function template.

 I'm using DMD v2.051 on a Windows platform. Help anybody?

 Like BlazingWhitester said, std.bind is scheduled for deprecation.  (It
 will be marked as such starting with the next DMD release.)  It is a
 relic from D1, and I don't think it has worked well with D2 for quite a
 while.

 Luckily, you don't need it at all.  You can do the same thing with D2's
 built-in features, such as nested functions and lambdas.

   // Lambda example
   int add2(int i) { return i + 2; }

   void main()
   {
   auto seven = () { return add2(5); };
   assert (seven() == 7);
   }

 -Lars


This is better:
http://www.digitalmars.com/d/2.0/phobos/std_functional.html#curry


Re: std.date / std.datetime

2011-01-18 Thread Jonathan M Davis
On Tuesday, January 18, 2011 09:18:33 Russel Winder wrote:
 On Tue, 2011-01-18 at 08:34 -0800, Jonathan M Davis wrote:
 [ . . . ]
 
  I don't know. The last release was about a month ago, and the one before
  that was about a month and a half before that. I'm not aware of there
  being any hard and fast rules or plan about when releases are done.
  However, they tend to be a month or two apart.
 
 [ . . . ]
 
  The latest code can be found here: http://www.dsource.org/projects/phobos
  
  However, you're going to have to have the latest druntime as well:
  http://www.dsource.org/projects/druntime
 
 Might it be worth putting in some infrastructure whereby people can use
 a distributed DMD or GDC but have a current snapshot or perhaps latest
 build of Phobos (where there is consistency between DMD/GDC on the one
 hand and Phobos on the other).  This is actually one thing Go does
 supremely well, you can pull the Mercurial snapshot and build the entire
 system within about 5 minutes.  It makes it very easy to test new
 stuff.

There has been discussion of D needing some sort of package management system. 
Perhaps that would deal with that issue. And maybe with dmd, druntime, and 
Phobos being moved over to git and github (which is currently being worked on) 
will make that easier. I don't know. However, I think that the focus of the dev 
team overall has been more on getting done than making it easier for people to 
get current development snapshots or know exactly what's going on with 
development at the moment. That's not to say that such things shouldn't be 
improved or that the dev team doesn't want to improve them, but there have been 
other priorities which have taken precedence. There's also a strong tendency 
for 
things to get done because someone wants them done and takes the time to do 
them, and if there's no one who's motivated enough to do something, then it 
often doesn't get done in a timely manner.

- Jonathan M Davis


Re: std.date / std.datetime

2011-01-18 Thread torhu

On 18.01.2011 12:34, Richard Chamberlain wrote:

Hello,

I'm in the process of learning D, and to do so I'm converting some older code.

I need to print out the current local date and time, which is causing
some difficulties because std.date doesn't seem adequate in this
respect. I understand there is soon to be a replacement, std.datetime,
which I suspect will be much easier.

When are we likely to see a new release which includes std.datetime?

If not relatively soon I presume the easiest thing to do is to download
it myself and recompile the phobos library to include it. In which case
there seems to be already a std.datetime with different functionality,
is this used elsewhere in phobos? i.e. if I replace it with the new
std.datetime is that OK?


You could always use the C functions, if you import core.stdc.time.  The 
ctime and strftime functions should do the trick.


http://cplusplus.com/reference/clibrary/ctime/


about float double

2011-01-18 Thread spir

Hello,


Is there somewhere a (clear) doc about float/double internals?
Some more particuliar questions:

What is the internal bit layout? (mantissa, sign, exponent)

Can I assume the integral range is [-2^(m-1) .. 2^⁽m-1)-1], where m is 
the number of mantissa bits?


What are the values used to represent thingies like NaNs, inf, error? 
(Or are there not represented as values?)


How would you get a float's integral and fractional parts without 
performing arithmetic? (I think at bit ops, indeed)



Denis
_
vita es estrany
spir.wikidot.com



const vs immutable

2011-01-18 Thread Sean Eskapp
In cases where they are the same, for instance declaring:
const int x = oldX + 5;

vs

immutable int x = oldX + 5;

Or in non-class, non-array function parameters, does it make a difference
which is used?


Re: about float double

2011-01-18 Thread Ali Çehreli

spir wrote:

 Is there somewhere a (clear) doc about float/double internals?

A very good read is:

  http://digitalmars.com/d/2.0/d-floating-point.html

 Some more particuliar questions:

 What is the internal bit layout? (mantissa, sign, exponent)

IEEE floating point format. This page has links to different 
representations:


  http://en.wikipedia.org/wiki/Ieee_floating_point

Specifically:

  http://en.wikipedia.org/wiki/Single_precision_floating-point_format
  http://en.wikipedia.org/wiki/Double_precision_floating-point_format

 What are the values used to represent thingies like NaNs, inf, error?
 (Or are there not represented as values?)

They are available on the documents above.

 How would you get a float's integral and fractional parts without
 performing arithmetic? (I think at bit ops, indeed)

Here is a function with endianness issues that I had used with 
different types:


import std.stdio;

void display_bytes(T)(ref T variable)
{
const ubyte * begin = cast(ubyte*)variable;

writefln(type  : %s, T.stringof);
writefln(value : %s, variable);
writefln(address   : %s, begin);
writef(  representation: );

foreach (p; begin .. begin + T.sizeof) {
writef(%02x , *p);
}

writeln();
writeln();
}

void main()
{
auto d_nan = double.nan;
auto d_inf = double.infinity;
display_bytes(d_nan);
display_bytes(d_inf);
}

Ali


Re: const vs immutable

2011-01-18 Thread Jesse Phillips
Sean Eskapp Wrote:

 In cases where they are the same, for instance declaring:
 const int x = oldX + 5;
 
 vs
 
 immutable int x = oldX + 5;
 
 Or in non-class, non-array function parameters, does it make a difference
 which is used?

Use immutable, it documents the type better. And const items cannot be used as 
immutable parameters (value types don't have such restriction).


Re: std.container.Array/RefCounted(T) leaking memory?

2011-01-18 Thread %u
 That would be bug 3516, wouldn't it?

Huh... yes, it indeed would. Thanks for the link, I couldn't think of the right
keywords to search for. :)