Re: delegate, template and alias

2011-12-19 Thread Philippe Sigaud
On Tue, Dec 20, 2011 at 00:23, Timon Gehr wrote: > Looks very good. > > Knowing it is a work in progress, I will already give some feedback: (snip) Wow, thanks for the thorough reading! I'll correct thos points. I need to write a code extractor to automatically compile the examples, because I'm

Re: Void initialization

2011-12-19 Thread Jacob Carlborg
On 2011-12-20 01:34, Jesse Phillips wrote: On Mon, 19 Dec 2011 18:52:44 +0100 Jacob Carlborg wrote: You can always make the variable uninitialized using "void", don't know if that what is what you're looking for. float[] f = void; He is trying to create an array where the elements are not

Re: newbie question: Can D do this?

2011-12-19 Thread Jakob Ovrum
On Monday, 19 December 2011 at 19:01:10 UTC, Simen Kjærås wrote: import std.typetuple : TypeTuple; import std.typecons : tuple; TypeTuple!(a, b) = tuple(b,a); There is a pull request implementing multiple variable declarations: https://github.com/D-Programming-Language/dmd/pull/341 However,

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

2011-12-19 Thread Andrej Mitrovic
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

Re: Void initialization

2011-12-19 Thread Jesse Phillips
On Mon, 19 Dec 2011 18:52:44 +0100 Jacob Carlborg wrote: > You can always make the variable uninitialized using "void", don't > know if that what is what you're looking for. > > float[] f = void; > He is trying to create an array where the elements are not initialized.

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

2011-12-19 Thread Martin Drašar
Dne 20.12.2011 0:02, Trass3r napsal(a): Am 19.12.2011, 23:13 Uhr, schrieb Martin Drašar : Dne 19.12.2011 23:09, Trass3r napsal(a): It actualy returns a procedure address and the procedure is called. It lands inside export extern (C) int magicNumber() and crashes when attempting to allocate mem

Re: delegate, template and alias

2011-12-19 Thread Timon Gehr
On 12/19/2011 09:30 PM, Philippe Sigaud wrote: On Mon, Dec 19, 2011 at 18:49, Timon Gehr wrote: On 12/19/2011 06:46 PM, Philippe Sigaud wrote: On Mon, Dec 19, 2011 at 15:35, Heromythwrote: Woo, I got it. What's the difference with your first post? He uses an eponymous template now

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

2011-12-19 Thread Trass3r
Am 19.12.2011, 23:13 Uhr, schrieb Martin Drašar : Dne 19.12.2011 23:09, Trass3r napsal(a): It actualy returns a procedure address and the procedure is called. It lands inside export extern (C) int magicNumber() and crashes when attempting to allocate memory for Something. Did you properly ini

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

2011-12-19 Thread Martin Drašar
Dne 19.12.2011 23:09, Trass3r napsal(a): It actualy returns a procedure address and the procedure is called. It lands inside export extern (C) int magicNumber() and crashes when attempting to allocate memory for Something. Did you properly initialize druntime? As I am just starting with D, th

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

2011-12-19 Thread Trass3r
It actualy returns a procedure address and the procedure is called. It lands inside export extern (C) int magicNumber() and crashes when attempting to allocate memory for Something. Did you properly initialize druntime?

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

2011-12-19 Thread Martin Drašar
Dne 19.12.2011 19:39, Simon napsal(a): On 19/12/2011 18:01, Andrej Mitrovic wrote: Check if GetProcAddress returns null? It seems to me you're looking for _magicFunction but defining magicNumber, two different names. that's be it. can't remember the rules for whether it will have a leading und

Re: delegate, template and alias

2011-12-19 Thread Philippe Sigaud
On Mon, Dec 19, 2011 at 18:49, Timon Gehr wrote: > On 12/19/2011 06:46 PM, Philippe Sigaud wrote: >> >> On Mon, Dec 19, 2011 at 15:35, Heromyth  wrote: >>> >>> Woo, I got it. >> >> >> What's the difference with your first post? > > > He uses an eponymous template now. Ah yes, thanks. Strange, I'm

Re: newbie question: Can D do this?

