How to expand an expression along with a parameter tuple?

2013-06-17 Thread TommiT
I can't figure out how to do the following C++ code in D: int arr[] = { 1, 3, 5, 7, 11 }; template typename... T void foo(T... values) { } template typename... T void bar(T... values) { foo((arr[values] * 10)...); } int main() { bar(1, 3, 4); /* calls foo(arr[1] * 10,

Re: How to expand an expression along with a parameter tuple?

2013-06-17 Thread TommiT
Although... now that I think about it, this should really be done as a language feature, and not through some inefficient CTFE trick. So, I should really be able to just write this: int[5] arr = [ 1, 3, 5, 7, 11 ]; void foo(T...)(T values) { } void bar(T...)(T values) { foo((arr[values]

Re: How to expand an expression along with a parameter tuple?

2013-06-17 Thread Ali Çehreli
On 06/16/2013 11:19 PM, TommiT wrote: I can't figure out how to do the following C++ code in D: int arr[] = { 1, 3, 5, 7, 11 }; template typename... T void foo(T... values) { } template typename... T void bar(T... values) { foo((arr[values] * 10)...); } int main() {

Re: 64bit window headers

2013-06-17 Thread PewPew
On Sunday, 16 June 2013 at 16:44:59 UTC, new wrote: hi, are there any 64bit windows header files availabe? You can use win api directly. 32/64 bit handled by defines, __WIN32__ etc. FucnA - for 32 bit, FuncW - for 64 bit. In D: version(...){ ... }

Re: 64bit window headers

2013-06-17 Thread Mike Parker
On Monday, 17 June 2013 at 07:46:46 UTC, PewPew wrote: 32/64 bit handled by defines, __WIN32__ etc. FucnA - for 32 bit, FuncW - for 64 bit. This is wrong. The *A functions deal with ascii strings, whereas the *W functions deal with unicode strings. Functions that neither return nor accept

Re: 64bit window headers

2013-06-17 Thread new
thank you all for your help.

Re: Can someone give me a little program design advice please?

2013-06-17 Thread Regan Heath
On Sun, 16 Jun 2013 16:27:27 +0100, Gary Willoughby d...@kalekold.net wrote: I'm writing a little program in D to perform some database operations and have a small question about design. Part of my program watches a log file for changes and this involves code which is wrapped up in a

Re: How to expand an expression along with a parameter tuple?

2013-06-17 Thread TommiT
On Monday, 17 June 2013 at 07:20:23 UTC, Ali Çehreli wrote: The following does not answer the question of expanding but at least foo() receives [30, 70, 110] :) import std.stdio; import std.algorithm; import std.array; import std.range; int[] arr = [ 1, 3, 5, 7, 11 ]; void foo(T)(T[]

Example on how to spawn a thread using a class method?

2013-06-17 Thread Gary Willoughby
Anyone got an example on how to spawn a thread using a class method? I want to wrap behaviour in a class and launch one of its methods using a thread. Once the method is running i want to interact with it from the main program by calling other methods which send the thread messages. I'm

Re: How to expand an expression along with a parameter tuple?

2013-06-17 Thread Artur Skawina
On 06/17/13 11:32, TommiT wrote: On Monday, 17 June 2013 at 07:20:23 UTC, Ali Çehreli wrote: The following does not answer the question of expanding but at least foo() receives [30, 70, 110] :) import std.stdio; import std.algorithm; import std.array; import std.range; int[] arr = [ 1,

Re: How to expand an expression along with a parameter tuple?

2013-06-17 Thread TommiT
On Monday, 17 June 2013 at 11:15:24 UTC, Artur Skawina wrote: On 06/17/13 11:32, TommiT wrote: On Monday, 17 June 2013 at 07:20:23 UTC, Ali Çehreli wrote: The following does not answer the question of expanding but at least foo() receives [30, 70, 110] :) import std.stdio; import

Re: How to expand an expression along with a parameter tuple?

2013-06-17 Thread Artur Skawina
On 06/17/13 13:23, TommiT wrote: On Monday, 17 June 2013 at 11:15:24 UTC, Artur Skawina wrote: void bar(T...)(T values) { T tmp; foreach (i, ref v; values) tmp[i] = arr[v]*10; foo(tmp); } Cool, I didn't know that you could create multiple variables like

Re: How to expand an expression along with a parameter tuple?

2013-06-17 Thread TommiT
On Monday, 17 June 2013 at 12:21:31 UTC, Artur Skawina wrote: A more correct, but a bit less readable version (the types of 'values' and 'arr' elements do not have to match) would be: void bar(T...)(T values) { static if (T.length) { NTup!(T.length, typeof(arr[T[0].init]))

Linker issue?

2013-06-17 Thread Josh
I've copied the source code from vibe.d's mongodb example into an Eclipse DDT project, and I can't seem to get it to compile, even though I *think* I've made the build options resemble what vibe uses to build. build.rf: -odbin -ofbin\TestProg.exe -Isrc -IC:\D\vibe.d\source

Re: How to expand an expression along with a parameter tuple?

2013-06-17 Thread Artur Skawina
On 06/17/13 14:57, TommiT wrote: On Monday, 17 June 2013 at 12:21:31 UTC, Artur Skawina wrote: A more correct, but a bit less readable version (the types of 'values' and 'arr' elements do not have to match) would be: void bar(T...)(T values) { static if (T.length) {

Re: How to expand an expression along with a parameter tuple?

2013-06-17 Thread bearophile
Artur Skawina: Yes, this is not as concise as '...' would be. But, with a bit more tuple support in the language, the '.tuple' part wouldn't be necessary, Implicit things are dangerous in languages. .tuple can also be written []. Bye, bearophile

D style guide

2013-06-17 Thread Joseph Rushton Wakeling
Hi all, A recent Phobos pull request got critiqued over some stylistic aspects -- which was obviously disappointing as I thought I'd learned those guidelines fairly well. Just to make sure, are the rules at http://dlang.org/dstyle.html considered to be the ones to follow -- and up to date?

Re: How to expand an expression along with a parameter tuple?

2013-06-17 Thread Ali Çehreli
On 06/17/2013 02:32 AM, TommiT wrote: On Monday, 17 June 2013 at 07:20:23 UTC, Ali Çehreli wrote: The following does not answer the question of expanding but at least foo() receives [30, 70, 110] :) import std.stdio; import std.algorithm; import std.array; import std.range; int[] arr

Re: D style guide

2013-06-17 Thread Ali Çehreli
Please ignore my comments because they are bike-shedding. I am not sure about Phobos coding guidelines. On 06/17/2013 09:13 AM, Joseph Rushton Wakeling wrote: * Space after if -- e.g. if (x 0) not if(x 0). This isn't cited, and in fact the example given (at the end of the page)

Re: D style guide

2013-06-17 Thread Jonathan M Davis
On Monday, June 17, 2013 17:13:07 Joseph Rushton Wakeling wrote: So, have I missed something in a style guide in a different location, or have these rules simply been adopted by custom without making it into official guidelines? If the latter, should I make a pull request for the website? :-)

Re: Finalize GC memory

2013-06-17 Thread Namespace
On Sunday, 16 June 2013 at 21:37:16 UTC, Namespace wrote: It seems that does what I want. The result is the same as with the current 'delete' implementation. void Delete(T)(ref T var) { static if (is(T == struct) is(typeof(var.__dtor))) var.__dtor();

Re: Finalize GC memory

2013-06-17 Thread Jonathan M Davis
On Monday, June 17, 2013 18:46:29 Namespace wrote: On Sunday, 16 June 2013 at 21:37:16 UTC, Namespace wrote: It seems that does what I want. The result is the same as with the current 'delete' implementation. void Delete(T)(ref T var) { static if (is(T == struct)

Re: Finalize GC memory

2013-06-17 Thread Steven Schveighoffer
On Sun, 16 Jun 2013 17:37:15 -0400, Namespace rswhi...@googlemail.com wrote: But if I call 'destroy' before I call GC.free, it does not work correct. Destroy puts anything back into it's initial state. So for anything that is a pointer, destroy will set it to null! Then calling GC free

Re: Example on how to spawn a thread using a class method?

2013-06-17 Thread Ali Çehreli
On 06/17/2013 03:22 AM, Gary Willoughby wrote: Anyone got an example on how to spawn a thread using a class method? I want to wrap behaviour in a class and launch one of its methods using a thread. Once the method is running i want to interact with it from the main program by calling other

Re: GtkD: Best way to get TreeStore out of TreeView.Model

2013-06-17 Thread Mike Wey
On 06/17/2013 04:44 AM, Alex Horvat wrote: On Sunday, 16 June 2013 at 18:22:47 UTC, Mike Wey wrote: On 06/13/2013 06:14 AM, Alex Horvat wrote: On Wednesday, 12 June 2013 at 21:44:55 UTC, Mike Wey wrote: On 06/11/2013 07:55 PM, Alex Horvat wrote: On Tuesday, 11 June 2013 at 17:41:59 UTC, Mike

Re: Fibers vs Async/await

2013-06-17 Thread Sean Kelly
Fibers don't actually execute asynchronously. They represent an alternate execution context (code and stack) but are executed by the thread that calls them, and control is returned when they either yield or complete. This video is a good introduction to fibers: http://vimeo.com/1873969 On

Re: GC dead-locking ?

2013-06-17 Thread Sean Kelly
On Jun 13, 2013, at 2:22 AM, Marco Leise marco.le...@gmx.de wrote: Here is an excerpt from a stack trace I got while profiling with OProfile: #0 sem_wait () from /lib64/libpthread.so.0 #1 thread_suspendAll () at core/thread.d:2471 #2 gc.gcx.Gcx.fullcollect() (this=...) at gc/gcx.d:2427

Re: Mac OS crash, details inside...

2013-06-17 Thread Sean Kelly
On Jun 14, 2013, at 2:49 AM, Gary Willoughby d...@kalekold.net wrote: In fact i have the same problem reading files too. It only reads files up to a certain amount of bytes then crashes in the same manner explained above. Again this only happens when the program runs as a daemon. Run as a

Re: D style guide

2013-06-17 Thread Joseph Rushton Wakeling
On 06/17/2013 05:48 PM, Jonathan M Davis wrote: What's on the website is correct. Those are all the rules that are required for Phobos as a whole, and if you were creating a new module, you wouldn't have had any such issues. The problem is that we try and keep the style within modules

Re: D style guide

2013-06-17 Thread Joseph Rushton Wakeling
On 06/17/2013 05:36 PM, Ali Çehreli wrote: I want that space. It is very common in most C++ guidelines as well. Any particular reason? It's not something that had ever occurred to me as being important one way or the other. Yes, curly brackets are very helpful in readability even when there

Re: GtkD: Best way to get TreeStore out of TreeView.Model

2013-06-17 Thread Alex Horvat
On Monday, 17 June 2013 at 17:52:38 UTC, Mike Wey wrote: On 06/17/2013 04:44 AM, Alex Horvat wrote: On Sunday, 16 June 2013 at 18:22:47 UTC, Mike Wey wrote: On 06/13/2013 06:14 AM, Alex Horvat wrote: On Wednesday, 12 June 2013 at 21:44:55 UTC, Mike Wey wrote: On 06/11/2013 07:55 PM, Alex

Re: Linker issue?

2013-06-17 Thread Aleksandar Ruzicic
On Monday, 17 June 2013 at 13:15:35 UTC, Josh wrote: I've copied the source code from vibe.d's mongodb example into an Eclipse DDT project, and I can't seem to get it to compile, even though I *think* I've made the build options resemble what vibe uses to build. build.rf: -odbin

Re: D style guide

2013-06-17 Thread Ali Çehreli
On 06/17/2013 12:09 PM, Joseph Rushton Wakeling wrote: On 06/17/2013 05:36 PM, Ali Çehreli wrote: I want that space. It is very common in most C++ guidelines as well. Any particular reason? It's not something that had ever occurred to me as being important one way or the other. I have

Re: D style guide

2013-06-17 Thread H. S. Teoh
On Mon, Jun 17, 2013 at 12:58:08PM -0700, Ali Çehreli wrote: On 06/17/2013 12:09 PM, Joseph Rushton Wakeling wrote: On 06/17/2013 05:36 PM, Ali Çehreli wrote: I want that space. It is very common in most C++ guidelines as well. Any particular reason? It's not something that had ever

Re: D style guide

2013-06-17 Thread Joseph Rushton Wakeling
On 06/17/2013 08:58 PM, Ali Çehreli wrote: I have no idea why that style have evolved but I like it. :) The reason may be to distinguish from function calls: foo(expr) if (expr) I can't think anything else. Makes sense to me, and I do like these kinds of visual distinction. :-)

Re: How to expand an expression along with a parameter tuple?

2013-06-17 Thread Artur Skawina
On 06/17/13 16:20, bearophile wrote: Artur Skawina: Yes, this is not as concise as '...' would be. But, with a bit more tuple support in the language, the '.tuple' part wouldn't be necessary, Implicit things are dangerous in languages. Not sure what you mean. A bit more tuple support

Re: D style guide

2013-06-17 Thread Jonathan M Davis
On Monday, June 17, 2013 21:14:15 Joseph Rushton Wakeling wrote: On 06/17/2013 08:58 PM, Ali Çehreli wrote: I have no idea why that style have evolved but I like it. :) The reason may be to distinguish from function calls: foo(expr) if (expr) I can't think anything else.

Re: How to expand an expression along with a parameter tuple?

2013-06-17 Thread bearophile
Artur Skawina: .tuple can also be written []. No idea what you mean by this. If in the code you wrote you replace the first .tuple with [] the code keeps working. Bye, bearophile

Re: How to expand an expression along with a parameter tuple?

2013-06-17 Thread Artur Skawina
On 06/17/13 23:11, bearophile wrote: Artur Skawina: .tuple can also be written []. No idea what you mean by this. If in the code you wrote you replace the first .tuple with [] the code keeps working. It does not - I really have no idea what you mean; slicing a struct does not (and can

Re: Mac OS crash, details inside...

2013-06-17 Thread Gary Willoughby
Run as a daemon how? By running the above code. All the code before opening the file causes the program to run as a daemon.

Re: Finalize GC memory

2013-06-17 Thread Namespace
On Monday, 17 June 2013 at 17:09:45 UTC, Steven Schveighoffer wrote: On Sun, 16 Jun 2013 17:37:15 -0400, Namespace rswhi...@googlemail.com wrote: But if I call 'destroy' before I call GC.free, it does not work correct. Destroy puts anything back into it's initial state. So for anything

make Pid constructor public

2013-06-17 Thread Timothee Cour
inside std.process it says: // Pids are only meant to be constructed inside this module, so we make the constructor private. However, this makes a number of useful functions from std.process useless unless the processes were created via one of std.process' functions. Can we make

D slicing

2013-06-17 Thread Colin Grogan
Hi all. Wondering what way I'd go about this, I want to slice an array into two arrays. First array containing every even index (i.e. 0,2,4,6,8..$) Second slice containing every odd index (i.e. 1,3,5,7,9..$) -- be some issue with using $ depending on if orig length is odd or even. Can work

Re: D slicing

2013-06-17 Thread bearophile
Colin Grogan: Reading the articles on array slicing its not clear if its possible. I presume Walter thinks that slicing with a stride is a not common enough operation to put it into D. His choices on such things are a bit arbitrary. One way to do it: import std.stdio, std.array,

Re: D slicing

2013-06-17 Thread Andrej Mitrovic
On Monday, 17 June 2013 at 23:34:46 UTC, Colin Grogan wrote: auto orig = [1,2,3,4,5,6,7]; auto sliceEven = orig[0..$..2]; auto sliceOdd = orig[1..$..2]; But I dont think thats possible? Not with arrays, they must be contiguous. But you can use ranges instead: - import std.stdio;

Re: D slicing

2013-06-17 Thread Ali Çehreli
On 06/17/2013 04:34 PM, Colin Grogan wrote: Wondering what way I'd go about this, I want to slice an array into two arrays. First array containing every even index (i.e. 0,2,4,6,8..$) Second slice containing every odd index (i.e. 1,3,5,7,9..$) -- be some issue with using $ depending on if

Re: can we detect at compile time module ctor/dtor cycles ?

2013-06-17 Thread Andrej Mitrovic
On Saturday, 8 June 2013 at 06:31:14 UTC, Timothee Cour wrote: Why can't we detect at compile time module ctor/dtor cycles (instead of runtime) ? No idea, but I've wondered this myself too. After all imports are a static feature and all are known at compile-time.

Re: can we detect at compile time module ctor/dtor cycles ?

2013-06-17 Thread bearophile
Andrej Mitrovic: No idea, but I've wondered this myself too. After all imports are a static feature and all are known at compile-time. rdmd is used often in a situation where it knows all the modules of a program. So it must be able to detect those cycles. It seems an enhancement request

Re: Access violation when exiting program

2013-06-17 Thread Andrej Mitrovic
On Tuesday, 4 June 2013 at 14:06:29 UTC, Frank Fuente wrote: The function is declared... alias extern (C) FT_STATUS function(uint* lpdwVersion) FT_GetLibraryVersion; The calling convention is wrongly declared, it should be: alias extern (Windows) FT_STATUS function(uint*

Re: AnalyzeD

2013-06-17 Thread Andrej Mitrovic
On Thursday, 30 May 2013 at 08:26:01 UTC, bioinfornatics wrote: hi Someone know if AnalyzeD could to be used from command line ? i.e http://dconf.org/talks/rohe.html I failed to find AnalyzeD source code thanks I think it's closed-source.

Re: can we detect at compile time module ctor/dtor cycles ?

2013-06-17 Thread Timothee Cour
On Mon, Jun 10, 2013 at 10:20 AM, Steven Schveighoffer schvei...@yahoo.comwrote: On Sun, 09 Jun 2013 23:15:42 -0400, Timothee Cour thelastmamm...@gmail.com wrote: On Fri, Jun 7, 2013 at 11:41 PM, Jonathan M Davis jmdavisp...@gmx.com wrote: On Friday, June 07, 2013 23:23:25 Timothee Cour

Re: can we detect at compile time module ctor/dtor cycles ?

2013-06-17 Thread Timothee Cour
On Mon, Jun 17, 2013 at 5:11 PM, bearophile bearophileh...@lycos.comwrote: Andrej Mitrovic: No idea, but I've wondered this myself too. After all imports are a static feature and all are known at compile-time. rdmd is used often in a situation where it knows all the modules of a

Re: How to expand an expression along with a parameter tuple?

2013-06-17 Thread TommiT
On Monday, 17 June 2013 at 13:59:34 UTC, Artur Skawina wrote: Another solution would be to have the following hidden in some lib: struct _ForEach(alias MAP, TS...) { NTup!(TS.length, typeof(MAP(TS[0].init))) tuple; this(TS values) { foreach (i, ref v; values)

Re: GtkD: Best way to get TreeStore out of TreeView.Model

2013-06-17 Thread Alex Horvat
Just upgraded to dmd 2.063.2 - no difference

Re: How to expand an expression along with a parameter tuple?

2013-06-17 Thread TommiT
On Monday, 17 June 2013 at 13:59:34 UTC, Artur Skawina wrote: [..] Your setup has a pretty serious issue with correctness though. It's because all the types of _ForEach.tuple are the same as the first element of TS... import std.stdio; template NTup(size_t N, T...) { static if (N 1)

Re: How to expand an expression along with a parameter tuple?

2013-06-17 Thread TommiT
On Tuesday, 18 June 2013 at 02:37:46 UTC, TommiT wrote: It's because all the types of _ForEach.tuple are the same as the first element of TS... I mean... the same as the type of MAP(TS[0])

Re: can we detect at compile time module ctor/dtor cycles ?

2013-06-17 Thread Andrej Mitrovic
On 6/18/13, Timothee Cour thelastmamm...@gmail.com wrote: why do the email threads keep splitting up again? I answered through DForum, but the email thread was already split-up (it had 0 replies). See here:

Re: A little of coordination for Rosettacode

2013-06-17 Thread bearophile
Adam D. Ruppe: and win the code golf every time! :P Some Rosettacode D entries are a bit compressed, but that site is not for code golfing. It's just preferred to not write long programs, for several reasonable reasons. code: http://arsdnet.net/dcode/rpc-example.d library:

Re: Linker issue?

2013-06-17 Thread Aleksandar Ruzicic
On Tuesday, 18 June 2013 at 02:02:52 UTC, Josh wrote: I've added in wsock32.lib, the -J, and the 3 versions, and it gives the same output. I should mention that I can compile the examples fine with both vibe and dub by themselves, but apparently not inside Eclipse. Thanks for your help