Re: proper way to calculate toHash() for string

2015-06-30 Thread aki via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 19:36:24 UTC, Jacob Carlborg wrote: On 30/06/15 16:19, aki wrote: Please suggest me if anyone have an idea. You can use TypeInfo.getHash [1] to get the hash of a given value. Something like: string a = "foo"; typeid(a).getHash(&a) [1] http://dlang.org/phobos/ob

Adam Ruppe's COM library - calling COM object from dynamic code eg VBA

2015-06-30 Thread Laeeth Isharc via Digitalmars-d-learn
Hi. With a few changes, I have got the source working for the client and server code for hello. The COM object isn't recognised by dynamic languages such as Python and VBA, even after registering. I think I need to add type library fields in the registry. Any tips or sample code from some

Re: Best way to count character spaces.

2015-06-30 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 30, 2015 at 06:33:32PM +, Taylor Hillegeist via Digitalmars-d-learn wrote: > So I am aware that Unicode is not simple... I have been working on a boxes > like project http://boxes.thomasjensen.com/ > > it basically puts a pretty border around stdin characters. like so: >

Re: Multi-dimensional fixed arrays

2015-06-30 Thread Justin Whear via Digitalmars-d-learn
On Tue, 30 Jun 2015 21:02:37 +, DLearner wrote: > Out of curiosity, why can't D define a 2-dim array by something like: > int(2,1) foo; > > which defines two elements referred to as: > foo(0,0) and foo(1,0)? Work is being done on multidimensional slicing, see this thread: http://forum.dlang.o

Re: Pure delegate not quite pure?

