How to mixin each element of tuple

2011-12-20 Thread Michal Minich
My naive approach doesn't works struct Item1 (T) {} struct Item2 (T) {} struct Group (Items ...) { // how to do this? ... no static foreach :( static foreach (I; Items) mixin I!(int); } void main () { alias Group!(Item1, Item2) G; }

Re: newbie question: Can D do this?

2011-12-20 Thread clk
Thank you for your quick replies. I'm impressed by the helpfulness and dedication of the D community! Here's another one. Is there a way to pass arguments to functions by keyword as in the calls to f and g below? void f(int a = 0, int b = 1) {} void g(int a) {} void main() { f(b = 1, a =

Re: Void initialization

2011-12-20 Thread Stewart Gordon
On 19/12/2011 18:11, Steven Schveighoffer wrote: On Mon, 19 Dec 2011 12:24:18 -0500, Bear joanylepri...@yahoo.fr wrote: gc.malloc actually returns void[] http://www.d-programming-language.org/phobos/core_memory.html#malloc Looks like void* to me... Or is there another function I'm not

Re: Void initialization

2011-12-20 Thread Stewart Gordon
On 19/12/2011 12:12, bearophile wrote: Bear: snip float[] f = cast(float[])std.gc.malloc(x*4); Try something like this (untested): alias float TF; TF[] f = (cast(TF*)std.gc.malloc(x * TF.sizeof))[0 .. x]; snip I fail to see any real difference from the OP's code: - Why the alias? -

Re: How to mixin each element of tuple

2011-12-20 Thread Timon Gehr
On 12/20/2011 02:32 PM, Michal Minich wrote: My naive approach doesn't works struct Item1 (T) {} struct Item2 (T) {} struct Group (Items ...) { // how to do this? ... no static foreach :( static foreach (I; Items) mixin I!(int); } void main () { alias Group!(Item1,

Re: newbie question: Can D do this?

2011-12-20 Thread Timon Gehr
On 12/20/2011 03:18 PM, clk wrote: Thank you for your quick replies. I'm impressed by the helpfulness and dedication of the D community! Here's another one. Is there a way to pass arguments to functions by keyword as in the calls to f and g below? void f(int a = 0, int b = 1) {} void g(int a)

Re: Void initialization

2011-12-20 Thread Steven Schveighoffer
On Tue, 20 Dec 2011 09:22:46 -0500, Stewart Gordon smjg_1...@yahoo.com wrote: On 19/12/2011 18:11, Steven Schveighoffer wrote: On Mon, 19 Dec 2011 12:24:18 -0500, Bear joanylepri...@yahoo.fr wrote: gc.malloc actually returns void[]

Re: newbie question: Can D do this?

2011-12-20 Thread Steven Schveighoffer
On Tue, 20 Dec 2011 09:18:16 -0500, clk c...@clksoft.com wrote: Thank you for your quick replies. I'm impressed by the helpfulness and dedication of the D community! Here's another one. Is there a way to pass arguments to functions by keyword as in the calls to f and g below? void f(int a =

Re: Void initialization

2011-12-20 Thread Timon Gehr
On 12/19/2011 01:04 PM, Bear wrote: Using D1, I have a program that creates tons of float[] ; for performance reasons, I would like them to be uninitialized. I've tried replacing float[] f = new float[x]; by float[] f = cast(float[])std.gc.malloc(x*4); Unfortunately I keep running into Access

Re: Allocating memory in D shared library when accessed from C++

2011-12-20 Thread Martin Drasar
Dne 20.12.2011 2:22, Andrej Mitrovic napsal(a): test.cpp: http://www.ideone.com/uh7vN DLibrary.d: http://www.ideone.com/fOLN8 $ g++ test.cpp $ dmd -ofDLibrary.dll DLibrary.d $ a.exe $ 9 Hi, Andrej, you are right, this works. Problem is going to be either in VisualD or cv2pdb. For those

Re: Void initialization

2011-12-20 Thread bearophile
Stewart Gordon: On 19/12/2011 12:12, bearophile wrote: Try something like this (untested): alias float TF; TF[] f = (cast(TF*)std.gc.malloc(x * TF.sizeof))[0 .. x]; snip I fail to see any real difference from the OP's code: - Why the alias? Because in that code I have used three

Re: How to mixin each element of tuple

2011-12-20 Thread bearophile
Michal Minich: struct Group (Items ...) { // how to do this? ... no static foreach :( static foreach (I; Items) In D if you use foreach on a typeTuple you get a static foreach. Bye, bearophile

Re: Void initialization

2011-12-20 Thread Timon Gehr
On 12/20/2011 07:12 PM, bearophile wrote: Stewart Gordon: On 19/12/2011 12:12, bearophile wrote: Try something like this (untested): alias float TF; TF[] f = (cast(TF*)std.gc.malloc(x * TF.sizeof))[0 .. x]; snip I fail to see any real difference from the OP's code: - Why the alias?

Re: How to mixin each element of tuple

2011-12-20 Thread Timon Gehr
On 12/20/2011 07:13 PM, bearophile wrote: Michal Minich: struct Group (Items ...) { // how to do this? ... no static foreach :( static foreach (I; Items) In D if you use foreach on a typeTuple you get a static foreach. Bye, bearophile Yes, but foreach cannot be used in

Re: Allocating memory in D shared library when accessed from C++

2011-12-20 Thread Andrej Mitrovic
I'd say make a small test-case and file it to visuald's bugtracker.

Re: How to mixin each element of tuple

2011-12-20 Thread bearophile
Timon Gehr: I think having static foreach would greatly benefit the language. Vote here! :-) http://d.puremagic.com/issues/show_bug.cgi?id=4085 Bye, bearophile

Re: newbie question: Can D do this?

2011-12-20 Thread Philippe Sigaud
On 20/12/2011 14:18, clk wrote: Here's another one. Is there a way to pass arguments to functions by keyword as in the calls to f and g below? I remember a discussion about year ago or so. It seems doable to have some kind of function transformer (adaptor?) for this. from: int foo(int a =

Re: newbie question: Can D do this?

2011-12-20 Thread Philippe Sigaud
On Mon, Dec 19, 2011 at 17:17, clk c...@clksoft.com wrote: 2) D doesn't  seem to support the list comprehension syntax available in python and javascript.  Is this correct? [f(x) for x in list if condition] Correct. As other have said, it's doable by combining std functions. As fas as I

Re: Void initialization

2011-12-20 Thread Stewart Gordon
On 20/12/2011 18:12, bearophile wrote: snip Because in that code I have used three times a type (TF), auto allows to remove only one of them. The alias is not the best solution (a better solution is to put that code into a templated function), but repeating the same generic type more than one

Re: Void initialization

2011-12-20 Thread bearophile
Stewart Gordon: I don't quite understand - why not just use float as it is? OK, so abbreviating it to TF saves 9 characters on that line, but the alias declaration and its trailing line break take up 16 characters, so you're not saving space at all. It's not a way to save chars, it's a

Re: newbie question: Can D do this?

2011-12-20 Thread Stewart Gordon
On 20/12/2011 20:36, Philippe Sigaud wrote: snip That is, it expects some values, then string/values couples as associative arrays. snip I've a recollection of seeing something like this in the PHP library, but I forget where. I believe it's used in some functions that have a lot of options

Re: Void initialization

2011-12-20 Thread Stewart Gordon
On 20/12/2011 22:19, bearophile wrote: snip That's also why I have said a better solution is to wrap that code into a function template, so there is no need for an alias. snip So what you actually meant was to make TF a template parameter? That would make more sense. I can understand an