Re: internal compiler error with immutable

2015-02-08 Thread ketmar via Digitalmars-d-learn
On Sat, 07 Feb 2015 09:23:42 -0800, H. S. Teoh via Digitalmars-d-learn wrote: On Sat, Feb 07, 2015 at 02:35:13PM +, Danny via Digitalmars-d-learn wrote: [...] cut- gdc A.d cc1d: ../../src/gcc/d/dfrontend/statement.c:293:

Re: Better native D 2D graphics library?

2015-02-08 Thread Gan via Digitalmars-d-learn
On Sunday, 8 February 2015 at 09:52:50 UTC, Namespace wrote: On Sunday, 8 February 2015 at 01:39:19 UTC, Gan wrote: On Saturday, 7 February 2015 at 23:29:01 UTC, Namespace wrote: On Saturday, 7 February 2015 at 22:09:03 UTC, Gan wrote: Is there a better D graphics library in the works? I'm

Re: Fun with floating point

2015-02-08 Thread ketmar via Digitalmars-d-learn
On Sat, 07 Feb 2015 21:33:46 +, Kenny wrote: The above code snippet works correctly when I use LDC compiler (it finds expected 'f' value and prints it to console). I'm wondering is it a bug in DMD? nope, this is a bug in your code. compiler (by the specs) is free to perform intermediate

Re: internal compiler error with immutable

2015-02-08 Thread Ali Çehreli via Digitalmars-d-learn
On 02/07/2015 06:35 AM, Danny wrote: I'm trying to use immutable class instances and that seems to be really difficult. You are not alone. :) Just some reminders: - immutable is a requirement that may not be usable with every type. - immutable string foo() {} is a member function that

Re: Fun with floating point

2015-02-08 Thread Kenny via Digitalmars-d-learn
nope, this is a bug in your code. compiler (by the specs) is free to perform intermediate calculations with any precision that is not lower than a highest used type (i.e. not lower that `float`'s one for `while` condition (`f + eps != f`). it may be even infinite precision, so your code may

Re: Fun with floating point

2015-02-08 Thread ketmar via Digitalmars-d-learn
On Sun, 08 Feb 2015 09:05:30 +, Kenny wrote: Thanks, it's clear now. I still have one question in the above post, I would appreciate if you check it too. i've seen that, but i don't know the answer, sorry. here we have to summon Walter to explain what his intentions was, how it should

Re: Fun with floating point

2015-02-08 Thread Kenny via Digitalmars-d-learn
For example, according to IEEE-754 specification if we work with 32bit floating point numbers (floats in D) then the following pseudo code prints 'Works'. F32 f = 16777216.0f; F32 f2 = f + 0.1f; if is_the_same_binary_presentation(f, f2) Print(Works); As I understand D does not guarantee

Re: Fun with floating point

2015-02-08 Thread via Digitalmars-d-learn
On Sunday, 8 February 2015 at 09:19:08 UTC, Kenny wrote: For example, according to IEEE-754 specification if we work with 32bit floating point numbers (floats in D) then the following pseudo code prints 'Works'. F32 f = 16777216.0f; F32 f2 = f + 0.1f; if is_the_same_binary_presentation(f, f2)

Re: Fun with floating point

2015-02-08 Thread Kenny via Digitalmars-d-learn
i think you are mixing two things here. IEEE doesn't specify which internal representation compilers should use, it only specifies the results for chosen representation. so if D specs states that `float` calculations are always performing with `float` precision (and specs aren't), your sample

Re: internal compiler error with immutable

2015-02-08 Thread Ali Çehreli via Digitalmars-d-learn
On 02/07/2015 06:35 AM, Danny wrote: What I'm trying to do is save space by putting often-used Attrs into an array and just compressing references to those into 1 Byte in the other data structures where it's used (these other data structures are not thread-local). The following is based on

Re: Better native D 2D graphics library?

2015-02-08 Thread Namespace via Digitalmars-d-learn
On Sunday, 8 February 2015 at 01:39:19 UTC, Gan wrote: On Saturday, 7 February 2015 at 23:29:01 UTC, Namespace wrote: On Saturday, 7 February 2015 at 22:09:03 UTC, Gan wrote: Is there a better D graphics library in the works? I'm using SFML(which is very easy and has lots of features) but it

