Re: Inner struct accessing host member
On Wednesday, 6 August 2014 at 05:53:55 UTC, Philippe Sigaud wrote: I see. I didn't know one could create an A.B 'outside'. I saw inner types as Voldemort types, but that is true only for inner structs in functions. But we weren't creating them, we were copying them, no constructors were used. If the struct is private that may follow different rules as the struct can't leave the outer struct. hmmm static and private... other keywords to try, but offhand it's been a while i don't know if either would change the behavior. Could just be inner scope limitations. Might be other tags/modifiers... I feel helpless :( I already tried to propagate a ref through A's methods, but that made a mess: I have lots of methods, which have all to transmit this ref, only for *one* of them being able to update it. Thanks for you explanations :) I'm now using classes and inner classes. I'm not fond of classes, but that's working correctly. I'm not sure if it would help, but sometimes if you reverse the logic you might get what you want by putting the data in B instead of A. The example coming to mind is from the game 'Mark of the Ninja'. In order to speed up and get their code to work how they wanted, instead of having guards listen for sounds (which would be a constant pinging to look for sounds and other effects), the sound listened for the guards and notified them... So if the data is in B, A can access B's data; Although if you have another class C next to B, then communication between them becomes more of a pain probably... Just something to consider
alias to fully qualified enum in scope where enum is expected
Is there a simple way to to do this? enum A{ a1, a2 } void fun(A a){...} void test(){ fun(A.a1); //works fun(a1); //I'd like a1 to work, but just where an A is expected to avoid polluting namespace. }
extern (C++, N) is it implemented?
This dlang.org/cpp_interface.html says I can do the following // c++ namespace N { void someCppFunction(); } // d extern (C++, N) void someCppFunction(); but this http://dpaste.dzfl.pl/e2242263e1dc says I can't Is this feature implemented?
Re: extern (C++, N) is it implemented?
On Wednesday, 6 August 2014 at 06:50:59 UTC, Alexandr Druzhinin wrote: This dlang.org/cpp_interface.html says I can do the following // c++ namespace N { void someCppFunction(); } // d extern (C++, N) void someCppFunction(); but this http://dpaste.dzfl.pl/e2242263e1dc says I can't Is this feature implemented? Should be in upcoming release.
Re: Best practices for testing functions that opens files
On 08/06/2014 01:22 AM, splatterdash wrote: Hi all, Is there a recommended way to test functions that opens and iterates over files? The unittest block seems more suited for testing functions whose input and output can be defined in the program itself. I'm wondering if there is a better way to test functions that open files with specific formats. Thanks before :). Split it to several functions: ubyte[] readFile(string file) {...} MyFormat parseData(ubyte[] data) { ... } This way you have very little logic where the files are read, and you can easily unittest your parsing.
Re: Help with porting grammar from PEGjs to D for dustjs project!
What I was thinking about is possibility to change ParseTree struct with user-defined version of it. And I was thinking about setting tree type as template parameter to grammar: grammar!(MyParseTree)( Arithmetic: ... ); Or somethink like this. I think changing source code of library in order to change tree type is not good and should be set as parameter. If it's already implemented please let me knoe because I couldn't find it. And also some minimal interface is needed to be described in documentation for ParseTree (may be ability to set it as class is good in order to have polymorthic nodes with different methods and properties). Of course I can transform PEGGED syntactic tree into another form of tree specified by usage domain. But if it doesn't significantly differs from PEGGED tree (for example node have a pair of additional properties) it only causes into additional memory consumption and CPU to transform tree. But if domain specific tree differs a lot of course we need some useful way to transform trees.
Re: alias to fully qualified enum in scope where enum is expected
On 6/08/2014 6:11 p.m., Timothee Cour via Digitalmars-d-learn wrote: Is there a simple way to to do this? enum A{ a1, a2 } void fun(A a){...} void test(){ fun(A.a1); //works fun(a1); //I'd like a1 to work, but just where an A is expected to avoid polluting namespace. } The magic of with statements! enum A { a1, a2 } void func(A a){} void main(){ func(A.a1); with(A) { func(a1); } }
Re: extern (C++, N) is it implemented?
06.08.2014 10:54, Dicebot пишет: On Wednesday, 6 August 2014 at 06:50:59 UTC, Alexandr Druzhinin wrote: This dlang.org/cpp_interface.html says I can do the following // c++ namespace N { void someCppFunction(); } // d extern (C++, N) void someCppFunction(); but this http://dpaste.dzfl.pl/e2242263e1dc says I can't Is this feature implemented? Should be in upcoming release. Ok. Hope it will )
Re: How to easily construct objects with multi-param constructors from lazy ranges?
On Tuesday, 5 August 2014 at 19:21:44 UTC, Philippe Sigaud via Digitalmars-d-learn wrote: Some range which takes an at compile time known number of elements from an input range and provides opIndex seems perfect to me, but as far as I know there's no such thing in Phobos. There is chunks: http://dlang.org/phobos/std_range.html#chunks Yea, but that won't work for forward ranges. It only provides opIndex if the underlying range provides it. Since the chunk size is a runtime parameter it can't implement opIndex efficiently for non-random access ranges. staticChunks was a bit of a misnomer. staticTake would be a better name. The range would contains a static array and pops that number of elements from the input range. Then, opIndex can easily be defined.
Re: How to easily construct objects with multi-param constructors from lazy ranges?
Yea, but that won't work for forward ranges. It only provides opIndex if the underlying range provides it. Since the chunk size is a runtime parameter it can't implement opIndex efficiently for non-random access ranges. But in your case, your range is random-access, no? Or else, you can always map array on the chunks... staticChunks was a bit of a misnomer. staticTake would be a better name. The range would contains a static array and pops that number of elements from the input range. Then, opIndex can easily be defined. What about takeExactly?
Re: Help with porting grammar from PEGjs to D for dustjs project!
On Wed, Aug 6, 2014 at 9:09 AM, Uranuz via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: What I was thinking about is possibility to change ParseTree struct with user-defined version of it. And I was thinking about setting tree type as template parameter to grammar: grammar!(MyParseTree)( Arithmetic: ... ); That's already the case, look at https://github.com/PhilippeSigaud/Pegged/blob/master/pegged/parser.d on line 134, for example. struct GenericPegged(TParseTree) { ... } And then, the library alias a standard version (line 1531): alias GenericPegged!(ParseTree).Pegged Pegged; Which means the customer-facing Pegged parser is in fact a generic parser specialized on ParseTree. But you can substitute your own parse tree. That's of course the same for all parsers: GenericXXX(TParseTree) {...} and then alias XXX = GenericXXX!(ParseTree); But you're right, it's not really documented and I don't have a template checking whether TParseTree respect some static inferface. This parameterization was asked by someone on github, but I don't think they used it finally. ParseTree is described here: https://github.com/PhilippeSigaud/Pegged/wiki/Parse-Trees Maybe we can continue this thread by private mail? I'm not sure people on the D list are that interested by the internals of a library.
multidimensional indexing/slicing docs?
Is there anywhere that describes what Kenji (it was Kenji wasn't it?) recently implemented for this?
Re: Haskell calling D code through the FFI
Jon via Digitalmars-d-learn digitalmars-d-learn@puremagic.com writes: So that does indeed solve some of the problems. However, using this method, when linking I get two errors, undefined reference rt_init() and rt_term() I had just put these methods in the header file. If I put wrappers around these functions and export I get the rt_init, rt_term is private. rt_init is part of druntime. You need to link druntime into your program in order to make it work.
AA initialization
I found AA initialization have a strange effect: ```d string[string] map; // same as `string[string] map = string[string].init; writeln(map); // output: [] string[string] refer = map; // make a reference refer[1] = 2; // update the reference writeln(map); // output: []. The reference does not affect the original. ``` But if I do an assignment first, the reference works: ```d string[string] map; // same as `string[string] map = string[string].init; writeln(map); // output: [] map[1] = 0; string[string] refer = map; // make a reference refer[1] = 2; // update the reference writeln(map); // output: [1:2]. The reference does affect. ``` So if I want an empty AA and want to use a variable to refer to it later, I have to do this: ```d string[string] map; // same as `string[string] map = string[string].init; map[1] = 0; map.remove(1); // assign and then REMOVE! writeln(map); // output: [] string[string] refer = map; // make a reference refer[1] = 2; // update the reference writeln(map); // output: [1:2]. The reference does affect. ``` which looks awkward. Is it because `string[string].init == null` ? If so, how do I specify an empty AA which is not null? Neither `[]` or `[:]` seems to work.
Re: AA initialization
On Wednesday, 6 August 2014 at 11:32:41 UTC, Puming wrote: I found AA initialization have a strange effect: ```d string[string] map; // same as `string[string] map = string[string].init; writeln(map); // output: [] string[string] refer = map; // make a reference refer[1] = 2; // update the reference writeln(map); // output: []. The reference does not affect the original. ``` But if I do an assignment first, the reference works: ```d string[string] map; // same as `string[string] map = string[string].init; writeln(map); // output: [] map[1] = 0; string[string] refer = map; // make a reference refer[1] = 2; // update the reference writeln(map); // output: [1:2]. The reference does affect. ``` So if I want an empty AA and want to use a variable to refer to it later, I have to do this: ```d string[string] map; // same as `string[string] map = string[string].init; map[1] = 0; map.remove(1); // assign and then REMOVE! writeln(map); // output: [] string[string] refer = map; // make a reference refer[1] = 2; // update the reference writeln(map); // output: [1:2]. The reference does affect. ``` which looks awkward. Is it because `string[string].init == null` ? If so, how do I specify an empty AA which is not null? Neither `[]` or `[:]` seems to work. AFAIK there is no easy way to do it. Maybe it would be fine to add some function to phobos. Something like this: auto initAA(VT,KT)() { static struct Entry { Entry *next; size_t hash; } static struct Impl { Entry*[] buckets; size_t nodes; TypeInfo _keyti; Entry*[4] binit; @property const(TypeInfo) keyti() const @safe pure nothrow @nogc { return _keyti; } } static struct AA { Impl* impl; } VT[KT] aaa; AA* aa = cast(AA*)aaa; if (aa.impl is null) { aa.impl = new Impl(); aa.impl.buckets = aa.impl.binit[]; } aa.impl._keyti = cast() typeid(aaa); return aaa; } Or it would be fine if I could write something like this: auto aa = new VT[KT]();
Re: Member access of __gshared global object
On Wednesday, 6 August 2014 at 04:14:51 UTC, Puming wrote: On Thursday, 31 July 2014 at 10:22:28 UTC, Marc Schütz wrote: On Thursday, 31 July 2014 at 02:03:37 UTC, Puming wrote: 1. Are AAs reference type? if so, why does the compiler copy it? This is probably your problem. They are reference types, but initially that reference is `null`. When you write: auto cmds = CONFIG.commands; `cmds` contains a copy of the `null` value. On assignment, the actual AA is created, and assigned to `cmds`, but not back to `CONFIG.commands`. Try initializing the AA in your class constructor. I checked the code and could concur your suggestion. What I found strange were: 1. The only way that I can initialize it is to assign a value. But I want to initialize an empty AA, is that possible? I don't know whether there is a way currently. The obvious `CONFIG.commands = []` produces an error: can't have associative array key of void. This is likely a restriction of the current implementation of AAs, which is known to be suboptimal and being reworked slowly. 2. CONFIG.commands is not `null` before initialized, it is '[]'(when I writeln it). That's just how writeln prints empty AAs. Try `writeln(cmds is null)`, it will print true. But it still behave like what you described (except that it won't produce an NullPointer Exception. Because the runtime checks whether they are null, and allocates memory if necessary.
Re: Member access of __gshared global object
On Wednesday, 6 August 2014 at 04:14:51 UTC, Puming wrote: 1. The only way that I can initialize it is to assign a value. But I want to initialize an empty AA, is that possible? workaround: string[string] aa; assert(aa is null); aa[] = ; aa.remove(); assert(aa !is null);
Re: extern (C++, N) is it implemented?
On Wednesday, 6 August 2014 at 06:50:59 UTC, Alexandr Druzhinin wrote: This dlang.org/cpp_interface.html says I can do the following // c++ namespace N { void someCppFunction(); } // d extern (C++, N) void someCppFunction(); but this http://dpaste.dzfl.pl/e2242263e1dc says I can't Is this feature implemented? dpaste provides DMD2.063 as DMD 2.x Git! http://dpaste.dzfl.pl/8dd68f98dbd73
Re: Member access of __gshared global object
1. The only way that I can initialize it is to assign a value. But I want to initialize an empty AA, is that possible? Like arrays, associative arrays have value semantics. This means that they can be always referenced. It is easier to see this with an array: int[] a1 = null; writeln(a1.ptr); writeln(a1.length); will print null and 0; The array is in fact a pair: ptr and length. The pair is allocated like any other primitive or struct and thus cannot be null. This means if you want an empty AA you can write aa1 = null; or more explicit aa1 = typeof(aa1).init; 2. CONFIG.commands is not `null` before initialized, it is '[]'(when I writeln it). But it still behave like what you described (except that it won't produce an NullPointer Exception. See 1.
Re: AA initialization
On Wednesday, 6 August 2014 at 14:38:34 UTC, Marc Schütz wrote: On Wednesday, 6 August 2014 at 13:15:27 UTC, Kozzi11 wrote: AFAIK there is no easy way to do it. Maybe it would be fine to add some function to phobos. Something like this: auto initAA(VT,KT)() { static struct Entry { Entry *next; size_t hash; } static struct Impl { Entry*[] buckets; size_t nodes; TypeInfo _keyti; Entry*[4] binit; @property const(TypeInfo) keyti() const @safe pure nothrow @nogc { return _keyti; } } static struct AA { Impl* impl; } VT[KT] aaa; AA* aa = cast(AA*)aaa; if (aa.impl is null) { aa.impl = new Impl(); aa.impl.buckets = aa.impl.binit[]; } aa.impl._keyti = cast() typeid(aaa); return aaa; } Or it would be fine if I could write something like this: auto aa = new VT[KT](); `string[string] aa = [];` would be fine, too, but it currently doesn't compile. Thanks for your clarification (and also in the other thread), so this is an implementation issue for builtin AAs.
Re: Member access of __gshared global object
On Wednesday, 6 August 2014 at 14:22:32 UTC, Dragos Carp wrote: 1. The only way that I can initialize it is to assign a value. But I want to initialize an empty AA, is that possible? --snip-- This means if you want an empty AA you can write aa1 = null; or more explicit aa1 = typeof(aa1).init; This would defeat the purpose, see the original post.
Re: AA initialization
On Wednesday, 6 August 2014 at 13:15:27 UTC, Kozzi11 wrote: AFAIK there is no easy way to do it. Maybe it would be fine to add some function to phobos. Something like this: auto initAA(VT,KT)() { static struct Entry { Entry *next; size_t hash; } static struct Impl { Entry*[] buckets; size_t nodes; TypeInfo _keyti; Entry*[4] binit; @property const(TypeInfo) keyti() const @safe pure nothrow @nogc { return _keyti; } } static struct AA { Impl* impl; } VT[KT] aaa; AA* aa = cast(AA*)aaa; if (aa.impl is null) { aa.impl = new Impl(); aa.impl.buckets = aa.impl.binit[]; } aa.impl._keyti = cast() typeid(aaa); return aaa; } Or it would be fine if I could write something like this: auto aa = new VT[KT](); `string[string] aa = [];` would be fine, too, but it currently doesn't compile.
Re: AA initialization
On Wednesday, 6 August 2014 at 14:40:00 UTC, Puming wrote: Thanks for your clarification (and also in the other thread), so this is an implementation issue for builtin AAs. https://issues.dlang.org/show_bug.cgi?id=10535
Re: Member access of __gshared global object
On Wednesday, 6 August 2014 at 14:36:23 UTC, Marc Schütz wrote: This would defeat the purpose, see the original post. sorry, I red just the last post. __gshared has no influence on this. auto cmds = CONFIG.commands; cmds[list] = new Command(...); cmds is a thread local variable referencing the shared AA. But if you add new elements to cmds, cmd will be reallocated and the shared AA will remain unchanged. Though, updated values of existing keys will be visible in the original, because no relocation takes place. If you want to change the original you need a pointer or a reference (for a setter function). auto cmds = CONFIG.commands; (*cmds)[list] = new Command(...);
Re: alias to fully qualified enum in scope where enum is expected
On Wednesday, 6 August 2014 at 07:23:32 UTC, Rikki Cattermole wrote: The magic of with statements! enum A { a1, a2 } void func(A a){} void main(){ func(A.a1); with(A) { func(a1); } } And if you want to be *really* concise: with (A) fun(a1);
Re: Member access of __gshared global object
On Wednesday, 6 August 2014 at 15:18:15 UTC, Dragos Carp wrote: On Wednesday, 6 August 2014 at 14:36:23 UTC, Marc Schütz wrote: This would defeat the purpose, see the original post. sorry, I red just the last post. __gshared has no influence on this. Indeed, it was just what the OP suspected as the culprit. auto cmds = CONFIG.commands; cmds[list] = new Command(...); cmds is a thread local variable referencing the shared AA. But if you add new elements to cmds, cmd will be reallocated and the shared AA will remain unchanged. Though, updated values of existing keys will be visible in the original, because no relocation takes place. This describes the semantics of regular arrays. Are you sure it also applies to AAs? I thought they will keep referring to the same data once they are initialized. But I might be mistaken... If you want to change the original you need a pointer or a reference (for a setter function). auto cmds = CONFIG.commands; (*cmds)[list] = new Command(...);
Re: Member access of __gshared global object
This describes the semantics of regular arrays. Are you sure it also applies to AAs? I thought they will keep referring to the same data once they are initialized. But I might be mistaken... This can be easily tested. And... you are right! In the current implementation (I couldn't find any specification) the AA contains just a pointer[1]. I suppose that initially this pointer is null and on copy the pointer is copied, so that after initialization any change of the copy is visible in the original. [1] https://github.com/D-Programming-Language/druntime/blob/master/src/rt/aaA.d#L82-85
Re: Haskell calling D code through the FFI
Hi, thank you!! I have modified the program based on a previous suggestion. rt_init is called before using any D functionality and rt_term is called after using D functionality. I did this by: 1) Placing int rt_init(); and int rt_term(); into the header file that Haskell reads 2) Creating Haskell stubs foreign import ccall unsafe FunctionsInD.h rt_init d_init :: IO CInt foreign import ccall unsafe FunctionsInD.h rt_term d_term :: IO CInt And then in the Main haskell program, in main, the function starts with d_init and ends with d_term I'm pretty sure this is working nicely, because I can allocate structs with the new keyword in D, and this led to segfaults before using rt_init and rt_term. I think the problem I was having was trying to do this in a stupid way i.e. put wrappers around init and term on the D side. However, I still do not know how to compile without the using a fake main. Compiling with -c -lib does still give me a _Dmain undefined reference. I did dmd -c -lib FunctionsInD.d ghc --make Main.hs FunctionsInD.a -lphobos2 And get /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libphobos2.so: undefined reference to `_Dmain' On Wednesday, 6 August 2014 at 11:03:33 UTC, David Soria Parra via Digitalmars-d-learn wrote: Jon via Digitalmars-d-learn digitalmars-d-learn@puremagic.com writes: So that does indeed solve some of the problems. However, using this method, when linking I get two errors, undefined reference rt_init() and rt_term() I had just put these methods in the header file. If I put wrappers around these functions and export I get the rt_init, rt_term is private. rt_init is part of druntime. You need to link druntime into your program in order to make it work.
Re: alias to fully qualified enum in scope where enum is expected
Thanks, I know with statement could be used but I was hoping for a solution not involving adding syntax to call site. void fun(with(A){A a}, int b){...} //conceptually like this void test(){ int a1=1; fun(A.a1, a1); // would work fun(a1, a1);// would work } On Wed, Aug 6, 2014 at 8:22 AM, Meta via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Wednesday, 6 August 2014 at 07:23:32 UTC, Rikki Cattermole wrote: The magic of with statements! enum A { a1, a2 } void func(A a){} void main(){ func(A.a1); with(A) { func(a1); } } And if you want to be *really* concise: with (A) fun(a1);
Re: Inner struct accessing host member
hmmm static and private... other keywords to try, but offhand it's been a while i don't know if either would change the behavior. Could just be inner scope limitations. Might be other tags/modifiers... I feel helpless :( No need to ;-) Thanks for your help, don't sweat it too much. I'm not sure if it would help, but sometimes if you reverse the logic you might get what you want by putting the data in B instead of A. I have a lot of Bs (nodes in a graph). They compute some things and when they get a result, they update A's field. Each A holds the entry point to their inner graph of Bs and waits for the results. So I don't see how I could invert it, really. What *could* do it to have the graph of Bs in thread and sending results as messages to another thread, where A is waiting for them. It's just... I'm so used to being able to mix and compose 'concepts' in D: structs in functions, classes in classes in structs, functions returning functions returning structs, etc. I'm used to begin able to organise my code as I see the problem space. But here, with a struct-in-a-struct, I hit a wall. Not fun, but not problematic too...
'with(Foo):' not allowed, why?
Is there a reason why 'with(Foo):' is not allowed, and we have to use with(Foo){...} ? It would be more in line with how other scope definitions work (extern(C) etc)
Re: unittest affects next unittest
On Wednesday, 6 August 2014 at 02:12:16 UTC, Era Scarecrow wrote: On Tuesday, 5 August 2014 at 17:41:06 UTC, Marc Schütz wrote: It's a consequence of the fact that every type in D has a default initializer which is known at compile time. Then doesn't this mean it should pop out a warning in case that's the behavior you wanted, perhaps a reference to the D specs? Beyond that it would be easy to forget it does that, since class initializes things different than structs because of the 'known at compile time' logic. It wouldn't make sense to warn about that, because it could be very legitimately be what the programmer wants to do. We can't warn about anything that would be legitimate to have, because it would force programmers to change their code to get rid of the warning, even when the code was valid. So, while in most cases, it might be a problem, we can't warn about it. But I do think that the spec should be clearer about it. - Jonathan M Davis
Associative value order
I know that there is no prescribed order that the .values array will be sorted in, however I'm curious if the order is deterministic based on keys. If I have two associative arrays with strings for keys and ints for values and they each have an identical set of keys, would the .values property return the values in the same order?
Max/Min values in an associative array
I am trying to find the max and min values in an associative array. Say I have: double[char] bids; bid['A'] = 37.50; bid['B'] = 38.11; bid['C'] = 36.12; How can I find the max and min values. I am thinking that I need to use max and min functions from std.algorithm, but not sure how to. Thanks! TJB
Re: Associative value order
On Wed, Aug 06, 2014 at 05:54:23PM +, Patrick via Digitalmars-d-learn wrote: I know that there is no prescribed order that the .values array will be sorted in, however I'm curious if the order is deterministic based on keys. If I have two associative arrays with strings for keys and ints for values and they each have an identical set of keys, would the .values property return the values in the same order? In the current implementation, yes. But I think it's a bad idea to rely on that, since a future implementation might no longer do this. (E.g., if we use a different hash collision resolution algorithm that is sensitive to insertion order.) It is probably safest to make an array of keys with .keys, and sort the array in the order you want. T -- One Word to write them all, One Access to find them, One Excel to count them all, And thus to Windows bind them. -- Mike Champion
Re: Max/Min values in an associative array
On Wed, 06 Aug 2014 17:57:54 +, TJB wrote: I am trying to find the max and min values in an associative array. Say I have: double[char] bids; bid['A'] = 37.50; bid['B'] = 38.11; bid['C'] = 36.12; How can I find the max and min values. I am thinking that I need to use max and min functions from std.algorithm, but not sure how to. Thanks! TJB Do you just need the min and max values or do you also need the keys of those values? If the former, here's a paste: http://dpaste.dzfl.pl/0bbf31278a25
Re: Max/Min values in an associative array
On Wed, Aug 06, 2014 at 05:57:54PM +, TJB via Digitalmars-d-learn wrote: I am trying to find the max and min values in an associative array. Say I have: double[char] bids; bid['A'] = 37.50; bid['B'] = 38.11; bid['C'] = 36.12; How can I find the max and min values. I am thinking that I need to use max and min functions from std.algorithm, but not sure how to. [...] import std.algorithm : reduce, max, min; auto highest = reduce!((a,b) = max(a,b))(-double.max, bids.byValue()); auto lowest = reduce!((a,b) = min(a,b))(double.max, bids.byValue()); T -- Designer clothes: how to cover less by paying more.
Re: Max/Min values in an associative array
On Wednesday, 6 August 2014 at 17:57:55 UTC, TJB wrote: I am trying to find the max and min values in an associative array. Say I have: double[char] bids; bid['A'] = 37.50; bid['B'] = 38.11; bid['C'] = 36.12; How can I find the max and min values. I am thinking that I need to use max and min functions from std.algorithm, but not sure how to. Thanks! TJB You can extract the values into a double[] using bid.values. Then you can simply use max and min from std.algorithm.
Re: multidimensional indexing/slicing docs?
On Wednesday, 6 August 2014 at 08:48:25 UTC, John Colvin wrote: Is there anywhere that describes what Kenji (it was Kenji wasn't it?) recently implemented for this? I'm curious about this as well. I've just come across a case where I need to work with a 2D array of channels*samples from an analog-digital converter, and what I thought would be a straightforward design problem turned out to be pretty complicated. I have a C++ solution but its procedural/oop. Going functional and range-based would be a huge improvement, but I'm caught in analysis paralysis.
Re: Max/Min values in an associative array
Justin, That's it! Perfect - thanks!! TJB Do you just need the min and max values or do you also need the keys of those values? If the former, here's a paste: http://dpaste.dzfl.pl/0bbf31278a25
private selective imports
Is there any way to make selective imports private? I've got a name clash from importing an all module that has a bunch of public imports, one of which is circular, it goes sort of like this: module math.all; public: import geometry; import vectors; --- module vectors; struct Vector {} --- module geometry; import math.all: Vector; And then I get an error like: vectors.Vector conflicts with geometry.Vector Its the same Vector, though. What can I do?
Re: multidimensional indexing/slicing docs?
On Wed, Aug 06, 2014 at 06:10:43PM +, Vlad Levenfeld via Digitalmars-d-learn wrote: On Wednesday, 6 August 2014 at 08:48:25 UTC, John Colvin wrote: Is there anywhere that describes what Kenji (it was Kenji wasn't it?) recently implemented for this? I'm curious about this as well. I've just come across a case where I need to work with a 2D array of channels*samples from an analog-digital converter, and what I thought would be a straightforward design problem turned out to be pretty complicated. I have a C++ solution but its procedural/oop. Going functional and range-based would be a huge improvement, but I'm caught in analysis paralysis. AFAIK, what Kenji implemented was just the support necessary for implementing a multidimensional array type with overloaded opIndex / opSlice / opDollar. I don't think there's any functional / range-based things actually built on top of this at present. I'm also quite interested in this topic, and several people in the past have also voiced similar interests. But I don't think we have anything standard just yet. In any case, what Kenji did was basically to implement support for: arr[i,j,k,...]; // opIndex arr[i,j,k,...] = ...; // opIndexAssign arr[i1 .. i2, j1 .. j2, ...]; // opSlice arr[i..$, j..$, k..$]; // opSlice / opDollar and perhaps one or two others. And, looking at the docs on dlang.org, evidently this feature isn't documented yet. :-( Maybe if I get some free time later today I'll take a shot at documenting it. T -- What do you call optometrist jokes? Vitreous humor.
Re: private selective imports
On Wed, Aug 06, 2014 at 06:19:34PM +, Vlad Levenfeld via Digitalmars-d-learn wrote: Is there any way to make selective imports private? I've got a name clash from importing an all module that has a bunch of public imports, one of which is circular, it goes sort of like this: module math.all; public: import geometry; import vectors; --- module vectors; struct Vector {} --- module geometry; import math.all: Vector; And then I get an error like: vectors.Vector conflicts with geometry.Vector Its the same Vector, though. What can I do? I'd file a bug. But obviously, you want a workaround in the meantime. I'll leave it to the module experts to answer that. ;-) (My module structures tend to be quite shallow and simple, so I haven't run into this problem myself yet.) T -- If you want to solve a problem, you need to address its root cause, not just its symptoms. Otherwise it's like treating cancer with Tylenol...
Re: private selective imports
Most voted DMD bug : https://issues.dlang.org/show_bug.cgi?id=314
Re: Associative value order
On 8/6/14, 2:59 PM, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Aug 06, 2014 at 05:54:23PM +, Patrick via Digitalmars-d-learn wrote: I know that there is no prescribed order that the .values array will be sorted in, however I'm curious if the order is deterministic based on keys. If I have two associative arrays with strings for keys and ints for values and they each have an identical set of keys, would the .values property return the values in the same order? In the current implementation, yes. But I think it's a bad idea to rely on that, since a future implementation might no longer do this. (E.g., if we use a different hash collision resolution algorithm that is sensitive to insertion order.) It is probably safest to make an array of keys with .keys, and sort the array in the order you want. T Why is a dictionary something built-in the language? Can't it be some standard library class/struct with syntax sugar for creation? All of these questions about associative arrays wouldn't exist if the source code for these operations was available. (it's probably available, but buried in some C++ code, I guess, on in dmd?)
Re: private selective imports
On Wednesday, 6 August 2014 at 18:33:23 UTC, Dicebot wrote: Most voted DMD bug : https://issues.dlang.org/show_bug.cgi?id=314 +1 vote from me.
map reduce for functioneren with two parameters
I was wondering whether there is a way to use map reduce to calculate e.g. the weighted mean and weighted standard deviation. These would not only need the values, but also the weights.
Re: private selective imports
On Wednesday, 6 August 2014 at 18:33:23 UTC, Dicebot wrote: Most voted DMD bug : https://issues.dlang.org/show_bug.cgi?id=314 Yeah this is a famous bug that seems to catch everyone out at some stage.
Re: Associative value order
On Wed, Aug 06, 2014 at 03:33:15PM -0300, Ary Borenszweig via Digitalmars-d-learn wrote: [...] Why is a dictionary something built-in the language? It's actually one of the things I really liked about D when I was first considering it. I hated the fact that it took until C++11 to even *get* a proper hash table into the C++ standard, and even now, it's a royal pain in the neck to even use them (e.g., you have to define your own hash function if you want to use a struct as key), because the language just wasn't designed to support them in a non-verbose, non-contorted way. In D, it Just Works(tm). (Well, excepting the numerous AA-related bugs in D, but that's more of a quality-of-implementation issue. The idea itself is sound, IMO.) Can't it be some standard library class/struct with syntax sugar for creation? That's where we hope to get to eventually. But we're not quite there yet. All of these questions about associative arrays wouldn't exist if the source code for these operations was available. (it's probably available, but buried in some C++ code, I guess, on in dmd?) It's certainly available, and it's in D, not C++: https://github.com/D-Programming-Language/druntime/blob/master/src/rt/aaA.d But that's beside the point. The point is that the AA interface does not specify the ordering of keys/values, precisely because we want to have the flexibility of changing the implementation (e.g., if we decide to implement a superior hash collision resolution algorithm, replace the default hash function, etc.) without affecting user code. User code that depends on the specifics of the current implementation are, strictly speaking, broken, because they break the encapsulation of AA's. People simply need to learn that AA's are *unordered*. This is D, not PHP. If they want an ordered dictionary, they really should be using something else instead, perhaps std.container.RedBlackTree. T -- Windows: the ultimate triumph of marketing over technology. -- Adrian von Bidder
Re: Associative value order
On Wednesday, 6 August 2014 at 18:33:16 UTC, Ary Borenszweig wrote: On 8/6/14, 2:59 PM, H. S. Teoh via Digitalmars-d-learn wrote: On Wed, Aug 06, 2014 at 05:54:23PM +, Patrick via Digitalmars-d-learn wrote: I know that there is no prescribed order that the .values array will be sorted in, however I'm curious if the order is deterministic based on keys. If I have two associative arrays with strings for keys and ints for values and they each have an identical set of keys, would the .values property return the values in the same order? In the current implementation, yes. But I think it's a bad idea to rely on that, since a future implementation might no longer do this. (E.g., if we use a different hash collision resolution algorithm that is sensitive to insertion order.) It is probably safest to make an array of keys with .keys, and sort the array in the order you want. T Why is a dictionary something built-in the language? Can't it be some standard library class/struct with syntax sugar for creation? All of these questions about associative arrays wouldn't exist if the source code for these operations was available. (it's probably available, but buried in some C++ code, I guess, on in dmd?) There is ongoing work to do exactly this, see for example: https://github.com/D-Programming-Language/druntime/pull/482#issuecomment-28486561 https://github.com/D-Programming-Language/druntime/pull/676
Re: map reduce for functioneren with two parameters
On Wed, Aug 06, 2014 at 06:44:44PM +, Martijn Pot via Digitalmars-d-learn wrote: I was wondering whether there is a way to use map reduce to calculate e.g. the weighted mean and weighted standard deviation. These would not only need the values, but also the weights. You can probably do this if each element of the range contains the weight. If it isn't already part of your structure, you can use zip to associate them together. Perhaps something like this: // Warning: untested code float[] values = ...; float[] weights = ...; assert(values.length == weights.length); auto weightedMean = reduce!( // b[0] == values[i]; b[1] == weights[i] (a,b) = a + b[0]*b[1] )(zip(values,weights)) / values.length; Of course, values and weights don't have to be arrays, zip works with arbitrary ranges. T -- People tell me that I'm skeptical, but I don't believe it.
Re: private selective imports
On Wednesday, 6 August 2014 at 18:33:23 UTC, Dicebot wrote: Most voted DMD bug : https://issues.dlang.org/show_bug.cgi?id=314 +1 from me as well. This is unfortunate. D otherwise has a very comfortable import system.
Removing an element from a list or array
I feel dumb. I've been searching for how to do this, and each page or forum entry I read makes me more confused. Let's say I have a list of values (Monday, Tuesday, Wednesday, Thursday, Friday). I can store this list in an Slist, Dlist, Array etc -- any collection is fine. I decide I want to remove Thursday from the list. How? I see that linearRemove is meant to do this, but that takes a range. How do I get a range of 'Thursday'?
Re: alias to fully qualified enum in scope where enum is expected
On Wednesday, 6 August 2014 at 16:48:57 UTC, Timothee Cour via Digitalmars-d-learn wrote: Thanks, I know with statement could be used but I was hoping for a solution not involving adding syntax to call site. If you control the declaration of the enum, you could write: alias a1 = A.a1; alias a2 = A.a2; A bit tedious, but it works, and could be automated if need be.
Re: multidimensional indexing/slicing docs?
On Wed, Aug 06, 2014 at 11:21:51AM -0700, H. S. Teoh via Digitalmars-d-learn wrote: [...] In any case, what Kenji did was basically to implement support for: arr[i,j,k,...]; // opIndex arr[i,j,k,...] = ...; // opIndexAssign arr[i1 .. i2, j1 .. j2, ...]; // opSlice arr[i..$, j..$, k..$]; // opSlice / opDollar and perhaps one or two others. OK, found the pull that implemented this, which also has a description of what was implemented: https://github.com/D-Programming-Language/dmd/pull/443 I'll see if I can cook up a PR to incorporate this into the language docs on dlang.org. T -- Heuristics are bug-ridden by definition. If they didn't have bugs, they'd be algorithms.
Re: private selective imports
On Wednesday, 6 August 2014 at 19:31:04 UTC, Jonathan M Davis wrote: On Wednesday, 6 August 2014 at 18:33:23 UTC, Dicebot wrote: Most voted DMD bug : https://issues.dlang.org/show_bug.cgi?id=314 Yeah, it's why I'd suggest that folks not use selective imports right now. But people seem to really love the feature, so they use it and keep running into this problem. - Jonathan M Davis scope-local selective imports are not affected
Re: private selective imports
On Wednesday, 6 August 2014 at 18:33:23 UTC, Dicebot wrote: Most voted DMD bug : https://issues.dlang.org/show_bug.cgi?id=314 Yeah, it's why I'd suggest that folks not use selective imports right now. But people seem to really love the feature, so they use it and keep running into this problem. - Jonathan M Davis
Re: private selective imports
On Wednesday, 6 August 2014 at 19:35:02 UTC, Dicebot wrote: On Wednesday, 6 August 2014 at 19:31:04 UTC, Jonathan M Davis wrote: On Wednesday, 6 August 2014 at 18:33:23 UTC, Dicebot wrote: Most voted DMD bug : https://issues.dlang.org/show_bug.cgi?id=314 Yeah, it's why I'd suggest that folks not use selective imports right now. But people seem to really love the feature, so they use it and keep running into this problem. - Jonathan M Davis scope-local selective imports are not affected Sure, but people keep using them at the module-level, which really shouldn't be done until the bug is fixed. IMHO, we'd be better off making it illegal to use selective imports at the module-level rather than keeping it as-is. - Jonathan M Davis
Re: How to easily construct objects with multi-param constructors from lazy ranges?
On Wednesday, 6 August 2014 at 08:00:32 UTC, Philippe Sigaud via Digitalmars-d-learn wrote: Yea, but that won't work for forward ranges. It only provides opIndex if the underlying range provides it. Since the chunk size is a runtime parameter it can't implement opIndex efficiently for non-random access ranges. But in your case, your range is random-access, no? Nope, splitter returns a forward range. Or else, you can always map array on the chunks... Sure. But that would be a completely unnecessary allocation. I'm trying to avoid those, it's what ranges are supposed to be good at ;) staticChunks was a bit of a misnomer. staticTake would be a better name. The range would contains a static array and pops that number of elements from the input range. Then, opIndex can easily be defined. What about takeExactly? Same problem. As long as the 'count' parameter is a runtime value instead of a compile time value, it's impossible to define opIndex efficiently. Therefore the Phobos ranges don't do it.
Re: Removing an element from a list or array
On Wednesday, 6 August 2014 at 19:01:26 UTC, Patrick wrote: I feel dumb. I've been searching for how to do this, and each page or forum entry I read makes me more confused. Let's say I have a list of values (Monday, Tuesday, Wednesday, Thursday, Friday). I can store this list in an Slist, Dlist, Array etc -- any collection is fine. I decide I want to remove Thursday from the list. How? I see that linearRemove is meant to do this, but that takes a range. How do I get a range of 'Thursday'? Slicing a container gives you a range for that container, and it's that type that needs to be used to remove elements (either that, or that type wrapped with std.range.Take), since otherwise, the container wouldn't know which elements you were trying to remove - just their values. You need to use std.algorithm.find to find the element that you want to remove, in which case, you have a range starting at that element (but it contains everything after it too). So, you used std.range.take to take the number of elements that you want from the range, and then you pass that result to linearRemove. e.g. import std.algorithm; import std.container; import std.range; void main() { auto arr = Array!string(Monday, Tuesday, Wednesday, Thursday, Friday); auto range = arr[]; assert(equal(range, [Monday, Tuesday, Wednesday, Thursday, Friday])); auto found = range.find(Thursday); assert(equal(found, [Thursday, Friday])); arr.linearRemove(found.take(1)); assert(equal(arr[], [Monday, Tuesday, Wednesday, Friday])); } C++ does it basically the same way that D does, but it's actually one place where iterators are cleaner, because you can just pass the iterator to erase, whereas with a range, that would remove all of the elements after that element, which is why you need take, which makes it that much more complicated. Using opSlice like that along with range-based functions like find which don't return a new range type will always be what you'll need to do in the general case, but it would definitely be nice if we added functions like removeFirst to remove elements which matched a specific value so that the simple use cases didn't require using find. - Jonathan M Davis
Re: multidimensional indexing/slicing docs?
On Wednesday, 6 August 2014 at 08:48:25 UTC, John Colvin wrote: Is there anywhere that describes what Kenji (it was Kenji wasn't it?) recently implemented for this? Not what you asked for, but maybe useful nonetheless: Denis Shelomovskij has written a multidimensional array implementation using the new syntax[1]. I've been using it in my code for a while now and it's been working great so far. [1] http://denis-sh.bitbucket.org/unstandard/unstd.multidimarray.html
Re: alias to fully qualified enum in scope where enum is expected
On Wed, Aug 6, 2014 at 12:04 PM, via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Wednesday, 6 August 2014 at 16:48:57 UTC, Timothee Cour via Digitalmars-d-learn wrote: Thanks, I know with statement could be used but I was hoping for a solution not involving adding syntax to call site. If you control the declaration of the enum, you could write: alias a1 = A.a1; alias a2 = A.a2; A bit tedious, but it works, and could be automated if need be. yes, but that pollutes the scope, what I wanted was to only expose the aliases in places where A is expected, see motivational in previous message: void fun(with(A){A a}, int b){...} //conceptually like this void test(){ int a1=1; fun(A.a1, a1); fun(a1, a1);// first a1 refers to A.a1, second one to local variable int a1 } ok I guess this isn't possible using current semantics.
Re: unittest affects next unittest
On Wednesday, 6 August 2014 at 17:42:02 UTC, Jonathan M Davis wrote: It wouldn't make sense to warn about that, because it could be very legitimately be what the programmer wants to do. We can't warn about anything that would be legitimate to have, because it would force programmers to change their code to get rid of the warning, even when the code was valid. So, while in most cases, it might be a problem, we can't warn about it. But I do think that the spec should be clearer about it. This is the similar problem to assignment inside if statements where it's easy to mistake and can cause problems later. I think it should warn, because the behavior although proper is a jarring difference from a class version of it. However to make the warning go away with 'yeah this is what i want so don't complain' a simple tag confirms while doubling as documentation for behavior would probably be enough. A short simple word probably wouldn't be enough for specific cases but something short... Maybe @shared_init or @propagates_statically, @static_assignment or something. Of course i don't want to litter the language with tags that aren't relevant except in certain obscure cases...
Re: Removing an element from a list or array
Thank you, that is a great sample. On Wednesday, 6 August 2014 at 19:41:50 UTC, Jonathan M Davis wrote: On Wednesday, 6 August 2014 at 19:01:26 UTC, Patrick wrote: I feel dumb. I've been searching for how to do this, and each page or forum entry I read makes me more confused. Let's say I have a list of values (Monday, Tuesday, Wednesday, Thursday, Friday). I can store this list in an Slist, Dlist, Array etc -- any collection is fine. I decide I want to remove Thursday from the list. How? I see that linearRemove is meant to do this, but that takes a range. How do I get a range of 'Thursday'? Slicing a container gives you a range for that container, and it's that type that needs to be used to remove elements (either that, or that type wrapped with std.range.Take), since otherwise, the container wouldn't know which elements you were trying to remove - just their values. You need to use std.algorithm.find to find the element that you want to remove, in which case, you have a range starting at that element (but it contains everything after it too). So, you used std.range.take to take the number of elements that you want from the range, and then you pass that result to linearRemove. e.g. import std.algorithm; import std.container; import std.range; void main() { auto arr = Array!string(Monday, Tuesday, Wednesday, Thursday, Friday); auto range = arr[]; assert(equal(range, [Monday, Tuesday, Wednesday, Thursday, Friday])); auto found = range.find(Thursday); assert(equal(found, [Thursday, Friday])); arr.linearRemove(found.take(1)); assert(equal(arr[], [Monday, Tuesday, Wednesday, Friday])); } C++ does it basically the same way that D does, but it's actually one place where iterators are cleaner, because you can just pass the iterator to erase, whereas with a range, that would remove all of the elements after that element, which is why you need take, which makes it that much more complicated. Using opSlice like that along with range-based functions like find which don't return a new range type will always be what you'll need to do in the general case, but it would definitely be nice if we added functions like removeFirst to remove elements which matched a specific value so that the simple use cases didn't require using find. - Jonathan M Davis
Re: private selective imports
Sure, but people keep using them at the module-level, which really shouldn't be done until the bug is fixed. IMHO, we'd be better off making it illegal to use selective imports at the module-level rather than keeping it as-is. - Jonathan M Davis I'm curious, what's the problem with it anyway? Judging by the posts in the bug report and the bug's own lifespan this must be a real tough one to crack.
Re: private selective imports
On Wed, Aug 06, 2014 at 10:07:53PM +, Vlad Levenfeld via Digitalmars-d-learn wrote: Sure, but people keep using them at the module-level, which really shouldn't be done until the bug is fixed. IMHO, we'd be better off making it illegal to use selective imports at the module-level rather than keeping it as-is. - Jonathan M Davis I'm curious, what's the problem with it anyway? Judging by the posts in the bug report and the bug's own lifespan this must be a real tough one to crack. My guess is that it requires knowledge of dmd internals that only few people have, and those few people have other fires to put out right now. T -- Be in denial for long enough, and one day you'll deny yourself of things you wish you hadn't.
Re: private selective imports
On Wednesday, 6 August 2014 at 22:24:24 UTC, H. S. Teoh via Digitalmars-d-learn wrote: My guess is that it requires knowledge of dmd internals that only few people have, and those few people have other fires to put out right now. Kenji has a PR with new symbol overload resolution system that fixes it but Walter disagrees with proposed rules - at least that was the last state of this PR when I checked.
Re: private selective imports
On Wed, Aug 06, 2014 at 10:55:14PM +, Dicebot via Digitalmars-d-learn wrote: On Wednesday, 6 August 2014 at 22:24:24 UTC, H. S. Teoh via Digitalmars-d-learn wrote: My guess is that it requires knowledge of dmd internals that only few people have, and those few people have other fires to put out right now. Kenji has a PR with new symbol overload resolution system that fixes it but Walter disagrees with proposed rules - at least that was the last state of this PR when I checked. So the way to proceed is to discuss overload resolution rules that Walter agrees with, then? T -- Without outlines, life would be pointless.
Re: multidimensional indexing/slicing docs?
On Wed, Aug 06, 2014 at 08:48:24AM +, John Colvin via Digitalmars-d-learn wrote: Is there anywhere that describes what Kenji (it was Kenji wasn't it?) recently implemented for this? https://github.com/D-Programming-Language/dlang.org/pull/625 --T
Re: BitArray/BitFields - Review
(Moved from: What have I missed?) If this is the wrong place to ask these questions I apologize, getting back into this takes some work. So I guess I need to ask: Should I try to resume work on the BitManip library? (So far it seems none of my code has been integrated to phobos) Assuming I do, should I try to fix lots of small bugs and make smaller pulls or should I try to do several at once? When I re-wrote the BitArray I personally think it is an overall improvement in many ways, and being a complete re-write you can't just do bug # and then bug # and then bug... etc etc. Also to ask, how many people tried out the rewrite I proposed, and do they think it was actually an improvement for ease of use, speed, fewer bugs/issues, etc?
Need help with building dmd
I'm trying to build dmd from source but make can't open the makefile. I checked out the source and everything and the make version I use is the one that comes with the distribution: Digital Mars Make Version 5.06 So I'm in the source folder (...\dmd2\src\dmd\src), I can clearly see that there is the file win32.mak present and I run: make release -fwin32 Here is the output: Error: can't read makefile 'win32' I'm building on Windows btw. Thanks, Phil
Re: Need help with building dmd
On Thursday, 7 August 2014 at 01:15:36 UTC, Phil Lavoie wrote: [...] make release -fwin32 Here is the output: Error: can't read makefile 'win32' I'm building on Windows btw. Thanks, Phil Close. You need the extension, I believe. make -f win32.mak release
Re: Need help with building dmd
On Thursday, 7 August 2014 at 01:18:52 UTC, Brad Anderson wrote: On Thursday, 7 August 2014 at 01:15:36 UTC, Phil Lavoie wrote: [...] make release -fwin32 Here is the output: Error: can't read makefile 'win32' I'm building on Windows btw. Thanks, Phil Close. You need the extension, I believe. make -f win32.mak release Nope, still not working, but thx.
Re: Need help with building dmd
On Thursday, 7 August 2014 at 01:27:55 UTC, Phil Lavoie wrote: Nope, still not working, but thx. Hmm, are you in the src directory?
Re: BitArray/BitFields - Review
On Thu, Aug 07, 2014 at 01:10:06AM +, Era Scarecrow via Digitalmars-d-learn wrote: (Moved from: What have I missed?) If this is the wrong place to ask these questions I apologize, getting back into this takes some work. Since this is about contributing to Phobos, probably a better place to ask is on the main D forum. So I guess I need to ask: Should I try to resume work on the BitManip library? (So far it seems none of my code has been integrated to phobos) Do you have a pull request? Which one is it? Assuming I do, should I try to fix lots of small bugs and make smaller pulls or should I try to do several at once? When I re-wrote the BitArray I personally think it is an overall improvement in many ways, and being a complete re-write you can't just do bug # and then bug # and then bug... etc etc. Also to ask, how many people tried out the rewrite I proposed, and do they think it was actually an improvement for ease of use, speed, fewer bugs/issues, etc? There have been a few fixes to std.bitmanip recently, including a current PR for adding attributes to some of the functions. Are these your PRs, or are you proposing something totally new? If it's something totally new, where can we get the code? T -- Maybe is a strange word. When mom or dad says it it means yes, but when my big brothers say it it means no! -- PJ jr.
Re: Need help with building dmd
On Thursday, 7 August 2014 at 01:37:46 UTC, Brad Anderson wrote: On Thursday, 7 August 2014 at 01:27:55 UTC, Phil Lavoie wrote: Nope, still not working, but thx. Hmm, are you in the src directory? Yes and ls *.mak shows three makefiles: osmodel.mak posix.mak win32.mak
Re: BitArray/BitFields - Review
On Thursday, 7 August 2014 at 01:51:46 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Since this is about contributing to Phobos, probably a better place to ask is on the main D forum. Yeah posted in my 'what have i missed?' as well... Do you have a pull request? Which one is it? https://github.com/rtcvb32/phobos/pull/1 From the looks of things it's 4 commits that are merged into a single request i think... There have been a few fixes to std.bitmanip recently, including a current PR for adding attributes to some of the functions. Are these your PRs, or are you proposing something totally new? If it's something totally new, where can we get the code? Glancing at the current code, none of my stuff got in. I do a large number of fixes, so likely a lot of those changes would get thrown away or integrated... Knock yourself out... the pull/1 above holds most of the commits and diff/changes to note of. https://github.com/rtcvb32/phobos/blob/master/std/bitmanip.d
Re: Member access of __gshared global object
On Wednesday, 6 August 2014 at 15:42:05 UTC, Marc Schütz wrote: On Wednesday, 6 August 2014 at 15:18:15 UTC, Dragos Carp wrote: On Wednesday, 6 August 2014 at 14:36:23 UTC, Marc Schütz wrote: This would defeat the purpose, see the original post. sorry, I red just the last post. __gshared has no influence on this. Indeed, it was just what the OP suspected as the culprit. You are right, I didn't know about the AA initialization problem then. When I writln the AA and it outputs '[]', I thought it was initialized, which in that case was actually null. auto cmds = CONFIG.commands; cmds[list] = new Command(...); cmds is a thread local variable referencing the shared AA. But if you add new elements to cmds, cmd will be reallocated and the shared AA will remain unchanged. Though, updated values of existing keys will be visible in the original, because no relocation takes place. This describes the semantics of regular arrays. Are you sure it also applies to AAs? I thought they will keep referring to the same data once they are initialized. But I might be mistaken... If you want to change the original you need a pointer or a reference (for a setter function). auto cmds = CONFIG.commands; (*cmds)[list] = new Command(...);
Re: BitArray/BitFields - Review
On Thursday, 7 August 2014 at 02:04:13 UTC, Era Scarecrow wrote: On Thursday, 7 August 2014 at 01:51:46 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Do you have a pull request? Which one is it? https://github.com/rtcvb32/phobos/pull/1 From the looks of things it's 4 commits that are merged into a single request i think... Looks like that pull is just the bitfields... but the actual bitmanip one i listed has the whole source.
Re: BitArray/BitFields - Review
On Thu, Aug 07, 2014 at 02:04:12AM +, Era Scarecrow via Digitalmars-d-learn wrote: On Thursday, 7 August 2014 at 01:51:46 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Since this is about contributing to Phobos, probably a better place to ask is on the main D forum. Yeah posted in my 'what have i missed?' as well... Do you have a pull request? Which one is it? https://github.com/rtcvb32/phobos/pull/1 From the looks of things it's 4 commits that are merged into a single request i think... Hold on a sec... that's a pull for your own fork of Phobos. You need to submit a pull to the main Phobos repo in order to get it reviewed and merged. :-) There have been a few fixes to std.bitmanip recently, including a current PR for adding attributes to some of the functions. Are these your PRs, or are you proposing something totally new? If it's something totally new, where can we get the code? Glancing at the current code, none of my stuff got in. I do a large number of fixes, so likely a lot of those changes would get thrown away or integrated... [...] Well, no wonder, your pull was submitted against your local fork, not to the main Phobos repo, so nobody knew about it (except Dmitry, apparently). It would help to submit pulls against the main Phobos repo. :-) Also, looks like you made major changes to the code... if it's a complete rewrite, I'd say submit it as a single pull. If it's a collection of many fixes, it's probably better to submit separate pulls so that the easy fixes will get in first while we work out the wrinkles on the more complicated fixes. T -- Любишь кататься - люби и саночки возить.
Re: Need help with building dmd
On Thursday, 7 August 2014 at 01:50:50 UTC, Phil Lavoie wrote: On Thursday, 7 August 2014 at 01:37:46 UTC, Brad Anderson wrote: On Thursday, 7 August 2014 at 01:27:55 UTC, Phil Lavoie wrote: Nope, still not working, but thx. Hmm, are you in the src directory? Yes and ls *.mak shows three makefiles: osmodel.mak posix.mak win32.mak ls? If you're not, I recommend using the cmd.exe terminal. optlink has had problems with using other terminals. You may want to look at this guide if you haven't already: http://wiki.dlang.org/Building_DMD
Re: Member access of __gshared global object
On Thu, Aug 07, 2014 at 02:00:27AM +, Puming via Digitalmars-d-learn wrote: On Wednesday, 6 August 2014 at 15:42:05 UTC, Marc Schütz wrote: [...] Indeed, it was just what the OP suspected as the culprit. You are right, I didn't know about the AA initialization problem then. When I writln the AA and it outputs '[]', I thought it was initialized, which in that case was actually null. [...] This is a known gotcha with AA's and built-in arrays: they are null until you insert something into them, which means that while they are null, passing them into functions that add stuff to them won't update the original references because there is no common object that null points to. But once they become non-empty, passing them around to functions that change their contents will affect what's seen through the original references, since now they are pointing at a common object in memory. So they behave like value types when null, but acquire reference semantics once they are non-empty. This can be rather confusing for newbies. T -- Ignorance is bliss... until you suffer the consequences!
Re: Need help with building dmd
On Thursday, 7 August 2014 at 02:13:38 UTC, Brad Anderson wrote: On Thursday, 7 August 2014 at 01:50:50 UTC, Phil Lavoie wrote: On Thursday, 7 August 2014 at 01:37:46 UTC, Brad Anderson wrote: On Thursday, 7 August 2014 at 01:27:55 UTC, Phil Lavoie wrote: Nope, still not working, but thx. Hmm, are you in the src directory? Yes and ls *.mak shows three makefiles: osmodel.mak posix.mak win32.mak ls? If you're not, I recommend using the cmd.exe terminal. optlink has had problems with using other terminals. You may want to look at this guide if you haven't already: http://wiki.dlang.org/Building_DMD Yeah I read that thx. Well, it seems like it was indeed the powershell that was troubling it. Just tried it with cmd and it seems to work. Thx Brad, Phil
Re: BitArray/BitFields - Review
On Thursday, 7 August 2014 at 02:12:20 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Hold on a sec... that's a pull for your own fork of Phobos. You need to submit a pull to the main Phobos repo in order to get it reviewed and merged. :-) Well, no wonder, your pull was submitted against your local fork, not to the main Phobos repo, so nobody knew about it (except Dmitry, apparently). It would help to submit pulls against the main Phobos repo. :-) Also, looks like you made major changes to the code... if it's a complete rewrite, I'd say submit it as a single pull. If it's a collection of many fixes, it's probably better to submit separate pulls so that the easy fixes will get in first while we work out the wrinkles on the more complicated fixes. I did submit it against the original Phobos, and the auto tester picked it up. For something like 3-4 weeks it tried and kept failing over and over again because it couldn't merge it. The reason? It was something like 13 unresolved newlines that didn't match up... or something that I have no idea how I could fix because whitespace is invisible. Later Walter or Andrei (I forget who) complained when they looked at it and wanted me to break it apart into smaller more indivdual bug fixes (since it's hard to tell what i changed as a single blob/replacement) but as a complete re-write and I don't know if I COULD do that... Trust me. I tried. It failed. Eventually I just pulled the request and gave up at that time... Right about the time of the Dconf 2013 I got burned out and got depressed (Probably major changes in meds).