Re: Parameter storage class 'in' transitive like 'const'?

2015-05-03 Thread Jakob Ovrum via Digitalmars-d-learn
On Sunday, 3 May 2015 at 05:20:34 UTC, Ali Çehreli wrote: We know that 'in' is "equivalent to const scope": http://dlang.org/function.html#parameters So, the constness of 'in' is transitive as well, right? Ali Of course, there's no concept of non-transitive const in D: struct S { char

Re: Parameter storage class 'in' transitive like 'const'?

2015-05-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, May 02, 2015 22:20:33 Ali Çehreli via Digitalmars-d-learn wrote: > We know that 'in' is "equivalent to const scope": > >http://dlang.org/function.html#parameters > > So, the constness of 'in' is transitive as well, right? Of course. in is identical to const scope. It doesn't intro

std.random question

2015-05-03 Thread tired_eyes via Digitalmars-d-learn
Feels pretty silly, but I can't compile this: import std.random; auto i = uniform(0, 10); DMD spits this: /usr/include/dmd/phobos/std/random.d(1188): Error: static variable initialized cannot be read at compile time /usr/include/dmd/phobos/std/random.d(1231):called from here: rndGen

Re: std.random question

2015-05-03 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 3 May 2015 at 08:42:57 UTC, tired_eyes wrote: Feels pretty silly, but I can't compile this: import std.random; auto i = uniform(0, 10); DMD spits this: /usr/include/dmd/phobos/std/random.d(1188): Error: static variable initialized cannot be read at compile time /usr/include/dmd/p

Re: std.random question

2015-05-03 Thread tired_eyes via Digitalmars-d-learn
On Sunday, 3 May 2015 at 08:48:52 UTC, Dennis Ritchie wrote: On Sunday, 3 May 2015 at 08:42:57 UTC, tired_eyes wrote: Feels pretty silly, but I can't compile this: import std.random; auto i = uniform(0, 10); DMD spits this: /usr/include/dmd/phobos/std/random.d(1188): Error: static variable

Re: std.random question

2015-05-03 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 3 May 2015 at 09:04:07 UTC, tired_eyes wrote: On Sunday, 3 May 2015 at 08:48:52 UTC, Dennis Ritchie wrote: On Sunday, 3 May 2015 at 08:42:57 UTC, tired_eyes wrote: Feels pretty silly, but I can't compile this: import std.random; auto i = uniform(0, 10); DMD spits this: /usr/incl

Re: std.random question

2015-05-03 Thread tired_eyes via Digitalmars-d-learn
Hmmm. hap.random from http://code.dlang.org/packages/hap behaves exactly the same.

Re: std.random question

2015-05-03 Thread biozic via Digitalmars-d-learn
On Sunday, 3 May 2015 at 09:28:40 UTC, Dennis Ritchie wrote: On Sunday, 3 May 2015 at 09:04:07 UTC, tired_eyes wrote: On Sunday, 3 May 2015 at 08:48:52 UTC, Dennis Ritchie wrote: On Sunday, 3 May 2015 at 08:42:57 UTC, tired_eyes wrote: Feels pretty silly, but I can't compile this: import std

Re: std.random question