Re: Fun with floating point

2015-02-08 Thread Kenny via Digitalmars-d-learn
There is no right or wrong when you compare floating point values for equality (and inequality) unless those values can be represented exactly in the machine. 1.0 is famously not representable exactly. (It is similar to how 1/3 cannot be represented in the decimal system.) Here I tested one

Re: How to write asia characters on console?

2015-02-08 Thread Lave Zhang via Digitalmars-d-learn
On Sunday, 8 February 2015 at 06:26:38 UTC, Ali Çehreli wrote: On 02/07/2015 09:57 PM, Lave Zhang wrote: Hi, My first D program is like this: --- import std.stdio; void main(string[] args) { dstring s1 = hello你好d; writeln(s1); }

Re: Fun with floating point

2015-02-08 Thread ketmar via Digitalmars-d-learn
On Sun, 08 Feb 2015 09:19:06 +, Kenny wrote: I asked more about this case: float f = 16777216.0f; if (f == f + 1.0f) writeln(Works); Although all operands are 32bit FP the result is not guaranteed to be equal to the result for FP32 computations as specified by IEEE-754. i think you

Re: Fun with floating point

2015-02-08 Thread via Digitalmars-d-learn
Also note that denormal numbers is an issue, e.g. D assumes that they are always supported, I think. Which frequently is not the case...

Re: strange work of GC

2015-02-08 Thread FG via Digitalmars-d-learn
On 2015-02-08 at 06:36, Mike Parker wrote: On 2/8/2015 11:32 AM, FG wrote: On 2015-02-08 at 01:20, Mike Parker wrote: In your case, forget destructors and the destroy method. Just implement a common method on all of your objects that need cleanup (perhaps name it 'terminate') and call that.

Re: internal compiler error with immutable

