Re: D serialization temporary fixup?

2015-10-23 Thread Atila Neves via Digitalmars-d-learn
On Thursday, 22 October 2015 at 16:15:23 UTC, Shriramana Sharma 
wrote:
I wanted a D equivalent to: 
http://doc.qt.io/qt-5/qdatastream.html 
https://docs.python.org/3/library/pickle.html


and saw that one is under construction: 
http://wiki.dlang.org/Review/std.serialization


But till it's finalized, I'd just like to have a quick but 
reliable way to store real and int data types into a binary 
data file and read therefrom. Is there such a solution? The 
size of the data is fixed, but especially since I have real 
values, I'd like to not write to limited fixed decimal text 
format.


https://github.com/atilaneves/cerealed

Atila


Re: error detected at """ ch in unicode.C """ Library error?

2015-10-23 Thread rumbu via Digitalmars-d-learn
My opinion is to use the Tango's unicodedata.d module to obtain 
the unicode category, std.uni does not provide such functionality.


This module does not have any dependency, therefore you can just 
use it directly:


https://github.com/SiegeLord/Tango-D2/blob/d2port/tango/text/UnicodeData.d#L169


Mixin template parameter that is an undefined variable

2015-10-23 Thread tcak via Digitalmars-d-learn

[code]
mixin template Test(alias a){
int a;
}

void main(){
mixin Test!blah;
}
[/code]

Compiler says it doesn't know about "blah". My purpose is to
define the parameter as a variable. Is that possible?


Re: Mixin template parameter that is an undefined variable

2015-10-23 Thread John Colvin via Digitalmars-d-learn

On Friday, 23 October 2015 at 12:22:49 UTC, tcak wrote:

[code]
mixin template Test(alias a){
int a;
}

void main(){
mixin Test!blah;
}
[/code]

Compiler says it doesn't know about "blah". My purpose is to
define the parameter as a variable. Is that possible?


you would have to use a string.

mixin template Test(string a)
{
mixin(`int ` ~ a ~ `;`);
}

void main()
{
mixin Test!"blah";
mixin Test!q{blah2};
}


Default method implementations in interfaces?

2015-10-23 Thread pineapple via Digitalmars-d-learn
Is it possible to have default method implementations in 
interfaces à la Java in D? Or some equivalent that allows 
multiple inheritance without a bunch of identical copypasted 
method bodies?


Re: Default method implementations in interfaces?

2015-10-23 Thread Alex Parrill via Digitalmars-d-learn

On Friday, 23 October 2015 at 14:58:43 UTC, pineapple wrote:
Is it possible to have default method implementations in 
interfaces à la Java in D? Or some equivalent that allows 
multiple inheritance without a bunch of identical copypasted 
method bodies?


Use template mixins: http://dlang.org/template-mixin.html

interface MyInterface {
void foo();
int bar();
}

mixin template MyInterfaceDefaultImpl() {
void foo() {
// put code here
}
int bar() {
// put code here
}
}

class MyClass : MyInterface {
mixin MyInterfaceDefaultImpl!(); // Similar to inserting the 
body of `MyInterfaceDefaultImpl` at this point.
mixin MyOtherInterfaceDefaultImpl!(); // Can put any amount 
of them here.

}


Re: Default method implementations in interfaces?

2015-10-23 Thread Adam D. Ruppe via Digitalmars-d-learn

On Friday, 23 October 2015 at 14:58:43 UTC, pineapple wrote:
Is it possible to have default method implementations in 
interfaces à la Java in D? Or some equivalent that allows 
multiple inheritance without a bunch of identical copypasted 
method bodies?


Use a mixin template together with your interface. Here's an 
example from my book:


http://arsdnet.net/dcode/book/chapter_06/09/multiple_inheritance.d

https://www.packtpub.com/application-development/d-cookbook

Notice that there's default implementations for each interface, 
you mix them in to get it all and can override individual names 
in the class too.


Invalid assembler comparison

2015-10-23 Thread Etienne Cimon via Digitalmars-d-learn

Hello,

I've been trying to understand this for a while now:

https://github.com/etcimon/botan/blob/master/source/botan/math/mp/mp_core.d#L765

This comparison (looking at it with windbg during cmp operation) 
has these invalid values in the respective registers:


rdx: 9366584610601550696
r15: 8407293697099479287

When moving them into a ulong variable with a mov [R11], RDX 
before the CMP command, I get:

RDX: 7549031027420429441
R15: 17850297365717953652

Which are the valid values.

Any idea how these values could have gotten corrupted this way? 
Is there a signed integer conversion going on behind the scenes?


Re: Invalid assembler comparison

2015-10-23 Thread Etienne Cimon via Digitalmars-d-learn

On Friday, 23 October 2015 at 15:17:43 UTC, Etienne Cimon wrote:

Hello,

I've been trying to understand this for a while now:

https://github.com/etcimon/botan/blob/master/source/botan/math/mp/mp_core.d#L765

This comparison (looking at it with windbg during cmp 
operation) has these invalid values in the respective registers:


rdx: 9366584610601550696
r15: 8407293697099479287

When moving them into a ulong variable with a mov [R11], RDX 
before the CMP command, I get:

RDX: 7549031027420429441
R15: 17850297365717953652

Which are the valid values.

Any idea how these values could have gotten corrupted this way? 
Is there a signed integer conversion going on behind the scenes?


I found out that there was an integer conversion going on behind 
the scenes when using jnl. I had to use jnb


http://stackoverflow.com/questions/27284895/how-to-compare-a-signed-value-and-an-unsigned-value-in-x86-assembly


Re: Default method implementations in interfaces?

2015-10-23 Thread pineapple via Digitalmars-d-learn

On Friday, 23 October 2015 at 15:07:05 UTC, Alex Parrill wrote:

Use template mixins: http://dlang.org/template-mixin.html


On Friday, 23 October 2015 at 15:08:30 UTC, Adam D. Ruppe wrote:

Use a mixin template together with your interface.


Awesome, thanks!

No way, though, to unite declaration and implementation? Feels a 
little too much like endless header files to me.


Re: Default method implementations in interfaces?

2015-10-23 Thread Steven Schveighoffer via Digitalmars-d-learn

On 10/23/15 10:58 AM, pineapple wrote:

Is it possible to have default method implementations in interfaces à la
Java in D? Or some equivalent that allows multiple inheritance without a
bunch of identical copypasted method bodies?


If the idea is to have an implementation that *doesn't* get overridden, 
you can have final methods in an interface.


I know it's not what you asked for, but sometimes people may ask for 
something they know not realizing that something else may satisfy their 
needs :)


-Steve


Re: D serialization temporary fixup?

2015-10-23 Thread Shriramana Sharma via Digitalmars-d-learn
Shriramana Sharma wrote:

> I'd just like to have a quick but reliable way to
> store real and int data types into a binary data file and read therefrom.
> Is there such a solution?

Wow thank you people! Nice to know I can do rawWrite and also have other 
options. 

BTW is there a reason that either msgpack or cerealed are not made part of 
Phobos but developed separately?

-- 
Shriramana Sharma, Penguin #395953


OT: The Genius Famine

2015-10-23 Thread Laeeth Isharc via Digitalmars-d-learn
Since there are some highly creative and intelligent people here, 
self-selected to be those who enjoy working on problems that are 
intrinsically interesting, I thought one or two people might 
enjoy reading some extracts from a forthcoming book on the topic 
of creative accomplishment and the endogenous personality by 
Professor Bruce Charlton, Professor of Medicine at Newcastle 
University.


If it's not your bag, then no need to read it!

http://geniusfamine.blogspot.co.uk/

This book is about genius: what it is, what it does, where it 
comes from.[1]


And about geniuses: especially why there used to be so many and 
now there are so few; what was the effect of an era of geniuses, 
and what will be the consequences of our current Genius Famine.


This book describes the genius as an Endogenous personality; that 
is, a person of high intelligence combined with a personality 
driven from within, an ‘inner’ –orientated personality: that is, 
a dominated by the Creative Triad of (1) Innate high ability, (2) 
Inner motivation and (3) Intuitive thinking.