2015-05-03 Thread tired_eyes via Digitalmars-d-learn
import std.random; struct Mystruct { int id; static opCall() { Mystruct s; s.id = uniform(0, 10); return s; } } void main() { auto s = Mystruct(); // whatever } --- This make sense, thant you for the e

Re: How to I translate this C++ structure/array

2015-05-03 Thread anonymous via Digitalmars-d-learn
On Sunday, 3 May 2015 at 02:31:51 UTC, WhatMeWorry wrote: On Saturday, 2 May 2015 at 22:36:29 UTC, anonymous wrote: [...] [1] `Vertex triangle[6]` works, but please don't do that. Thanks. I assume you would prefer I use triangle[] but with OpenGL calls the dynamic arrays don't work. But may

Is it safe to reset HOLD fiber?

2015-05-03 Thread Dzugaru via Digitalmars-d-learn
Documentation says "This fiber must be in state TERM." but in the core.thread I see In contract only on reset without parameters (bug maybe?) and with HOLD condition too: "assert( m_state == State.TERM || m_state == State.HOLD );" Does that mean its ok to reset the fiber if I'm not using things

Re: Is it safe to reset HOLD fiber?

2015-05-03 Thread Dzugaru via Digitalmars-d-learn
Just did another test and it seems its not safe at all. Reusing the fibers with reset without properly exiting the function leads to eventual stack overflow.

Re: Is it safe to reset HOLD fiber?

2015-05-03 Thread Martin Nowak via Digitalmars-d-learn
On Sunday, 3 May 2015 at 12:42:23 UTC, Dzugaru wrote: Just did another test and it seems its not safe at all. Reusing the fibers with reset without properly exiting the function leads to eventual stack overflow. It won't cleanup the old stack, so it may leak resources. It will properly reset

Re: Reading bzipped files

2015-05-03 Thread via Digitalmars-d-learn
On Saturday, 2 May 2015 at 20:37:44 UTC, tom wrote: i use Stephan Schiffels code from http://forum.dlang.org/thread/djhteyhpcnaskpabx...@forum.dlang.org?page=2 See polished version at: https://github.com/nordlow/justd/blob/master/zio.d

Re: Is it safe to reset HOLD fiber?

2015-05-03 Thread Martin Nowak via Digitalmars-d-learn
On Sunday, 3 May 2015 at 12:33:36 UTC, Dzugaru wrote: Documentation says "This fiber must be in state TERM." but in the core.thread I see In contract only on reset without parameters (bug maybe?) and with HOLD condition too: "assert( m_state == State.TERM || m_state == State.HOLD );" Does that

Re: Ada to D - an array for storing values of each of the six bits which are sufficient

2015-05-03 Thread Martin Nowak via Digitalmars-d-learn
On Friday, 1 May 2015 at 23:22:31 UTC, Dennis Ritchie wrote: Maybe someone will show a primitive packed array. I really can not imagine how to do it on D. Look at BitArray for an example https://github.com/D-Programming-Language/phobos/blob/12187d7be8b15b2f5f8ff6889cdb5ea3afb93dd1/std/bitmanip

Re: Merging one Array with Another

2015-05-03 Thread via Digitalmars-d-learn
On Saturday, 2 May 2015 at 04:08:04 UTC, Ali Çehreli wrote: Interesting idea. I have defined a simple algorithm below to see how it could work (my skipped() function instead of uniq()). That's a bit above my current D experience to decide. What about just tweaking uniq() for now to propagate S

Re: A slice can lose capacity simply by calling a function

2015-05-03 Thread Andrew Godfrey via Digitalmars-d-learn
I really don't think that it's an issue in general, but if you do want to guarantee that nothing affects the capacity of your array, then you're going to need to either wrap all access to it I agree with everything Jonathan said in both threads EXCEPT that this is not an issue. The syntax

Re: Merging one Array with Another

2015-05-03 Thread Ali Çehreli via Digitalmars-d-learn
On 05/03/2015 07:56 AM, "Per =?UTF-8?B?Tm9yZGzDtnci?= " wrote: On Saturday, 2 May 2015 at 04:08:04 UTC, Ali Çehreli wrote: Interesting idea. I have defined a simple algorithm below to see how it could work (my skipped() function instead of uniq()). That's a bit above my current D experience to

Re: How to I translate this C++ structure/array

2015-05-03 Thread WhatMeWorry via Digitalmars-d-learn
On Sunday, 3 May 2015 at 10:56:44 UTC, anonymous wrote: On Sunday, 3 May 2015 at 02:31:51 UTC, WhatMeWorry wrote: On Saturday, 2 May 2015 at 22:36:29 UTC, anonymous wrote: [...] [1] `Vertex triangle[6]` works, but please don't do that. Thanks. I assume you would prefer I use triangle[] but w

Re: How to I translate this C++ structure/array

2015-05-03 Thread WhatMeWorry via Digitalmars-d-learn
On Sunday, 3 May 2015 at 10:56:44 UTC, anonymous wrote: On Sunday, 3 May 2015 at 02:31:51 UTC, WhatMeWorry wrote: On Saturday, 2 May 2015 at 22:36:29 UTC, anonymous wrote: [...] [1] `Vertex triangle[6]` works, but please don't do that. Thanks. I assume you would prefer I use triangle[] but w

Re: A slice can lose capacity simply by calling a function

2015-05-03 Thread Meta via Digitalmars-d-learn
On Sunday, 3 May 2015 at 15:21:17 UTC, Andrew Godfrey wrote: I really don't think that it's an issue in general, but if you do want to guarantee that nothing affects the capacity of your array, then you're going to need to either wrap all access to it I agree with everything Jonathan said i

UDA and ReturnType!(__traits...) doesn't work

2015-05-03 Thread filcuc via Digitalmars-d-learn
Hi all, i'm working in the generation of the code but i'm failing in extracting a function return type when invoking the ReturnType!(T) type trait and mixing it with __traits(getMember) function. Can anyone help me? or explaining what is happenning? i've created a gist here: https://gist.gith

Re: Ada to D - an array for storing values of each of the six bits which are sufficient

2015-05-03 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 3 May 2015 at 14:49:55 UTC, Martin Nowak wrote: On Friday, 1 May 2015 at 23:22:31 UTC, Dennis Ritchie wrote: Maybe someone will show a primitive packed array. I really can not imagine how to do it on D. Look at BitArray for an example https://github.com/D-Programming-Language/phobo

Classes. C++ to D

2015-05-03 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, How can I rewrite this code to the D? - #include #include class A { public: std::string a() { return std::string("foo"); } }; class B { public: std::string b(){ return std::string("bar"); } }; class C : public A, public B {}; int main

Re: UDA and ReturnType!(__traits...) doesn't work

2015-05-03 Thread Meta via Digitalmars-d-learn
On Sunday, 3 May 2015 at 17:22:00 UTC, filcuc wrote: Hi all, i'm working in the generation of the code but i'm failing in extracting a function return type when invoking the ReturnType!(T) type trait and mixing it with __traits(getMember) function. Can anyone help me? or explaining what is ha

Re: UDA and ReturnType!(__traits...) doesn't work

2015-05-03 Thread ketmar via Digitalmars-d-learn
On Sun, 03 May 2015 17:21:58 +, filcuc wrote: > Hi all, > i'm working in the generation of the code but i'm failing in extracting > a function return type when invoking the ReturnType!(T) type trait and > mixing it with __traits(getMember) function. > Can anyone help me? or explaining what is

Re: Classes. C++ to D

2015-05-03 Thread Meta via Digitalmars-d-learn
On Sunday, 3 May 2015 at 17:35:42 UTC, Dennis Ritchie wrote: Hi, How can I rewrite this code to the D? - #include #include class A { public: std::string a() { return std::string("foo"); } }; class B { public: std::string b(){ return std::string(

Re: UDA and ReturnType!(__traits...) doesn't work

2015-05-03 Thread filcuc via Digitalmars-d-learn
On Sunday, 3 May 2015 at 17:48:55 UTC, ketmar wrote: On Sun, 03 May 2015 17:21:58 +, filcuc wrote: Hi all, i'm working in the generation of the code but i'm failing in extracting a function return type when invoking the ReturnType!(T) type trait and mixing it with __traits(getMember) fun

Re: Classes. C++ to D

2015-05-03 Thread Adam D. Ruppe via Digitalmars-d-learn
I'd make class A and class B into mixin templates instead. mixin template A { string a() { return "foo"; } } mixin template B { string b() { return "bar"; } } class C { mixin A; mixin B; } If you still need class A and class B, just make a class that mixes in the template for them

Re: Classes. C++ to D

2015-05-03 Thread QAston via Digitalmars-d-learn
On Sunday, 3 May 2015 at 17:35:42 UTC, Dennis Ritchie wrote: Hi, How can I rewrite this code to the D? - #include #include class A { public: std::string a() { return std::string("foo"); } }; class B { public: std::string b(){ return std::string(

Re: Classes. C++ to D

2015-05-03 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 3 May 2015 at 17:46:54 UTC, Meta wrote: This is not really doable right now in D. You can forward the function calls to a and b easily enough, but you can't inherit from more than one class. Once the multiple alias this patch gets merged you will be able to do this in D. On Sunday,

CTFE & template predicates

2015-05-03 Thread Robert M. Münch via Digitalmars-d-learn
Hi, I have now played a around couple of hours (reading everything I could find) to get something to work, but I think I'm missing some basic concepts/understanding. Maybe someone can enlighten me how these things work. I thought that some code from David Nadlinger is what I'm searching for but

Re: CTFE & template predicates

2015-05-03 Thread anonymous via Digitalmars-d-learn
On Sunday, 3 May 2015 at 21:46:11 UTC, Robert M. Münch wrote: Hi, I have now played a around couple of hours (reading everything I could find) to get something to work, but I think I'm missing some basic concepts/understanding. Maybe someone can enlighten me how these things work. I thought tha

Re: CTFE & template predicates

2015-05-03 Thread Dicebot via Digitalmars-d-learn
On Sunday, 3 May 2015 at 21:46:11 UTC, Robert M. Münch wrote: 3. TupleType is a very missleading name when you are learning these things, because the tuple can hold values as well. Or is there a more extensive explanation for the name I don't get? Legacy we are trying to get rid of. See also:

Re: Is it safe to reset HOLD fiber?

2015-05-03 Thread Dzugaru via Digitalmars-d-learn
On Sunday, 3 May 2015 at 14:36:04 UTC, Martin Nowak wrote: On Sunday, 3 May 2015 at 12:33:36 UTC, Dzugaru wrote: Actually the documentation answers your question, please help to improve it if you don't find it clear enough. http://dlang.org/phobos/core_thread.html#.Fiber.reset Created a pull

Re: What wrong?

2015-05-03 Thread Fyodor Ustinov via Digitalmars-d-learn
On Saturday, 2 May 2015 at 20:46:32 UTC, Dennis Ritchie wrote: On Saturday, 2 May 2015 at 19:38:01 UTC, Fyodor Ustinov wrote: I see it by the lack of "42". :) But why is this "receive" breaks down? Report, please, about it (D)evepopers :) https://issues.dlang.org/ I'm not sure that it's not