2015-06-30 Thread Jesse Phillips via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 22:23:40 UTC, Tofu Ninja wrote: On Tuesday, 30 June 2015 at 22:05:43 UTC, Steven Schveighoffer wrote: Have you tried placing const on the function signature? i.e.: pure int delegate() const d = () const {... That's how you'd do it (I think, didn't test) if the deleg

Re: Pure delegate not quite pure?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Wednesday, 1 July 2015 at 00:13:36 UTC, Jesse Phillips wrote: On Tuesday, 30 June 2015 at 22:23:40 UTC, Tofu Ninja wrote: On Tuesday, 30 June 2015 at 22:05:43 UTC, Steven Schveighoffer wrote: Have you tried placing const on the function signature? i.e.: pure int delegate() const d = () cons

Array operations, dynamic arrays and length

2015-06-30 Thread ixid via Digitalmars-d-learn
int[] a = [1,1,1,1]; int[] b = [1,1,1,1]; int[] c; c[] = a[] - b[]; c.writeln; This outputs []. This feels wrong, it feels like something that should have exploded or set the length to 4. If the lengths of a and b are mismatched it throws an exception.

Re: goroutines vs vibe.d tasks

2015-06-30 Thread rsw0x via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 15:18:36 UTC, Jack Applegame wrote: Just creating a bunch (10k) of sleeping (for 100 msecs) goroutines/tasks. Compilers go: go version go1.4.2 linux/amd64 vibe.d: DMD64 D Compiler v2.067.1 linux/amd64, vibe.d 0.7.23 Code go: http://pastebin.com/2zBnGBpt vibe

Re: Pure delegate not quite pure?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 22:05:43 UTC, Steven Schveighoffer wrote: Have you tried placing const on the function signature? i.e.: pure int delegate() const d = () const {... That's how you'd do it (I think, didn't test) if the delegate context pointer was a class/struct. -Steve Nah, says

Re: Multi-dimensional fixed arrays

2015-06-30 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 21:02:39 UTC, DLearner wrote: On Tuesday, 30 June 2015 at 20:33:31 UTC, jmh530 wrote: On Tuesday, 30 June 2015 at 20:17:12 UTC, Justin Whear wrote: [...] I think this is a good explanation. Looking through http://dlang.org/arrays.html I see that the multidimension

Re: Pure delegate not quite pure?

2015-06-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/30/15 5:44 PM, Tofu Ninja wrote: On Tuesday, 30 June 2015 at 21:31:05 UTC, Steven Schveighoffer wrote: On 6/30/15 5:23 PM, Tofu Ninja wrote: On Sunday, 28 June 2015 at 10:19:05 UTC, anonymous wrote: [...] Is there any way to annotate the context as const? const x = 4 ;) But even if y

Re: Pure delegate not quite pure?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 22:23:40 UTC, Tofu Ninja wrote: On Tuesday, 30 June 2015 at 22:05:43 UTC, Steven Schveighoffer wrote: Have you tried placing const on the function signature? i.e.: pure int delegate() const d = () const {... That's how you'd do it (I think, didn't test) if the deleg

Re: Pure delegate not quite pure?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 21:31:05 UTC, Steven Schveighoffer wrote: On 6/30/15 5:23 PM, Tofu Ninja wrote: On Sunday, 28 June 2015 at 10:19:05 UTC, anonymous wrote: [...] Is there any way to annotate the context as const? const x = 4 ;) But even if you could annotate just the *reference*

Re: Template Declarations - Why not Template definitions?

2015-06-30 Thread WhatMeWorry via Digitalmars-d-learn
I was reading "D Templates: A Tutorial" by Philippe Sigaud which says: --- quote What is a Template? In the next chapters, you’ll see how to define function, struct and class templates. But before that, I’d like to introduce what a template really is, because this def

Re: Best way to count character spaces.

2015-06-30 Thread Rikki Cattermole via Digitalmars-d-learn
On 1/07/2015 6:33 a.m., Taylor Hillegeist wrote: So I am aware that Unicode is not simple... I have been working on a boxes like project http://boxes.thomasjensen.com/ it basically puts a pretty border around stdin characters. like so: /\ \ \_|Dif

Re: Template Declarations - Why not Template definitions?

2015-06-30 Thread anonymous via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 21:06:58 UTC, WhatMeWorry wrote: All the stuff I've read about templates always refers to them as template declarations. So with the following code segment: template codeBlockTemplate(T, U) { T a = 7; U b = 'z'; } codeBlockTemplate!(int, char); // error he

Re: goroutines vs vibe.d tasks

2015-06-30 Thread Laeeth Isharc via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 15:18:36 UTC, Jack Applegame wrote: Just creating a bunch (10k) of sleeping (for 100 msecs) goroutines/tasks. Compilers go: go version go1.4.2 linux/amd64 vibe.d: DMD64 D Compiler v2.067.1 linux/amd64, vibe.d 0.7.23 Code go: http://pastebin.com/2zBnGBpt vibe

Re: Multi-dimensional fixed arrays

2015-06-30 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 20:17:12 UTC, Justin Whear wrote: No. The order of braces when indexing is the opposite of the order when declaring. The declaration int [1][2] foo; reads innermost to outermost, "((int [1] ) [2])" When indexing foo, you index from outermost to innermost, so foo[

Re: Multi-dimensional fixed arrays

2015-06-30 Thread vladde via Digitalmars-d-learn
Oh, seems I should learn to refresh the page :)

Re: Pure delegate not quite pure?

2015-06-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/30/15 5:23 PM, Tofu Ninja wrote: On Sunday, 28 June 2015 at 10:19:05 UTC, anonymous wrote: [...] Is there any way to annotate the context as const? const x = 4 ;) But even if you could annotate just the *reference* as const, it doesn't stop foo from changing it as you did in the examp

Best way to count character spaces.

2015-06-30 Thread Taylor Hillegeist via Digitalmars-d-learn
So I am aware that Unicode is not simple... I have been working on a boxes like project http://boxes.thomasjensen.com/ it basically puts a pretty border around stdin characters. like so: /\ \ \_|Different all twisty a| |of in maze are you, |

Multi-dimensional fixed arrays

2015-06-30 Thread DLearner via Digitalmars-d-learn
Suppose: 'int [1][2] foo;' Probably I misunderstand, but TDPL seems to say that foo has two elements: foo[0][0] and foo[1][0] as opposed to two elements: foo[0][0] and foo[0][1] Is this correct?

Re: Multi-dimensional fixed arrays

2015-06-30 Thread vladde via Digitalmars-d-learn
I am pretty surprised, as the following code gives errors. void main(){ int [1][2] foo; foo[0][0] = 1; foo[0][1] = 2; foo[1][0] = 3; foo[1][1] = 4; } Those errors are: app.d(5): Error: array index 1 is out of bounds foo[0][0 .. 1] app.d(7): Error: array index 1 is out of bound

Template Declarations - Why not Template definitions?

2015-06-30 Thread WhatMeWorry via Digitalmars-d-learn
All the stuff I've read about templates always refers to them as template declarations. So with the following code segment: template codeBlockTemplate(T, U) { T a = 7; U b = 'z'; } codeBlockTemplate!(int, char); // error here Microsof's Visual Studio IDE tells me expected, ; found

Re: std.concurrent Tid vector initialization problem

2015-06-30 Thread Charles Hixson via Digitalmars-d-learn
On Sunday, 28 June 2015 at 09:59:29 UTC, Marc Schütz wrote: On Sunday, 28 June 2015 at 01:02:02 UTC, Charles Hixson wrote: I'm planning an application where a series of threads each ...gn. Does anyone have a better idea? (The rough estimate of the number of Tids is six, but that's likely to

Re: is it safe to call `GC.removeRange` in dtor?

2015-06-30 Thread rsw0x via Digitalmars-d-learn
On Saturday, 27 June 2015 at 21:53:33 UTC, ketmar wrote: is it safe to call `GC.removeRange` in dtor? i believe it should be safe, so one can perform various cleanups, but documentation says nothing about guarantees It's not documented. Afaik parts of the standard library depend on this behav

Re: Pure delegate not quite pure?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Sunday, 28 June 2015 at 10:19:05 UTC, anonymous wrote: [...] Is there any way to annotate the context as const?

Re: Multi-dimensional fixed arrays

2015-06-30 Thread DLearner via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 20:33:31 UTC, jmh530 wrote: On Tuesday, 30 June 2015 at 20:17:12 UTC, Justin Whear wrote: [...] I think this is a good explanation. Looking through http://dlang.org/arrays.html I see that the multidimensional array indexing is not particularly focused on (could be

Re: proper way to calculate toHash() for string

2015-06-30 Thread Jacob Carlborg via Digitalmars-d-learn
On 30/06/15 16:19, aki wrote: Please suggest me if anyone have an idea. You can use TypeInfo.getHash [1] to get the hash of a given value. Something like: string a = "foo"; typeid(a).getHash(&a) [1] http://dlang.org/phobos/object.html#.TypeInfo.getHash -- /Jacob Carlborg

Re: Nullable with reference types

2015-06-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/30/15 11:16 AM, Jonathan M Davis wrote: On Tuesday, 30 June 2015 at 00:02:38 UTC, Meta wrote: On Monday, 29 June 2015 at 19:29:37 UTC, sigod wrote: Hi, everyone. ``` import std.typecons : Nullable; class Test {} Nullable!Test test; assert(test.isNull); ``` Why does `Nullable` allowed t

Re: goroutines vs vibe.d tasks

2015-06-30 Thread Jack Applegame via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 17:37:38 UTC, Atila Neves wrote: Sleep will almost certainly pause and block the fiber. Vibe.d only switches between them when there's IO to be done or something else from the event loop. Sleep blocks the fiber, but not the event loop. Because it isn't core.thread.Th

Re: Multi-dimensional fixed arrays

2015-06-30 Thread Justin Whear via Digitalmars-d-learn
On Tue, 30 Jun 2015 20:09:50 +, DLearner wrote: > Suppose: > 'int [1][2] foo;' > > Probably I misunderstand, but TDPL seems to say that foo has two > elements: > foo[0][0] and foo[1][0] > > as opposed to two elements: > foo[0][0] and foo[0][1] > > Is this correct? No. The order of braces

Re: tkd - basic compilation problem

2015-06-30 Thread Alex Parrill via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 14:28:49 UTC, Paul wrote: Using dub I get this during linking: Building tkd-test ~master configuration "application", build type debug. Compiling using dmd... Linking... /usr/bin/ld: cannot find -ltcl /usr/bin/ld: cannot find -ltk ...any suggestions please? You n

Re: is it safe to call `GC.removeRange` in dtor?

2015-06-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/27/15 5:53 PM, ketmar wrote: is it safe to call `GC.removeRange` in dtor? i believe it should be safe, so one can perform various cleanups, but documentation says nothing about guarantees. Hm... I can't see any reason why it wouldn't be allowed. removeRange shouldn't allocate, so the one

Re: goroutines vs vibe.d tasks

2015-06-30 Thread anonymous via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 15:18:36 UTC, Jack Applegame wrote: Just creating a bunch (10k) of sleeping (for 100 msecs) goroutines/tasks. Compilers go: go version go1.4.2 linux/amd64 vibe.d: DMD64 D Compiler v2.067.1 linux/amd64, vibe.d 0.7.23 Code go: http://pastebin.com/2zBnGBpt vibe

Re: Static constructors guaranteed to run?

2015-06-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/26/15 6:00 PM, Tofu Ninja wrote: Also are static constructors in templated types guaranteed to run for every instantiation? I'd hazard to guess that the current compiler does run them, but that they probably aren't guaranteed to run by a sufficiently smart future compiler. Note, I stro

Re: Nullable with reference types

2015-06-30 Thread Meta via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 15:17:00 UTC, Jonathan M Davis wrote: I tend to think that it's incredibly stupid to use something like Nullable for a type that's already Nullable. Unfortunately, we're stuck with it as changing that would break code. It's just silly. If a type is already nullabl

Re: Bug or feature?

2015-06-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, 29 June 2015 at 14:28:06 UTC, anonymous wrote: On Monday, 29 June 2015 at 12:04:46 UTC, Jonathan M Davis wrote: You haven't declared an immutable constructor, so you can't construct an immutable Foo. That's not what's happening. Constructing an immutable Foo works just fine. Then

Re: Template mixin can not introduce overloads

2015-06-30 Thread SimonN via Digitalmars-d-learn
On Thursday, 25 June 2015 at 03:49:04 UTC, Tofu Ninja wrote: > Is this intended or is it a bug? On Thursday, 25 June 2015 at 03:53:58 UTC, Adam D. Ruppe wrote: Intended, the mixin template works on the basis of names. This The extra step is easy though: alias the name in: I would like to to t

Re: Replacement of std.stream

2015-06-30 Thread cym13 via Digitalmars-d-learn
On Sunday, 28 June 2015 at 05:04:48 UTC, DlangLearner wrote: I will convert a Java program into D. The original Java code is based on the class RandomeAccessFile which essentially defines a set of methods for read/write Int/Long/Float/String etc. The module std.stream seems to be a good fit for

Re: goroutines vs vibe.d tasks

2015-06-30 Thread Atila Neves via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 16:43:58 UTC, anonymous wrote: On Tuesday, 30 June 2015 at 15:18:36 UTC, Jack Applegame wrote: Just creating a bunch (10k) of sleeping (for 100 msecs) goroutines/tasks. Compilers go: go version go1.4.2 linux/amd64 vibe.d: DMD64 D Compiler v2.067.1 linux/amd64, v

Re: tkd - basic compilation problem

2015-06-30 Thread via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 15:25:27 UTC, Alex Parrill wrote: On Tuesday, 30 June 2015 at 14:28:49 UTC, Paul wrote: Using dub I get this during linking: Building tkd-test ~master configuration "application", build type debug. Compiling using dmd... Linking... /usr/bin/ld: cannot find -ltcl /u

Re: Nullable with reference types

2015-06-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 00:02:38 UTC, Meta wrote: On Monday, 29 June 2015 at 19:29:37 UTC, sigod wrote: Hi, everyone. ``` import std.typecons : Nullable; class Test {} Nullable!Test test; assert(test.isNull); ``` Why does `Nullable` allowed to be used with reference types (e.g. classes)

Re: goroutines vs vibe.d tasks

2015-06-30 Thread via Digitalmars-d-learn
Don't have go installed, but for me, the timings don't change very much depending on compiler and optimization flags: dub --compiler=dmd 13346ms dub --compiler=dmd --build=release 12348ms dub --compiler=ldc212082ms dub --compiler=ldc2 --build=release

proper way to calculate toHash() for string

2015-06-30 Thread aki via Digitalmars-d-learn
I would like to know proper way to calculate hash for given member fields. class Foo { int value; string str; override nothrow @safe size_t toHash() { // calculate hash based on field value. // value and str in this example. } } boo

Re: goroutines vs vibe.d tasks

2015-06-30 Thread Alex Parrill via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 15:18:36 UTC, Jack Applegame wrote: Just creating a bunch (10k) of sleeping (for 100 msecs) goroutines/tasks. Compilers go: go version go1.4.2 linux/amd64 vibe.d: DMD64 D Compiler v2.067.1 linux/amd64, vibe.d 0.7.23 Code go: http://pastebin.com/2zBnGBpt vibe

Re: proper way to calculate toHash() for string

2015-06-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 14:19:39 UTC, aki wrote: I would like to know proper way to calculate hash for given member fields. class Foo { int value; string str; override nothrow @safe size_t toHash() { // calculate hash based on field value.

goroutines vs vibe.d tasks

2015-06-30 Thread Jack Applegame via Digitalmars-d-learn
Just creating a bunch (10k) of sleeping (for 100 msecs) goroutines/tasks. Compilers go: go version go1.4.2 linux/amd64 vibe.d: DMD64 D Compiler v2.067.1 linux/amd64, vibe.d 0.7.23 Code go: http://pastebin.com/2zBnGBpt vibe.d: http://pastebin.com/JkpwSe47 go version build with "go b

Re: Nullable with reference types

2015-06-30 Thread via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 00:02:38 UTC, Meta wrote: It's a design mistake in Nullable. I would suggest that either never use Nullable with a type that already has a null value, or use the "overload" of Nullable that takes a null value, and set it to null. Example: Class Test {} alias Nullab

Re: Nullable with reference types

2015-06-30 Thread Meta via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 11:50:19 UTC, Marc Schütz wrote: On Tuesday, 30 June 2015 at 00:02:38 UTC, Meta wrote: It's a design mistake in Nullable. I would suggest that either never use Nullable with a type that already has a null value, or use the "overload" of Nullable that takes a null val

Re: tkd - basic compilation problem

2015-06-30 Thread Paul via Digitalmars-d-learn
Using dub I get this during linking: Building tkd-test ~master configuration "application", build type debug. Compiling using dmd... Linking... /usr/bin/ld: cannot find -ltcl /usr/bin/ld: cannot find -ltk ...any suggestions please?

Re: Bug or feature?

2015-06-30 Thread Jack Applegame via Digitalmars-d-learn
https://issues.dlang.org/show_bug.cgi?id=14751

Re: tkd - basic compilation problem

2015-06-30 Thread via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 12:58:21 UTC, Paul wrote: I downloaded the archive from https://github.com/nomad-software/tkd and files are same as in the git repo. Tcl/tk is installed on this machine (test 'hello world' script works fine) but I get this error when compiling the example from the g

Re: tkd - basic compilation problem

2015-06-30 Thread Paul via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 13:19:25 UTC, Marc Schütz wrote: If you don't want to use DUB, you need to download the other two packages from code.dlang.org and specifiy "-I/path/to/tcltk -I/path/to/x11 -I/path/to/tkd" in the DMD invocation. Thank you, I'll try that.

Re: tkd - basic compilation problem

2015-06-30 Thread via Digitalmars-d-learn
If you don't want to use DUB, you need to download the other two packages from code.dlang.org and specifiy "-I/path/to/tcltk -I/path/to/x11 -I/path/to/tkd" in the DMD invocation.

tkd - basic compilation problem

2015-06-30 Thread Paul via Digitalmars-d-learn
I downloaded the archive from https://github.com/nomad-software/tkd and files are same as in the git repo. Tcl/tk is installed on this machine (test 'hello world' script works fine) but I get this error when compiling the example from the github page: tkd/interpreter/tcl.d(16): Error: module

Re: tkd - basic compilation problem

2015-06-30 Thread Paul via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 13:22:43 UTC, Paul wrote: On Tuesday, 30 June 2015 at 13:19:25 UTC, Marc Schütz wrote: If you don't want to use DUB, you need to download the other two packages from code.dlang.org and specifiy "-I/path/to/tcltk -I/path/to/x11 -I/path/to/tkd" in the DMD invocation.

Re: Nullable with reference types

2015-06-30 Thread Meta via Digitalmars-d-learn
On Monday, 29 June 2015 at 19:29:37 UTC, sigod wrote: Hi, everyone. ``` import std.typecons : Nullable; class Test {} Nullable!Test test; assert(test.isNull); ``` Why does `Nullable` allowed to be used with reference types (e.g. classes)? P.S. I have experience with C#, where `Nullable` ca

Re: Why D doesn't have an equivalent to C#'s readonly?

2015-06-30 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 29 June 2015 at 20:12:12 UTC, Assembly wrote: I believe it's a design choice, if so, could someone explain why? is immutable better than C#'s readonly so that the readonly keyword isn't even needed? for example, I'd like to declare a member as readonly but I can't do it directly beca

Packing enums

2015-06-30 Thread qznc via Digitalmars-d-learn
I stumbled upon this interesting programming challenge [0], which imho should be possible to implement in D. Maybe someone here wants to try. Task: Given two enums with less than 256 states, pack them into one byte and provide convenient accessor functions. Something like this: enum X { A,

Why D doesn't have an equivalent to C#'s readonly?

2015-06-30 Thread Assembly via Digitalmars-d-learn
I believe it's a design choice, if so, could someone explain why? is immutable better than C#'s readonly so that the readonly keyword isn't even needed? for example, I'd like to declare a member as readonly but I can't do it directly because immutable create a new type (since it's a type specif

Re: Why D doesn't have an equivalent to C#'s readonly?

2015-06-30 Thread anonymous via Digitalmars-d-learn
On Monday, 29 June 2015 at 22:11:16 UTC, sigod wrote: `new immutable(MyClass)()` is invalid code. It's perfectly fine, actually.

Re: how do I create an array of objects as member of class?

2015-06-30 Thread Assembly via Digitalmars-d-learn
On Friday, 26 June 2015 at 22:14:56 UTC, Adam D. Ruppe wrote: On Friday, 26 June 2015 at 21:50:30 UTC, Assembly wrote: class Baa { Foo a = new Foo(); Foo b = new Foo(); Foo[] l = [a,b]; I wasn't aware about this. I'm used to have static only when I request so, like using static keyword

Re: Packing enums

2015-06-30 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 29 June 2015 at 22:05:47 UTC, qznc wrote: I stumbled upon this interesting programming challenge [0], which imho should be possible to implement in D. Maybe someone here wants to try. Task: Given two enums with less than 256 states, pack them into one byte and provide convenient ac

Re: Static constructors guaranteed to run?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Monday, 29 June 2015 at 11:36:42 UTC, ketmar wrote: it doesn't, afair, but it's quite natural. if user type was throwed out as unused, it would be very strange to insist on keeping it's initialization code. Personally I would be kinda pissed if the compiler did this, I expect the static ct

Re: Nullable with reference types

2015-06-30 Thread Gary Willoughby via Digitalmars-d-learn
On Monday, 29 June 2015 at 19:29:37 UTC, sigod wrote: Hi, everyone. ``` import std.typecons : Nullable; class Test {} Nullable!Test test; assert(test.isNull); ``` Why does `Nullable` allowed to be used with reference types (e.g. classes)? P.S. I have experience with C#, where `Nullable` ca

Nullable with reference types

2015-06-30 Thread sigod via Digitalmars-d-learn
Hi, everyone. ``` import std.typecons : Nullable; class Test {} Nullable!Test test; assert(test.isNull); ``` Why does `Nullable` allowed to be used with reference types (e.g. classes)? P.S. I have experience with C#, where `Nullable` cannot be used with reference types. And it sounds logic

Re: Why D doesn't have an equivalent to C#'s readonly?

2015-06-30 Thread sigod via Digitalmars-d-learn
On Monday, 29 June 2015 at 20:12:12 UTC, Assembly wrote: I believe it's a design choice, if so, could someone explain why? is immutable better than C#'s readonly so that the readonly keyword isn't even needed? for example, I'd like to declare a member as readonly but I can't do it directly beca

Re: Why D doesn't have an equivalent to C#'s readonly?

2015-06-30 Thread sigod via Digitalmars-d-learn
On Monday, 29 June 2015 at 22:22:46 UTC, anonymous wrote: On Monday, 29 June 2015 at 22:11:16 UTC, sigod wrote: `new immutable(MyClass)()` is invalid code. It's perfectly fine, actually. Yes, you're right. It seems I've mistyped `immutable` when was checking it with compiler.

Re: Setting um makefile for dmd

2015-06-30 Thread Orfeo via Digitalmars-d-learn
something like that can help? ``` run: all $(OUT) ```

Re: Typed Message Passing between D Processes

2015-06-30 Thread Nordlöw
On Monday, 29 June 2015 at 10:22:10 UTC, Atila Neves wrote: I guess I'm going to have benchmark this now... :) What about doing a memory profiling using DMD fresh builtin profiler of http://dpaste.dzfl.pl/17b0ed9c0204 ? I'm guessing the GC might give misguiding results as your testStruct

Re: Static constructors guaranteed to run?

2015-06-30 Thread via Digitalmars-d-learn
On Monday, 29 June 2015 at 11:36:42 UTC, ketmar wrote: it doesn't, afair, but it's quite natural. if user type was throwed out as unused, it would be very strange to insist on keeping it's initialization code. Yes, but I would instead expect that the static ctor prevents the type from becomin

Re: Bug or feature?

2015-06-30 Thread Daniel Kozák via Digitalmars-d-learn
On Mon, 29 Jun 2015 05:04:36 -0700 Jonathan M Davis via Digitalmars-d-learn wrote: > On Sunday, June 28, 2015 11:37:59 Jack Applegame via > Digitalmars-d-learn wrote: > > I don't see any reason why it should not compile. > > > > import std.array; > > import std.range; > > import std.algorithm; >

Re: Bug or feature?

2015-06-30 Thread anonymous via Digitalmars-d-learn
On Monday, 29 June 2015 at 12:04:46 UTC, Jonathan M Davis wrote: You haven't declared an immutable constructor, so you can't construct an immutable Foo. That's not what's happening. Constructing an immutable Foo works just fine.

Re: Bug or feature?

2015-06-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, June 28, 2015 11:37:59 Jack Applegame via Digitalmars-d-learn wrote: > I don't see any reason why it should not compile. > > import std.array; > import std.range; > import std.algorithm; > > class Foo { > } > > void main() { > auto result = iota(3).map!(i => new immutable Foo).array();

Re: Typed Message Passing between D Processes

2015-06-30 Thread Atila Neves via Digitalmars-d-learn
On Monday, 29 June 2015 at 08:45:15 UTC, Atila Neves wrote: On Sunday, 28 June 2015 at 17:02:42 UTC, Nordlöw wrote: On Friday, 26 June 2015 at 21:40:49 UTC, Atila Neves wrote: I'd have to benchmark it against something, but I'm pretty sure cerealed is fast. Faster than msgpack? I guess I'm

Re: Static constructors guaranteed to run?

2015-06-30 Thread via Digitalmars-d-learn
On Monday, 29 June 2015 at 02:07:57 UTC, ketmar wrote: On Sat, 27 Jun 2015 22:49:13 +, Tofu Ninja wrote: On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: 2. no. Hmm... any reason why? if instantiated template was not used in any code that makes into compiled binary, compiler

Setting um makefile for dmd

2015-06-30 Thread Namal via Digitalmars-d-learn
Hello, i get myself a nice makefile from here: https://gist.github.com/darkstalker/2221824 How can I modify it so that I can use the run option of dmd? I tried to add another compiler flag variable which would be only used with run but then it messed with -of$@ option and said it couldn't re

Re: Replacement of std.stream

2015-06-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, June 28, 2015 11:14:57 Baz via Digitalmars-d-learn wrote: > On Sunday, 28 June 2015 at 05:04:48 UTC, DlangLearner wrote: > > I will convert a Java program into D. The original Java code is > > based on the class RandomeAccessFile which essentially defines > > a set of methods for read/wr

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
On Mon, 29 Jun 2015 10:19:33 +, Marc Schütz wrote: > On Monday, 29 June 2015 at 02:07:57 UTC, ketmar wrote: >> On Sat, 27 Jun 2015 22:49:13 +, Tofu Ninja wrote: >> >>> On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: 2. no. >>> >>> Hmm... any reason why? >> >> if instantiat

Re: Porting from D1 to D2

2015-06-30 Thread ponce via Digitalmars-d-learn
On Sunday, 28 June 2015 at 21:26:52 UTC, Walter Bright wrote: On 6/28/2015 2:48 AM, ponce wrote: I don't quite get what code could be generating that reference, since I don't call format or toString on a Throwable. You can grep the .obj files for the symbol. Thanks. Fixed by upgrading. I th

Re: Typed Message Passing between D Processes

2015-06-30 Thread Atila Neves via Digitalmars-d-learn
On Sunday, 28 June 2015 at 17:02:42 UTC, Nordlöw wrote: On Friday, 26 June 2015 at 21:40:49 UTC, Atila Neves wrote: I'd have to benchmark it against something, but I'm pretty sure cerealed is fast. Faster than msgpack? I guess I'm going to have benchmark this now... :) Atila

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
p.s. also note that module can has several static ctors, i.e. this works fine: === z00.d === module z00; import std.stdio; static this () { writeln("ctor0"); } static this () { writeln("ctor1"); } === z01.d === module z01; import z00; void main () {} this prints: ctor0 ctor1 so you c

Re: generic cast(unshared) ?

2015-06-30 Thread tcak via Digitalmars-d-learn
On Sunday, 28 June 2015 at 23:42:47 UTC, Timothee Cour wrote: How would I cast away shared for a given expression? I can write it for a specific type but I'd like to have a generic way to do so. Also, Unqual doesn't help here. Normally, "cast()" removes "shared" from a type. BUT, sometimes i

Re: Bug or feature?

2015-06-30 Thread Adam D. Ruppe via Digitalmars-d-learn
I'd say bug, I think the array function is trying an optimization it shouldn't be trying for immutable classes.

Re: generic cast(unshared) ?

2015-06-30 Thread Timothee Cour via Digitalmars-d-learn
Note: should work with any types, eg: shared(T[])* => T[]* etc... On Sun, Jun 28, 2015 at 4:42 PM, Timothee Cour wrote: > How would I cast away shared for a given expression? > I can write it for a specific type but I'd like to have a generic way to > do so. > Also, Unqual doesn't help here. >

Re: Static constructors guaranteed to run?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Monday, 29 June 2015 at 02:31:18 UTC, ketmar wrote: yes. it doesn't do that now, afair, but i can't see any sense in running code that obviously does nothing, as it's owner is not used. module ctors was designed for such things -- i.e. to run some code on startup. if someone is doing some vi

Re: Porting from D1 to D2

2015-06-30 Thread Walter Bright via Digitalmars-d-learn
On 6/28/2015 2:48 AM, ponce wrote: I don't quite get what code could be generating that reference, since I don't call format or toString on a Throwable. You can grep the .obj files for the symbol.

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
On Sat, 27 Jun 2015 22:49:13 +, Tofu Ninja wrote: > On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: >> 2. no. > > Hmm... any reason why? if instantiated template was not used in any code that makes into compiled binary, compiler is free to remove it with all it's ctors. it may do

Re: Static constructors guaranteed to run?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Monday, 29 June 2015 at 02:07:57 UTC, ketmar wrote: On Sat, 27 Jun 2015 22:49:13 +, Tofu Ninja wrote: On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: 2. no. Hmm... any reason why? if instantiated template was not used in any code that makes into compiled binary, compiler

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
On Mon, 29 Jun 2015 03:10:44 +, Tofu Ninja wrote: > On Monday, 29 June 2015 at 02:31:18 UTC, ketmar wrote: >> yes. it doesn't do that now, afair, but i can't see any sense in >> running code that obviously does nothing, as it's owner is not used. >> module ctors was designed for such things --

generic cast(unshared) ?

2015-06-30 Thread Timothee Cour via Digitalmars-d-learn
How would I cast away shared for a given expression? I can write it for a specific type but I'd like to have a generic way to do so. Also, Unqual doesn't help here.

Re: std.concurrent Tid vector initialization problem

2015-06-30 Thread Ali Çehreli via Digitalmars-d-learn
On 06/28/2015 01:50 PM, Charles Hixson via Digitalmars-d-learn wrote: I'm planning an application where a series of threads each need to be aware of the Tids of all the others. The original thread did receive a couple of responses: http://forum.dlang.org/thread/mailman.5134.1435453322.7663.di

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
On Mon, 29 Jun 2015 02:19:54 +, Tofu Ninja wrote: > On Monday, 29 June 2015 at 02:07:57 UTC, ketmar wrote: >> On Sat, 27 Jun 2015 22:49:13 +, Tofu Ninja wrote: >> >>> On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: 2. no. >>> >>> Hmm... any reason why? >> >> if instantiated

std.concurrent Tid vector initialization problem

2015-06-30 Thread Charles Hixson via Digitalmars-d-learn
I'm planning an application where a series of threads each need to be aware of the Tids of all the others. The number won't be known at compile time, but that doesn't seem to change the design. All I've been able to come up with is a pair of loops, one to spawn the threads, and collect their

Re: how to iterate on Array?

2015-06-30 Thread aki via Digitalmars-d-learn
On Sunday, 28 June 2015 at 10:16:47 UTC, Marc Schütz wrote: On Saturday, 27 June 2015 at 17:43:13 UTC, aki wrote: But when I compile it by DMD 2.062 on Windows it says: testArray.d(5): Error: cannot infer argument types (line 5 is at "foreach(i, v; a[]) {" ) 2.062 is really ancient, we're abo

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
On Sat, 27 Jun 2015 22:49:13 +, Tofu Ninja wrote: > On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: >> 2. no. > > Hmm... any reason why? p.s. note that static ctors are *intended* to run in runtime, not in compile time. if compiler decides that some code is not required in runtim

Map Purity

2015-06-30 Thread jmh530 via Digitalmars-d-learn
My understanding of pure is that a function labeled pure can only include pure functions. I've been confused by the fact that a function calling map (like below) can be labeled pure without any problems. The only way I can rationalize it is that map really isn't a function, it's (if I'm underst

Re: Map Purity

2015-06-30 Thread jmh530 via Digitalmars-d-learn
On Sunday, 28 June 2015 at 16:15:31 UTC, Marc Schütz wrote: Secondly, `map` is indeed a template function, as you write. For templates functions, the compiler infers many properties, including purity. Thanks for the reply. Two follow ups: 1) Does labeling a template as pure matter if the co

Re: Map Purity

2015-06-30 Thread Xinok via Digitalmars-d-learn
On Sunday, 28 June 2015 at 15:55:51 UTC, jmh530 wrote: My understanding of pure is that a function labeled pure can only include pure functions. I've been confused by the fact that a function calling map (like below) can be labeled pure without any problems. The only way I can rationalize it is

  1   2   >