2015-02-08 Thread Danny via Digitalmars-d-learn
Hi Ketmar, Hi Ali, thank you! On Sunday, 8 February 2015 at 09:42:14 UTC, Ali Çehreli wrote: spawn(user, cucs, ubyte(3)); ^to! Other than that, it works. (The Attributes are basically literal constants but the library cannot know which are used in a given

Re: Classes and @disable this()

2015-02-08 Thread Rene Zwanenburg via Digitalmars-d-learn
On Sunday, 8 February 2015 at 16:28:21 UTC, fra wrote: On Sunday, 8 February 2015 at 16:22:36 UTC, fra wrote: Missclick... Anywya: class Something { @disable this(); this(int i) {} } produces an undefined reference error. I guess it has to do with classes implicitly inheriting from

Classes and @disable this()

2015-02-08 Thread fra via Digitalmars-d-learn
I just realized that you cannot define a disabled default constructor for classes: writing code like this will give a linker error class Something {

Re: why GC not work?

2015-02-08 Thread FG via Digitalmars-d-learn
On 2015-02-08 at 15:56, mzf wrote: On Saturday, 7 February 2015 at 06:08:39 UTC, ketmar wrote: On Sat, 07 Feb 2015 04:30:07 +, Safety0ff wrote: False pointers, current GC is not precise. not only that. constantly allocating big chunks of memory will inevitably lead to OOM due to

Re: Classes and @disable this()

2015-02-08 Thread fra via Digitalmars-d-learn
On Sunday, 8 February 2015 at 16:22:36 UTC, fra wrote: Missclick... Anywya: class Something { @disable this(); this(int i) {} } produces an undefined reference error. I guess it has to do with classes implicitly inheriting from Object, and Object defining a this(), and @disable telling

Re: Classes and @disable this()

2015-02-08 Thread bearophile via Digitalmars-d-learn
fra: However making it a compiler error would be far, far better I think this can be filed in Bugzilla as diagnostic enhancement: class Foo { @disable this(); this(int i) {} } void main() {} Bye, bearophile

Re: why GC not work?

2015-02-08 Thread safety0ff via Digitalmars-d-learn
On Sunday, 8 February 2015 at 16:23:44 UTC, FG wrote: 2. auto buf = new byte[](1024*1024*100); now the gc can't free this buf. can i free it by manual? Yes. import core.memory; GC.free(buf.ptr); // and don't use buf afterwards That won't work, see:

Re: why GC not work?

2015-02-08 Thread FG via Digitalmars-d-learn
On 2015-02-08 at 19:15, safety0ff wrote: On Sunday, 8 February 2015 at 16:23:44 UTC, FG wrote: 2. auto buf = new byte[](1024*1024*100); now the gc can't free this buf. can i free it by manual? Yes. import core.memory; GC.free(buf.ptr); // and don't use buf afterwards That

Re: How to write asia characters on console?

2015-02-08 Thread mzfhhhh via Digitalmars-d-learn
Thanks, my problem has been solved:) --- import std.stdio; import core.stdc.wchar_; extern(C) int setlocale(int, char*); static this() { fwide(core.stdc.stdio.stdout, 1); setlocale(0, cast(char*)china); } int main(string[] args) { string s1 =

Re: Better native D 2D graphics library?

2015-02-08 Thread Namespace via Digitalmars-d-learn
Let me hear what comes out. ;)

Re: Fast array copy. SIMD manual or automatic?

2015-02-08 Thread fra via Digitalmars-d-learn
On Saturday, 7 February 2015 at 06:30:32 UTC, tcak wrote: I have two char arrays at the size of 16KB. I will copy a part of data between them again and again. arrayA[0 .. dataLen] = arrayB[0 .. dataLen]; Does the compiler generate code that uses SIMD operations (128-bits memory copy)

Re: why GC not work?

2015-02-08 Thread mzfhhhh via Digitalmars-d-learn
On Saturday, 7 February 2015 at 06:08:39 UTC, ketmar wrote: On Sat, 07 Feb 2015 04:30:07 +, Safety0ff wrote: False pointers, current GC is not precise. not only that. constantly allocating big chunks of memory will inevitably lead to OOM due to current GC design. you can check it with

Rational of some DMD decisions

2015-02-08 Thread Robin via Digitalmars-d-learn
Hiho, as I am currently very insterested in compiler implementation I often look into the DMD github and look how things are done there. Often I find myself curious about things at first but find out the rational behind certain implementation decisions. One thing I can't figure out is the

Template constructor in a non-template struct.

2015-02-08 Thread ChrisG via Digitalmars-d-learn
Hi, I couldn't find information about problem I'm having. This builds: enum { Option1, Option2 } struct boring { this(int Opt = Option1)(int arg1, int arg2) { ... } } However, I can't figure out how to instantiate that constructor. When I call it like this: auto a = boring(1, 2); The

Re: Template constructor in a non-template struct.

2015-02-08 Thread bearophile via Digitalmars-d-learn
ChrisG: I don't really understand how I'd differentiate a constructor template from a class/struct template. One solution is to use a template struct (struct/class names start with an upper case in D, while typed enum members usually start with a lower case): enum E { option1, option2 }

Re: why GC not work?

2015-02-08 Thread safety0ff via Digitalmars-d-learn
On Sunday, 8 February 2015 at 18:43:18 UTC, FG wrote: On 2015-02-08 at 19:15, safety0ff wrote: That won't work, see: http://forum.dlang.org/thread/uankmwjejsitmlmrb...@forum.dlang.org Perhaps it was fixed in DMD 2.066.1, because this works for me just fine: Here's the link I couldn't

Re: Classes and @disable this()

2015-02-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, February 08, 2015 17:51:09 bearophile via Digitalmars-d-learn wrote: fra: However making it a compiler error would be far, far better I think this can be filed in Bugzilla as diagnostic enhancement: class Foo { @disable this(); this(int i) {} } void main() {} The

Re: Template constructor in a non-template struct.

2015-02-08 Thread ChrisG via Digitalmars-d-learn
Thanks bearophile. Your first suggestion about making the struct a template is something I considered. However, because of all the code I've already written that approach would force me to use inheritance or convert a ton of functions to templates. Ick. The __ctor syntax looks like the answer

primitive type variables not nullable ?

2015-02-08 Thread Venkat Akkineni via Digitalmars-d-learn
colors = [ black : నలుపు, white : తెలుపు, red : యెరుపు, green : పచ్చ, blue: నీలం ]; writefln(Before: ); writeln(colors); colors = null;

Static method of inner class needs this

2015-02-08 Thread rumbu via Digitalmars-d-learn
class Outer { class Inner { static Inner createInner() { return new Inner(); //need 'this' to access member this } } } Is this a bug? If Inner is not nested, it works as expected: class Inner { static Inner createInner() {

parse string as char

2015-02-08 Thread Timothee Cour via Digitalmars-d-learn
Is there a simple way to parse a string as a char? eg: unittest{ assert(parseChar(`a`)=='a'); assert(parseChar(`\n`)=='\n'); //NOTE: I'm looking at `\n` not \n // should also work with other forms of characters, see http://dlang.org/lex.html } Note, std.conv.to doesn't work (`\n`.to!char

Re: Better native D 2D graphics library?

2015-02-08 Thread uri via Digitalmars-d-learn
On Saturday, 7 February 2015 at 23:29:01 UTC, Namespace wrote: On Saturday, 7 February 2015 at 22:09:03 UTC, Gan wrote: Is there a better D graphics library in the works? I'm using SFML(which is very easy and has lots of features) but it seems to use a lot of ram(if you leave it running for a

Re: Rational of some DMD decisions

2015-02-08 Thread Robin via Digitalmars-d-learn
Thank you for your reply. I didn't know that it isn't possible to overload the post-inc and decrement operators in Dlang but I think I don't even miss this feature if pre-inc/dec is still available. =)

Re: primitive type variables not nullable ?

2015-02-08 Thread bearophile via Digitalmars-d-learn
Tobias Pankrath: Check for null with (x is null) not via printing to stdout. In most cases instead of checking dynamic arrays for null, it's better to use std.array.empty. Bye, bearophile

Re: appender!(string[]).put(string) doesn't work

2015-02-08 Thread David Held via Digitalmars-d-learn
On 2/8/2015 4:09 PM, David Held wrote: auto data = appender!(string[]); ... data.put(someString); [...] Never mind. someString is actually the result of stdin.byLine(), which returns a char[], not a string. I didn't notice this until just now. .idup fixes this just fine

Re: Rational of some DMD decisions

2015-02-08 Thread Ali Çehreli via Digitalmars-d-learn
On 02/08/2015 01:05 PM, Robin wrote: the postfix inc and decrement expressions are inherited from BinExpr (binary expression) which define their second expression to be an integer expression with a value of 1. Post-increment cannot be overloaded in D. It is always implemented in terms of

appender!(string[]).put(string) doesn't work

2015-02-08 Thread David Held via Digitalmars-d-learn
auto data = appender!(string[]); ... data.put(someString); source\colony.d(360): Error: template std.array.Appender(string[]).Appender.put does not match any function template declaration. Candidates are: D:\D\dmd2\windows\bin\..\..\src\phobos\std\array.d(2251):

Re: primitive type variables not nullable ?

2015-02-08 Thread Venkat Akkineni via Digitalmars-d-learn
Never mind, stupid question I realize, would delete it if I could. http://stackoverflow.com/questions/11047276/null-for-primitive-data-types

Re: parse string as char

2015-02-08 Thread Rikki Cattermole via Digitalmars-d-learn
On 9/02/2015 3:40 p.m., Timothee Cour via Digitalmars-d-learn wrote: Is there a simple way to parse a string as a char? eg: unittest{ assert(parseChar(`a`)=='a'); assert(parseChar(`\n`)=='\n'); //NOTE: I'm looking at `\n` not \n // should also work with other forms of characters, see

Re: primitive type variables not nullable ?

2015-02-08 Thread Tobias Pankrath via Digitalmars-d-learn
On Sunday, 8 February 2015 at 23:13:33 UTC, Venkat Akkineni wrote: Never mind, stupid question I realize, would delete it if I could. http://stackoverflow.com/questions/11047276/null-for-primitive-data-types Check for null with (x is null) not via printing to stdout.