Re: A slice can lose capacity simply by calling a function

2015-05-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 03, 2015 15:21:15 Andrew Godfrey via Digitalmars-d-learn wrote: > > > I really don't think that it's an issue in general, but if you > > do want to > > guarantee that nothing affects the capacity of your array, then > > you're going > > to need to either wrap all access to it > > I a

Is this expected? default to public members in private class

2015-05-03 Thread Dan Olson via Digitalmars-d-learn
It seems a private class or struct defaults to public members. Just curious if this is intended. I would have expected private all the way down unless overriden. --- plugh.d module plugh; auto makeFoo() {return new Foo;} private: class Foo { void maybepriv() {} private void priv() {}

Re: What wrong?

2015-05-03 Thread Dennis Ritchie via Digitalmars-d-learn
On Monday, 4 May 2015 at 01:03:43 UTC, Fyodor Ustinov wrote: I'm not sure that it's not my fault. So I hope that will come by knowledgeable people and say "Hey, buddy, your mistake is..." :) OK. But if one does not come within three days :), duplicate topic in this section: http://forum.dlan

Efficiently passing structs

2015-05-03 Thread bitwise via Digitalmars-d-learn
If I have a large struct that needs to be passed around, like a 4x4 matrix for example, how do I do that efficiently in D? In std.datetime, "in" is used for most struct parameters, but I'm confused by the docs for function parameter storage classes[1]. In C++, I would pass a large struct as

