rdmd --makedepend requires -of; how to just print to stdout?
In 2.065 rdmd would just print the stuff from --makedepend to stdout, now it seems to require -of. How to print to stdout like before? (On Windows) cheers! /k
Re: Installing LDC on Windows
On Sat, 2014-09-06 at 21:52 +, David Nadlinger via Digitalmars-d-learn wrote: On Saturday, 6 September 2014 at 16:11:55 UTC, Russel Winder via Digitalmars-d-learn wrote: I installed the other MinGW option and it provides libgcc_s_sjlj-1.dll which is not helping me actually run ldc2 on Windows :-( It is mentioned both the in README coming with the Windows packages and the on wiki [1] that you need a Dwarf 2 EH package (-dw2) of MinGW-w64 for LDC to work. How can we make this more clear? I wasn't looking at anything that was to do with building LDC on Windows, so I guess I just didn't look. I wanted a binary download install process. LDC came down fine, but it was then a question of getting MinGW-w64. The MinGW-w64 installer only offers seh and sjlj as options it doesn't offer dw2. I probably would have read the README eventually, but I wasn't in the frame of mind of doing this: I just wanted to test something on Windows quickly and give the machine back. I am therefore a bad sample for worrying about making things clear! :-) On Linux, I happily build LDC from a Git repository clone, I have even got it all working on OSX as well. I just don't do Windows… but for the SCons D tools Windows tests need running… -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder signature.asc Description: This is a digitally signed message part
How to pack types with variables in one message to send it to another thread? [tuple]
Hi! I'm trying to make my program multithreaded, and I was stuck at messaging between threads. I need to pack types and variables into one message. Will I use Tuples or something? e.g. class Sprite {}; send(tid, Sprite, create, myInt); Also I don't understand how to use Variant. Messages can be different, and I don't know how to extract data from variant. send(tid, One, Two, myInt); receive( (Variant args) { /* args contains Tuple!(string, string, int)(One, Two, 42); I need simple access to data, e.g. args[0] args[1] args[2] but I don't know how to do this because `.get` method need precise type of Tuple */ } ); Regards, MarisaLovesUsAll
Re: How to pack types with variables in one message to send it to another thread? [tuple]
On 7/09/2014 10:42 p.m., MarisaLovesUsAll wrote: Hi! I'm trying to make my program multithreaded, and I was stuck at messaging between threads. I need to pack types and variables into one message. Will I use Tuples or something? e.g. class Sprite {}; send(tid, Sprite, create, myInt); Don't worry about the packing when calling send. It'll automatically be converted into a tuple. Also you should only be using immutable or primitive types. Strings are immutable so thats ok. A class instance that isn't immutable isn't. Note Sprite is a class type not a class instance. Also I don't understand how to use Variant. Messages can be different, and I don't know how to extract data from variant. send(tid, One, Two, myInt); receive( (Variant args) { /* args contains Tuple!(string, string, int)(One, Two, 42); I need simple access to data, e.g. args[0] args[1] args[2] but I don't know how to do this because `.get` method need precise type of Tuple */ } ); Don't worry about it. Just have separate receiving functions per the data type. You'll probably be better off. In other words Variant is overkill. It basically just wraps a piece of data so that it can be passed around without knowing its type. Which in this case is bad. You would end up having to know the datatype to do anything with it anyway.
Re: How to pack types with variables in one message to send it to another thread? [tuple]
On Sunday, 7 September 2014 at 10:42:37 UTC, MarisaLovesUsAll wrote: Hi! I'm trying to make my program multithreaded, and I was stuck at messaging between threads. I need to pack types and variables into one message. Will I use Tuples or something? e.g. class Sprite {}; send(tid, Sprite, create, myInt); Also I don't understand how to use Variant. Messages can be different, and I don't know how to extract data from variant. send(tid, One, Two, myInt); receive( (Variant args) { /* args contains Tuple!(string, string, int)(One, Two, 42); I need simple access to data, e.g. args[0] args[1] args[2] but I don't know how to do this because `.get` method need precise type of Tuple */ } ); Regards, MarisaLovesUsAll receive() automatically expands tuples into multiple arguments. receive((string s, string t, int i) { });
Re: How to pack types with variables in one message to send it to another thread? [tuple]
Thanks for reply. Strings are immutable so thats ok. A class instance that isn't immutable isn't. It's not a class instance, it's a class type. Something like `cast(Sprite) null` in parameters. It can be replaced by string Sprite, but in this case I can't use receive() as it is. E.g. send(tid,gameobjectId,Sprite,reload); //must call sprite.reload(); send(tid,gameobjectId,Animation,reload); //must call animation.reload(); Just have separate receiving functions per the data type. But both messages are (int, string, string) so they can't be separate by different receiving functions. It will be better if messages was (int, Sprite, string) / (int, Animation, string). And it solves my problem. :) But I don't know how to achieve this. In other words Variant is overkill. It basically just wraps a piece of data so that it can be passed around without knowing its type. Which in this case is bad. You would end up having to know the datatype to do anything with it anyway. Then I need something like Variant[] to store this data in array. MyVariant[] args; if(args[0] == typeid(int)) { if(args[1] == Sprite) {} if(args[1] == Animation) {} } etc. I'm trying to make something like messages in Smalltalk (?), but between threads. Thread can receive anything and thread decides what to do on its own.
Re: How to pack types with variables in one message to send it to another thread? [tuple]
On 8/09/2014 12:39 a.m., MarisaLovesUsAll wrote: Thanks for reply. Strings are immutable so thats ok. A class instance that isn't immutable isn't. It's not a class instance, it's a class type. Something like `cast(Sprite) null` in parameters. It can be replaced by string Sprite, but in this case I can't use receive() as it is. E.g. send(tid,gameobjectId,Sprite,reload); //must call sprite.reload(); send(tid,gameobjectId,Animation,reload); //must call animation.reload(); Those calls to send are fine. Just have separate receiving functions per the data type. But both messages are (int, string, string) so they can't be separate by different receiving functions. It will be better if messages was (int, Sprite, string) / (int, Animation, string). And it solves my problem. :) But I don't know how to achieve this. In the given send function calls you don't need to. Just use if statements to check the string type. In other words Variant is overkill. It basically just wraps a piece of data so that it can be passed around without knowing its type. Which in this case is bad. You would end up having to know the datatype to do anything with it anyway. Then I need something like Variant[] to store this data in array. MyVariant[] args; if(args[0] == typeid(int)) { if(args[1] == Sprite) {} if(args[1] == Animation) {} } etc. No need. http://dlang.org/phobos/std_concurrency.html#.receive receive( (int id, string type, string action) { if (type == Sprite) { if (action == reload) mySprite.reload(); } else if (type == Animation) { if (action == reload) myAnimation.reload(); } } );
Higher Order AA Algorithms
What's the preferred to apply higher-order algorithms such as map and filter on AAs which operate on both key and value? Has there been any progress since http://forum.dlang.org/thread/mailman.75.1392335793.6445.digitalmars-d-le...@puremagic.com
Re: How to pack types with variables in one message to send it to another thread? [tuple]
You can also create new types: struct UseSprite { string s;} struct UseAnimation { string s;} It's not a class instance, it's a class type. Something like `cast(Sprite) null` in parameters. It can be replaced by string Sprite, but in this case I can't use receive() as it is. E.g. send(tid,gameobjectId,Sprite,reload); //must call sprite.reload(); You could use: sent(tid, gameobjectId, UseSprite(reload)); send(tid,gameobjectId,Animation,reload); //must call animation.reload(); sent(tid, gameobjectId, UseAnimation(reload)); Another way, if you have way to determine that gameobjectId points to an animation or a sprite, would be to define a struct name Reload {} and then: sent(tid, gameobjectId, Reload()); Third way: if Animation.reload() and Sprite.reload() are static methods: send(tid, gameobjectId, Sprite.reload); But both messages are (int, string, string) so they can't be separate by different receiving functions. It will be better if messages was (int, Sprite, string) / (int, Animation, string). And it solves my problem. :) But I don't know how to achieve this. See my proposal: define your message as types, directly, and load them for any data necessary for the call. UseAnimation(reload), or whatever.
Re: How to pack types with variables in one message to send it to another thread? [tuple]
No need. Message has additional arguments. Btw, thanks for help! I found a solution. struct Message { uint id; string command; Variant[] args; this(T...)(uint id, string command, T args) { this.id = id; this.command = command; this.args = variantArray(args); } }; send(tid, cast(immutable Message) Message(id, Sprite, load, filename)); receive((immutable Message receivedMsg) { Message msg = cast(Message) receivedMsg; writeln(msg.args[1].get!uint); }); Cast to immutable and back to mutable looks like crutch, but I don't know what to do with std.concurrency restrictions.
Lossless Bidirectional Enum-Conversions Mixin
Have anybody come up with some mixin magic that given enum A { x,y,z } enum B { a,b,c } and call to a mixin BidirectionalEnums( x, a, y, b, z, c, ); generates two to!Enum overloads that implement bidirectional (lossless) conversion rules between A and B?
Re: Lossless Bidirectional Enum-Conversions Mixin
On Sunday, 7 September 2014 at 17:22:38 UTC, Nordlöw wrote: BidirectionalEnums( x, a, y, b, z, c, ); The enumeration names must of course be given aswell: BidirectionalEnums2( A, B, x, a, ... ); and two specifies the number of enums involved. We could of course also use BidirectionalEnums( tuple(A, B), tuple(x, a), ... ); for more verbosity.
Re: dmd dub from git master
I had the same problem just now... on Win8.1 with - DMD32 D Compiler v2.066.0 - DUB version 0.9.21 The workaround is to manually update the dub.json file of your project, which was written from dub init, to the latest vibe-d info on http://code.dlang.org/packages/vibe-d;, so dependencies: { vibe-d: =0.7.21-beta.1 }, Regards Anton Oks On Monday, 7 July 2014 at 17:00:30 UTC, Nordlöw wrote: I got things to work after some cleanups of the DUB installations. I don't know exactly how...but no things work :)
Re: Allowing Expressions such as (low value high)
On Thursday, 4 September 2014 at 20:03:57 UTC, Nordlöw wrote: Are there any programming languages that extend the behaviour of comparison operators to allow expressions such as if (low value high) ? This syntax is currently disallowed by DMD. I'm aware of the risk of a programmer misinterpreting this as if ((low value) high) Is this the reason why no languages (including D allows it). I'm asking for in some cases, where value is a long expression, it would be a nice syntatic sugar to use. I know Coffeescript has them, they are called 'chained comparison operators' I believe and are a nice syntax cake imo. they are written as expected: if 10 a 20
Re: opSlice() or opIndex() for the entire slice?
I think I figured this one out. Before 2.066, we did not have proper support for multi-dimensional slicing. The following were the semantics we had: -- The opIndex() overloads provided access to direct elements. Since multi-dimensional support was incomplete, opIndex() was about accessing a single object: a[i] // element i by opIndex(size_t) a[i, j] // element i,j by opIndex(size_t, size_t) -- The two overloads of opSlice() returned range objects that represented either all of the elements or a slice of them: a[]// opSlice() a[i..j]// opSlice(size_t, size_t) Note that those features are still usable but according to documentation, they are discouraged. Since 2.066, we have multi-dimensional slicing. The way we look at these operators have changed a little: -- The opIndex() overloads now return ranges that represent a range of elements. For example, if 'a' is a two-dimensional matrix, the first line below should return a sub-matrix inside it, not a single element: a[i..j, k..l]// opIndex(MyRange, MyRange) The following can indeed return a single element but I think it is a valid design decision to return a sub-matrix consisting of a single element as well: a[i, j]// a matrix of one element by opIndex(size_t size_t) A single matrix row: a[i, j..j] // opIndex(size_t, MyRange) Here is the answer to my original question: Consistent with the above, now opIndex() must take the responsibility of returning all of the elements: a[] // opIndex() -- With that change of responsibility, what remains for opSlice() is the only task of producing a range object that opIndex() can later use to represent one or more elements: a[i..j, k..l] // opIndex(opSlice(i, j), opSlice(k, l)) In summary, the following is what opSlice() should do almost in all cases: Tuple!(size_t size_t) opSlice(size_t beg, size_t end) { return tuple(beg, end); } Also note that representing i..j and k..l can always be done by a Tuple!(size_t, size_t) without loss of any information. (i.e. MyRange above can actually be Tuple!(size_t, size_t)): I am attaching an example that helped me understand what was going on. Note that the program is decidedly elegant as opposed to efficient. :) For example, even initializing a single element by random access goes through these steps: Initializing 1 of 80 deneme.Matrix.opIndexAssign!(int, int).opIndexAssign deneme.Matrix.opIndex!(int, int).opIndex deneme.Matrix.opDollar!0LU.opDollar deneme.Matrix.opDollar!1LU.opDollar deneme.Matrix.subMatrix deneme.Matrix.this deneme.Matrix.opAssign [...] But I like it. :) Ali import std.stdio; import std.format; import std.string; struct Matrix { private: int[][] rows; /* Represents a range of rows of columns. */ struct Range { size_t beg; size_t end; } /* Returns a reference to a sub-matrix that correspond to * the range arguments. */ Matrix subMatrix(Range rowRange, Range columnRange) { writeln(__FUNCTION__); int[][] slices; foreach (row; rows[rowRange.beg .. rowRange.end]) { slices ~= row[columnRange.beg .. columnRange.end]; } return Matrix(slices); } public: this(size_t height, size_t width) { writeln(__FUNCTION__); rows = new int[][](height, width); } this(int[][] rows) { writeln(__FUNCTION__); this.rows = rows; } void toString(void delegate(const(char)[]) sink) const { formattedWrite(sink, %(%(%5s %)\n%), rows); } /* Assigns the value to all of the elements of the * matrix. */ Matrix opAssign(int value) { writeln(__FUNCTION__); foreach (row; rows) { row[] = value; } return this; } /* Applies the operation to each element and assigns the * result back to it. e.g. 'm += 42'*/ Matrix opOpAssign(string op)(int value) { writeln(__FUNCTION__); foreach (row; rows) { mixin (row[] ~ op ~ = value;); } return this; } /* Returns the size of the provided dimension. */ size_t opDollar(size_t dimension)() const { writeln(__FUNCTION__); static if (dimension == 0) { return rows.length; } else static if (dimension == 1) { return rows.length ? rows[0].length : 0; } else { static assert(false, format(Invalid dimension: %s, dimension)); } } /* Returns a range representing the provided indices. */ Range opSlice(size_t dimension)(size_t beg, size_t end) { writeln(__FUNCTION__); return Range(beg, end); } /* Returns a sub-matrix corresponding to the arguments. */ Matrix opIndex(A...)(A args) {
Novice web developer trying to learn D
Hello, First, here is my Linkedin profile http://www.linkedin.com/in/andreiboar in order to make an image of my professional background. I do realise here are really good programmers for which this background might sound like a joke, but this is what I did so far. After watching some presentantions from DConf, and trying the language I decided to give it a try in the future. Currrently I'm reading the Programming in D book by Ali Çehreli, and then The D Programming Language by Andrei Alexandrescu in order to learn more. The reason I post this is to ask you what other books do you think I should try in order to become hireable in the next 2 years? As a web developer I know I lack a lot of information, but I'm willing to do the hard work. So if anyone has any other books/things I need to know and is willing to make me like a small roadmap to become a good D developer I would really appreciate. Thanks a lot, Andrei
Re: Novice web developer trying to learn D
There's Adam Ruppe's excellent D Cookbook available here: https://www.packtpub.com/application-development/d-cookbook And since you specifically said web developer I hope you're looking at vibe.d: http://vibed.org/
Re: Novice web developer trying to learn D
On Sunday, 7 September 2014 at 21:06:48 UTC, zuzuleinen wrote: Hello, First, here is my Linkedin profile http://www.linkedin.com/in/andreiboar in order to make an image of my professional background. I do realise here are really good programmers for which this background might sound like a joke, but this is what I did so far. After watching some presentantions from DConf, and trying the language I decided to give it a try in the future. Currrently I'm reading the Programming in D book by Ali Çehreli, and then The D Programming Language by Andrei Alexandrescu in order to learn more. The reason I post this is to ask you what other books do you think I should try in order to become hireable in the next 2 years? As a web developer I know I lack a lot of information, but I'm willing to do the hard work. So if anyone has any other books/things I need to know and is willing to make me like a small roadmap to become a good D developer I would really appreciate. Thanks a lot, Andrei I would also recommend for you to investigate my work on: Cmsed[0] Dakka[1] Dvorm[2] livereload[3] skeleton[4] Please note next version of Cmsed which will support livereload/skeleton/Dakka is currently not ready to go on github. [0] https://github.com/rikkimax/Cmsed [1] https://github.com/rikkimax/dakka [2] https://github.com/rikkimax/Dvorm [3] https://github.com/rikkimax/livereload [4] https://github.com/rikkimax/skeleton
D1: Windows DWORD conversion in D
Greetings. I have a type long variable, ie. long v = 1024; and I have to pass it to a Window's function and it's not working. I found out that I have to pass a DWORD to the function, and I know that dchar is somewhat close to DWORD, so, how do I pass this to this Windows function? Anyone knows? Thanks. josé
Re: Allowing Expressions such as (low value high)
On Thursday, 4 September 2014 at 20:33:45 UTC, Nordlöw wrote: On Thursday, 4 September 2014 at 20:25:52 UTC, monarch_dodra wrote: In the case of D, it's a C compatibility thing. Other languages I don't know. FYI, auto x = 1 2 3; as C++ is accepted (but warned about) by GCC as x.cpp:19:20: warning: comparisons like ‘X=Y=Z’ do not have their mathematical meaning [-Wparentheses] auto x = 1 2 3; Clang gives no warning. Very surprising clang doesn't. But it willn't take so long to do so.