Re: Format double in decimal notation without trailing zeros after the decimal point

2015-03-28 Thread Baz via Digitalmars-d-learn

On Friday, 27 March 2015 at 15:02:19 UTC, akaDemik wrote:

The task seemed very simple. But I'm stuck.
I want to:
  1234567890123.0 to "1234567890123"
  1.23 to "1.23"
  1.234567 to "1.2346".
With format string "%.4f" i get "1.2300" for 1.23.
With "%g" i get "1.23456789e+12" for "1234567890123.0".
I can not believe that it is not implemented. What did I miss?


such a format specifier does not exist.
[.number] means the minimal digits to display, so there is always 
at least `number` digits.


In your three examples, there is no common way to format them, 
you have to write you own helper:



struct YourExoticFormater
{
   private float _value;
   alias _value this;
   string toString()
   {
  // here you test the number and you choose how to diplay it.
  // for example if frac() returns 0 you return the string 
repr

  // esentation of the the integral part, etc...
  // this will work with to!string(), probably format %s (?), 
and the

  // write() functions family.
   }
}



Re: std.logger sharedLog usage

2015-03-28 Thread lobo via Digitalmars-d-learn

On Sunday, 29 March 2015 at 01:36:24 UTC, lobo wrote:

Hi,

I'm trying to use std.experimental.logger and I'd like the 
logf(), tracef() style functions to log to a file and stdout.
(note: I can use sharedLog.logf(), sharedLog.tracef(), but I 
prefer just logf())



So I did this:

shared static this() {
auto ml = new MultiLogger();
ml.insertLogger("stdout", new FileLogger(std.stdio.stdout));
ml.insertLogger("applog", new FileLogger("applog.txt"));
sharedLog = ml;
logf("This is a test"); // Doesn't work
}


Which doesn't work, so I'm wondering if it's possible to do 
what I want.



thanks,
lobo


Hmm, I should read code before posting. logf() etc. are using 
stdThreadLocalLog so this does what I want:


shared static this() {
 auto ml = new MultiLogger();
 ml.insertLogger("stdout", new FileLogger(std.stdio.stdout));
 ml.insertLogger("applog", new FileLogger("applog.txt"));
 stdThreadLocalLog = ml;
 logf("This is a test"); // works :)
}


Minor nitpick: This isn't clear in the docs of std.logger. 
Throughout sharedLog is referred to as the "default" logger, not 
stdThreadLocalLog.


Other than that I'm finding std.logger is really easy to use, 
nice work Phobosians!


bye,
lobo





std.logger sharedLog usage

2015-03-28 Thread lobo via Digitalmars-d-learn

Hi,

I'm trying to use std.experimental.logger and I'd like the 
logf(), tracef() style functions to log to a file and stdout.
(note: I can use sharedLog.logf(), sharedLog.tracef(), but I 
prefer just logf())



So I did this:

shared static this() {
auto ml = new MultiLogger();
ml.insertLogger("stdout", new FileLogger(std.stdio.stdout));
ml.insertLogger("applog", new FileLogger("applog.txt"));
sharedLog = ml;
logf("This is a test"); // Doesn't work
}


Which doesn't work, so I'm wondering if it's possible to do what 
I want.



thanks,
lobo


DerelictGL3.reload() returns wrong (?) GLVersion (GL32, should be 33)

2015-03-28 Thread Koi via Digitalmars-d-learn

Hello,

today i implemented OpenGL instancing, and it crashed when 
calling glVertexAttribDivisor (OpenGL 3.3).


So i checked DerelictGL3.reload() and it returned GLVersion.GL32, 
not GL33.


My graphic card (NVidia GT 240) should support GL33 and an OpenGL 
Extensions Viewer tool confirmed, that it supports OpenGL 3.3 
fully.


Did i overlook something?


Re: Associative Array of Const Objects?

2015-03-28 Thread Baz via Digitalmars-d-learn

On Friday, 27 March 2015 at 21:33:19 UTC, bitwise wrote:

class Test{}

void main()
{
const(Test)[string] tests;
tests["test"] = new Test();
}

This code used to work, but after upgrading to dmd 2.067, it no 
longer does.

--Error: cannot modify const expression tests["test"]

How do I insert an item into an associative array of const 
objects?


Generally speaking, you can insert an item in a constructor:
---
class Test{}

const (Test)[string] tests;

static this()
{
tests["test"] = new Test();
}

class Bar
{
immutable (Test)[string] tests2;
this()
{
this.tests2["test"] = new Test();
}
}

void main()
{
auto bar = new Bar;
}
---

The same problem already existed before 2.067 for AA with strings 
as value (string[string]), since they are immutable.


Re: Associative Array of Const Objects?

2015-03-28 Thread via Digitalmars-d-learn

On Friday, 27 March 2015 at 21:33:19 UTC, bitwise wrote:

class Test{}

void main()
{
const(Test)[string] tests;
tests["test"] = new Test();
}

This code used to work, but after upgrading to dmd 2.067, it no 
longer does.

--Error: cannot modify const expression tests["test"]

How do I insert an item into an associative array of const 
objects?


FWIW, it was changed in 
https://github.com/D-Programming-Language/dmd/pull/4148


It seems Kenji argues that the first assignment (like in your 
case) should be allowed, because it's supposed to be a 
construction rather than an assignment, but I fail to see how the 
compiler could detect this in the general case.


Re: Associative Array of Const Objects?

2015-03-28 Thread bearophile via Digitalmars-d-learn

bitwise:


class Test{}

void main()
{
const(Test)[string] tests;
tests["test"] = new Test();
}

This code used to work, but after upgrading to dmd 2.067, it no 
longer does.

--Error: cannot modify const expression tests["test"]

How do I insert an item into an associative array of const 
objects?


You meant to say "associative array with const objects as 
values". I think the short answer is that you can't. This is a 
breaking change, I think, it broke some of my code too. But 
perhaps something like Rebindable could be used.


Bye,
bearophile


Re: OT; Donald Knuth on beauty, efficiency, and the programmer as artist

2015-03-28 Thread Messenger via Digitalmars-d-learn

On Saturday, 28 March 2015 at 01:09:44 UTC, Laeeth Isharc wrote:

On Friday, 27 March 2015 at 11:33:39 UTC, Kagamin wrote:
Hmm... science exists only as long as we don't understand 
something, then it disappears and only knowledge remains. 
Looks like he talks about engineering, but calls it science.


One dismisses Knuth discussing the topic for which he is 
rightfully exceptionally well known at one's peril.  He may be 
wrong, but one should agonize before being sure this is the 
case and read widely and carefully about the topic first.  
Often in our society people resolve cognitive dissonance by 
dismissing the awkward perspective that causes such discomfort, 
when one would reach a fuller perspective by putting up with 
the discomfort for a while before attempting to reach 
intellectual closure.


I don't believe he is making the confusion you suggest.


Without touching on what Kagamin said, one must also take care 
not to fall to argumentum ab auctoritate.