Struct lifetime wrt function return?

2015-05-03 Thread rsw0x via Digitalmars-d-learn
I remember reading that guaranteed RVO was part of the D standard, but I am completely unable to find anything on it in the specification. I'm also unable to find anything in it that explicitly states the lifetime of returning a stack-local struct from a function. However, it does state Destruc

Re: Efficiently passing structs

2015-05-03 Thread rsw0x via Digitalmars-d-learn
On Monday, 4 May 2015 at 01:58:12 UTC, bitwise wrote: If I have a large struct that needs to be passed around, like a 4x4 matrix for example, how do I do that efficiently in D? In std.datetime, "in" is used for most struct parameters, but I'm confused by the docs for function parameter storage

Converting (casting?) a dynamic array to a fixed array?

2015-05-03 Thread WhatMeWorry via Digitalmars-d-learn
This following code works fine. A triangle is displayed. GLfloat[6] verts = [ 0.0, 1.0, -1.0, -1.0, 1.0, -1.0 ]; glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); // Some of the types are:

Re: Converting (casting?) a dynamic array to a fixed array?

2015-05-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 4 May 2015 at 02:47:24 UTC, WhatMeWorry wrote: glBufferData(GL_ARRAY_BUFFER, verts.sizeof, &verts, GL_STATIC_DRAW); Try (GL_ARRAY_BUFFER, verts.length, verts.ptr, GL_STATIC_DRAW) or maybe: (GL_ARRAY_BUFFER, verts.length * verts[0].sizeof, verts.ptr, GL_STATIC_DRAW) I'm