2011-12-19 Thread Jonathan M Davis
On Monday, December 19, 2011 11:07:49 Ali Çehreli wrote: > That's a great article.[1] I hope that this chapter is more > beginner-friendly: > > http://ddili.org/ders/d.en/ranges.html Cool. One of the things that we're missing on the website is a solid article on ranges (I started such an article

Re: newbie question: Can D do this?

2011-12-19 Thread Ali Çehreli
On 12/19/2011 10:39 AM, Jonathan M Davis wrote: > it's a range (see > http://www.informit.com/articles/printerfriendly.aspx?p=1407357 for a general > explanation of the concept of ranges) That's a great article.[1] I hope that this chapter is more beginner-friendly: http://ddili.org/ders/d

Re: newbie question: Can D do this?

2011-12-19 Thread Simen Kjærås
On Mon, 19 Dec 2011 17:17:43 +0100, clk wrote: Hello, I'm new to this mailing list. I'm trying to learn D to eventually use it in production code. I'm a little bit intimidated by the fact that the topics in the d-learn list look rather advanced to a newbie like me. I have 3 fairly simple ques

Re: newbie question: Can D do this?

2011-12-19 Thread Kai Meyer
On 12/19/2011 09:17 AM, clk wrote: Hello, I'm new to this mailing list. I'm trying to learn D to eventually use it in production code. I'm a little bit intimidated by the fact that the topics in the d-learn list look rather advanced to a newbie like me. I have 3 fairly simple questions: 1) Does

Re: newbie question: Can D do this?

2011-12-19 Thread Ali Çehreli
On 12/19/2011 08:17 AM, clk wrote: > I'm a little bit intimidated by the fact that the topics in the d-learn > list look rather advanced to a newbie like me. We need more newbie topics here! :) > 1) Does D support something like the javascript 1.8 destructuring > assigment (multiple assigment i

Re: newbie question: Can D do this?

2011-12-19 Thread Jonathan M Davis
On Monday, December 19, 2011 11:17:43 clk wrote: > Hello, > I'm new to this mailing list. I'm trying to learn D to eventually use > it in production code. > I'm a little bit intimidated by the fact that the topics in the d-learn > list look rather advanced to a newbie like me. > I have 3 fairly sim

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

2011-12-19 Thread Simon
On 19/12/2011 18:01, Andrej Mitrovic wrote: Check if GetProcAddress returns null? It seems to me you're looking for _magicFunction but defining magicNumber, two different names. that's be it. can't remember the rules for whether it will have a leading underscore, but you can always use depende

Re: newbie question: Can D do this?

2011-12-19 Thread simendsjo
On 19.12.2011 17:17, clk wrote: 1) Does D support something like the javascript 1.8 destructuring assigment (multiple assigment in python): [a, b] = [b, a]; I don't think so, but you can do something like this with templates: void swap(alias a, alias b)() { auto t = a; a = b; b = t

Re: Void initialization

2011-12-19 Thread Steven Schveighoffer
On Mon, 19 Dec 2011 12:24:18 -0500, Bear 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 aware of? I think it should be GC.malloc, not gc.malloc, so maybe I'm miss

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

2011-12-19 Thread Andrej Mitrovic
Check if GetProcAddress returns null? It seems to me you're looking for _magicFunction but defining magicNumber, two different names.

Re: Void initialization

2011-12-19 Thread Jacob Carlborg
On 2011-12-19 18:24, Bear wrote: gc.malloc actually returns void[] Bearophile's suggestion seems to work though, but it doesn't seem to improve performance for some reason... I guess I'll have to find some other way to make my prog quicker. You can always make the variable uninitialized using

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

2011-12-19 Thread Martin Drasar
Hello everyone, I would like to ask you about linking D shared objects (.dll and .so) from a C++ program. Say I have this C++ loader: typedef int (*MagicFunction) (); HMODULE handle = LoadLibraryA("DLibrary.dll"); if (handle) { MagicFunction fn = (MagicFunction) GetProcAddress(handle, "_m

newbie question: Can D do this?

2011-12-19 Thread clk
Hello, I'm new to this mailing list. I'm trying to learn D to eventually use it in production code. I'm a little bit intimidated by the fact that the topics in the d-learn list look rather advanced to a newbie like me. I have 3 fairly simple questions: 1) Does D support something like the ja

Re: delegate, template and alias

2011-12-19 Thread Timon Gehr
On 12/19/2011 06:46 PM, Philippe Sigaud wrote: On Mon, Dec 19, 2011 at 15:35, Heromyth wrote: Woo, I got it. What's the difference with your first post? He uses an eponymous template now.

Re: delegate, template and alias

2011-12-19 Thread Philippe Sigaud
On Mon, Dec 19, 2011 at 15:35, Heromyth wrote: > Woo, I got it. What's the difference with your first post?

Re: Void initialization

2011-12-19 Thread Bear
gc.malloc actually returns void[] Bearophile's suggestion seems to work though, but it doesn't seem to improve performance for some reason... I guess I'll have to find some other way to make my prog quicker.

Re: Void initialization

2011-12-19 Thread Steven Schveighoffer
On Mon, 19 Dec 2011 07:04:20 -0500, 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); this is wrong. a float[] s

Re: Array expanding

2011-12-19 Thread Steven Schveighoffer
On Sun, 18 Dec 2011 18:42:31 -0500, Jonathan M Davis wrote: On Sunday, December 18, 2011 22:12:07 RenatoL wrote: Reading the book from Alexandrescu we can find this (page 103-104, at least in my edition): Expanding arrays has a couple of subtleties that concern possible reallocation of the

Re: delegate, template and alias

2011-12-19 Thread Heromyth
== Quote from Heromyth (bitwo...@qq.com)'s article > == Quote from Philippe Sigaud (philippe.sig...@gmail.com)'s article > > I suppose you do *not*want the commented line? > I want to convert a delegate type define in C# to D's, as such: > public delegate void AsynchronousAction(T argument, Asy

Re: delegate, template and alias

2011-12-19 Thread Heromyth
== Quote from Philippe Sigaud (philippe.sig...@gmail.com)'s article > On Sun, Dec 18, 2011 at 14:13, Heromyth wrote: > > I have a delegate as a parameter in a function which is a template function. > > And I want to use alias for the delegate parameter. > > Is there a better way for this? > I supp

Re: Void initialization

2011-12-19 Thread Trass3r
Am 19.12.2011, 13:04 Uhr, schrieb Bear : Using D1, I have a program that creates tons of float[] ; for performance reasons, I would like them to be uninitialized. std.array.uninitializedArray

Re: Void initialization

2011-12-19 Thread bearophile
Bear: > 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); Try something like this (untested): alias float TF; TF[] f

Void initialization

2011-12-19 Thread Bear
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 violation" and sometimes "Array bound