When high intelligence and this type of personality are 
confluent, a potential genius is the result. But to fulfil this 
potential the Endogenous personality must find and accept his own 
Destiny, and must undergo the trials and tribulations of a Quest 
before he is likely to be rewarded by an Illumination: a 
breakthrough.


Even then, the breakthrough must be noticed, understood, 
accepted, implemented by society at large; and we describe how 
past societies were much better at recognizing and making a place 
for the potential genius. Because the problem is that the 
Endogenous personality is usually an awkward and asocial 
character at best; and often an actively unpleasant person and a 
disruptive influence.


Geniuses are altruistic, in the sense that their work is 
primarily for the good of the group; and not for the usual social 
rewards such as status, money, sex, and popularity.


Therefore many geniuses need to be sustained in a long-term way; 
and their work demands careful attention and evaluation.


We argue that modern societies, by means both indirect and 
direct, have become hostile to genius and indifferent to the work 
of those relatively few remaining geniuses.


However, because the work of a genius is necessary and 
irreplaceable, we argue for a change of attitude. Modern society 
needs geniuses for its own survival in the face of unfamiliar, 
often unprecedented, threats. Therefore, we must in future do a 
better job of recognizing, sustaining and accepting guidance from 
as many geniuses of the highest quality that can be found.


Re: Overloading an imported function

2015-10-23 Thread Maxim Fomin via Digitalmars-d-learn
On Wednesday, 21 October 2015 at 12:05:27 UTC, Shriramana Sharma 
wrote:

import std.math;
real round(real val, int prec)
{
real pow = 10 ^^ prec;
return round(val * pow) / pow;
}

Trying to compile this I get:

foo.d(5): Error: function foo.round (real val, int prec) is not 
callable using argument types (real)


When I've imported std.math which contains round(real), why is 
the compiler complaining about not being able to call the 
overload function defined in *this* module?


I don't see anything in http://dlang.org/module.html that says 
I cannot define an overload of an imported function. Did I miss 
something?


My guess is that .round shadows math.round. But you can 
get desired behavior
by moving declaration of math.round inside scope of 
.round. This compiles:


real round(real val, int prec)
{
import std.math;
real pow = 10 ^^ prec;
return round(val * pow) / pow;
}




Re: error detected at """ ch in unicode.C """ Library error?

2015-10-23 Thread Charles Hixson via Digitalmars-d-learn



On 10/23/2015 04:33 AM, rumbu via Digitalmars-d-learn wrote:
My opinion is to use the Tango's unicodedata.d module to obtain the 
unicode category, std.uni does not provide such functionality.


This module does not have any dependency, therefore you can just use 
it directly:


https://github.com/SiegeLord/Tango-D2/blob/d2port/tango/text/UnicodeData.d#L169 



Thank you for confirming that std.uni doesn't implement that 
functionality, and for pointing to a Tango source.  That's probably the 
one I was originally remembering, but is Tango even still being 
maintained?  (OK, this very module was last updated 3 days ago.)


FWIW, in the past I've had a lot of trouble syncing Tango and D, to the 
point that I just dropped Tango, but as you say, this module doesn't 
seem to have any external dependencies, and it would be a faster 
solution to the problem, and perhaps it would work on the various 
control chars.


Still, I don't use this for heavy processing, so maintaining this 
external dependency would likely be more effort than it is worth...as 
long as I don't need to handle exotic chars in the control range.


If speed were my main consideration, I'd certainly give that solution a 
try.  The benefit of the solution that I proposed is that it's easy to 
understand given the phobos library.  And if I actually needed to handle 
exotic control chars, then it would be the only option I've seen.  
However the text I'm handling is *almost* all ASCII, so ... (occasional 
German, occasional footnotes in Greek, and occasional and usually 
isolated single ideograms in Chinese or some Japanese script, etc.  I 
don't think I've run across any Sanskrit yet.  etc.)


As such the solution I proposed is probably good enough, though if there 
were a Phobos level solution I'd prefer that.