Re: Converting (casting?) a dynamic array to a fixed array?

2015-05-03 Thread rsw0x via Digitalmars-d-learn
On Monday, 4 May 2015 at 02:47:24 UTC, WhatMeWorry wrote: This following code works fine. A triangle is displayed. GLfloat[6] verts = [ 0.0, 1.0, -1.0, -1.0, 1.0, -1.0 ]; glGenBuffers(1, &vbo); glBindBuffer(GL_

Re: Efficiently passing structs

2015-05-03 Thread Baz via Digitalmars-d-learn
On Monday, 4 May 2015 at 01:58:12 UTC, bitwise wrote: The documentation doesn't say anything about "in" being a reference, but it doesn't say that "out" parameters are references either, even though it's usage in the example clearly shows that it is. Thanks, Bit http://dlang.org/function.h

Re: CTFE & template predicates

2015-05-03 Thread Rikki Cattermole via Digitalmars-d-learn
On 4/05/2015 9:46 a.m., Robert M. Münch wrote: Hi, I have now played a around couple of hours (reading everything I could find) to get something to work, but I think I'm missing some basic concepts/understanding. Maybe someone can enlighten me how these things work. I thought that some code from

Re: Efficiently passing structs

2015-05-03 Thread bitwise via Digitalmars-d-learn
On Sun, 03 May 2015 22:37:52 -0400, rsw0x wrote: Use the ref storage class. You can use more than one storage class i.e, foo(in ref int x) Thanks, this should work. On Sun, 03 May 2015 23:29:59 -0400, Baz wrote: it's specified in http://dlang.org/abi.html (at the bottom): "out and ref are

Re: Efficiently passing structs

2015-05-03 Thread rsw0x via Digitalmars-d-learn
On Monday, 4 May 2015 at 03:57:04 UTC, bitwise wrote: I'll probably go with "in ref". I think "escape proof" is probably a good default. Not to mention, easier to type ;) FYI I'm unsure how well `scope` storage class is currently implemented because it's in a state of flux at the moment as far

Re: Efficiently passing structs

2015-05-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 03, 2015 21:58:12 bitwise via Digitalmars-d-learn wrote: > If I have a large struct that needs to be passed around, like a 4x4 matrix > for example, how do I do that efficiently in D? > > In std.datetime, "in" is used for most struct parameters, but I'm confused > by the docs for fun

Re: Struct lifetime wrt function return?

2015-05-03 Thread ketmar via Digitalmars-d-learn
On Mon, 04 May 2015 02:29:19 +, rsw0x wrote: > This says "Goodbye!" exactly once, indicating(?) that S was NRVO'd which > means the scope of s went from foo to main. However, is this a guarantee > by the standard? Is an implementation allowed to define foo such that it > returns by copy and ca

Re: Is this expected? default to public members in private class

2015-05-03 Thread ketmar via Digitalmars-d-learn
On Sun, 03 May 2015 18:07:20 -0700, Dan Olson wrote: > It seems a private class or struct defaults to public members. Just > curious if this is intended. I would have expected private all the way > down unless overriden. i bet it is intended. protection of struct/class members is independed of

Re: UDA and ReturnType!(__traits...) doesn't work

2015-05-03 Thread ketmar via Digitalmars-d-learn
On Sun, 03 May 2015 18:02:37 +, filcuc wrote: > Yep sorry, > i'm still learning :) i'm not blaming you at all. what i mean i that i'm bad at explanations, so you'd better read one of the D books to better understand my cryptic "don't do that, do this" comments. ;-) signature.asc Descriptio

Re: A slice can lose capacity simply by calling a function

2015-05-03 Thread Ali Çehreli via Digitalmars-d-learn
On 05/03/2015 06:06 PM, Jonathan M Davis via Digitalmars-d-learn wrote: > On Sunday, May 03, 2015 15:21:15 Andrew Godfrey via Digitalmars-d-learn wrote: >> >>> I really don't think that it's an issue in general, but if you >>> do want to >>> guarantee that nothing affects the capacity of your a