Re: Call destructor directly.
On Monday, 21 October 2013 at 05:40:13 UTC, Agustin wrote: On Monday, 21 October 2013 at 05:17:01 UTC, Jonathan M Davis wrote: On Monday, October 21, 2013 05:53:46 Agustin wrote: On Monday, 21 October 2013 at 03:50:24 UTC, Agustin wrote: > On Monday, 21 October 2013 at 03:46:33 UTC, Jonathan M Davis > > wrote: >> On Monday, October 21, 2013 05:07:02 Agustin wrote: >>> What about constructor?. My current code is: >>>T allocate(T : Object, A...)(auto ref A arguments) { >>> >>> auto pMemory = rawAllocate(__traits(classInstanceSize, >>> T), >>> >>> T.alignof); // Return void* >>> >>> emplace!T(cast(T *)pMemory, arguments); >>>return cast(T) pMemory; >>> >>>} >>> >>> Doesn't seems to work, and i can't find any good >>> documentation >>> about it. >> >> IIRC, the constructor should be name __ctor. >> >> - Jonathan M Davis > > no property 'opCall' for type 'Main.MyClass' :( Trait allMember return "__ctor", but seems like i cannot call it directly: (cast(T)pMemory).__ctor(arguments); // Being pMemory void* If you want to see how to use emplace, I'd advise looking at std.typecons.RefCounted's implementation: https://github.com/D-Programming-Language/phobos/blob/master/std/typecons.d#L3505 emplace calls the constructor for you, so I don't know why you'd be trying to call it. But you can look at emplace's implementation if you want to see how to call __ctor. For structs: https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L3976 For classes: https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L4716 I don't think that it'll work if the constructor is private though, so maybe that's your problem. - Jonathan M Davis I'm silly the issue was at this line auto pMemory = rawAllocate(__traits(classInstanceSize, T), T.alignof); emplace(pMemory, arguments); Correct was auto pMemory = rawAllocate(__traits(classInstanceSize, T), T.alignof); emplace(&pMemory, arguments); Thanks guys That didn't work, but after reading how emplace works, i had to make some changes. public T allocate(T : Object, A...)(auto ref A arguments) { auto pMemory = rawAllocate(__traits(classInstanceSize, T), T.alignof); assert(pMemory !is null, "Not enought memory on the allocator"); byte[] * pByteMemory = cast(byte[] *) pMemory; *pByteMemory = typeid(T).init[]; auto pObject = cast(T) pMemory; static if (is(typeof(pObject.__ctor(arguments { pObject.__ctor(arguments); } return pObject; } That would work.
Re: D / GtkD for SQL Server
On 2013-10-21 06:53, John Joyus wrote: Thanks. Does it need Java runtime on end user's machine? No, it's a complete D port. No libraries are necessary except for the system libraries (GTK+ on Linux). -- /Jacob Carlborg
Re: Call destructor directly.
On Monday, 21 October 2013 at 05:17:01 UTC, Jonathan M Davis wrote: On Monday, October 21, 2013 05:53:46 Agustin wrote: On Monday, 21 October 2013 at 03:50:24 UTC, Agustin wrote: > On Monday, 21 October 2013 at 03:46:33 UTC, Jonathan M Davis > > wrote: >> On Monday, October 21, 2013 05:07:02 Agustin wrote: >>> What about constructor?. My current code is: >>>T allocate(T : Object, A...)(auto ref A arguments) { >>> >>> auto pMemory = rawAllocate(__traits(classInstanceSize, >>> T), >>> >>> T.alignof); // Return void* >>> >>> emplace!T(cast(T *)pMemory, arguments); >>>return cast(T) pMemory; >>> >>>} >>> >>> Doesn't seems to work, and i can't find any good >>> documentation >>> about it. >> >> IIRC, the constructor should be name __ctor. >> >> - Jonathan M Davis > > no property 'opCall' for type 'Main.MyClass' :( Trait allMember return "__ctor", but seems like i cannot call it directly: (cast(T)pMemory).__ctor(arguments); // Being pMemory void* If you want to see how to use emplace, I'd advise looking at std.typecons.RefCounted's implementation: https://github.com/D-Programming-Language/phobos/blob/master/std/typecons.d#L3505 emplace calls the constructor for you, so I don't know why you'd be trying to call it. But you can look at emplace's implementation if you want to see how to call __ctor. For structs: https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L3976 For classes: https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L4716 I don't think that it'll work if the constructor is private though, so maybe that's your problem. - Jonathan M Davis I'm silly the issue was at this line auto pMemory = rawAllocate(__traits(classInstanceSize, T), T.alignof); emplace(pMemory, arguments); Correct was auto pMemory = rawAllocate(__traits(classInstanceSize, T), T.alignof); emplace(&pMemory, arguments); Thanks guys
Re: Call destructor directly.
On Monday, October 21, 2013 05:53:46 Agustin wrote: > On Monday, 21 October 2013 at 03:50:24 UTC, Agustin wrote: > > On Monday, 21 October 2013 at 03:46:33 UTC, Jonathan M Davis > > > > wrote: > >> On Monday, October 21, 2013 05:07:02 Agustin wrote: > >>> What about constructor?. My current code is: > >>> T allocate(T : Object, A...)(auto ref A arguments) { > >>> > >>> auto pMemory = rawAllocate(__traits(classInstanceSize, T), > >>> > >>> T.alignof); // Return void* > >>> > >>> emplace!T(cast(T *)pMemory, arguments); > >>> return cast(T) pMemory; > >>> > >>> } > >>> > >>> Doesn't seems to work, and i can't find any good documentation > >>> about it. > >> > >> IIRC, the constructor should be name __ctor. > >> > >> - Jonathan M Davis > > > > no property 'opCall' for type 'Main.MyClass' :( > > Trait allMember return "__ctor", but seems like i cannot call it > directly: > > (cast(T)pMemory).__ctor(arguments); // Being pMemory void* If you want to see how to use emplace, I'd advise looking at std.typecons.RefCounted's implementation: https://github.com/D-Programming-Language/phobos/blob/master/std/typecons.d#L3505 emplace calls the constructor for you, so I don't know why you'd be trying to call it. But you can look at emplace's implementation if you want to see how to call __ctor. For structs: https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L3976 For classes: https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L4716 I don't think that it'll work if the constructor is private though, so maybe that's your problem. - Jonathan M Davis
Re: D / GtkD for SQL Server
On 10/20/2013 02:15 PM, Adam D. Ruppe wrote: On Sunday, 20 October 2013 at 17:24:30 UTC, John Joyus wrote: Regarding the GUI part, all I really need is a form and a bunch of buttons. Can I do that through pure Windows API in D to create a small stand-alone executable that does everything by itself? yup. I started a thing to do it, but haven't finished it yet https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff Grab the files simpledisplay.d, color,d and minigui.d. Lots of stuff doesn't work, and the stuff that does work is still subject to change... but if all ou need are the basics, it might be good enough as it is. Then compile: dmd yourapp.d simpledisplay.d color.d minigui.d and it should just work. If you avoid phobos throughout your code, you can get stand-alone executables about 230 KB in size. With phobos, you'll probably add 200-700 KB, depending on how much you use. Add " -L/SUBSYSTEM:WINDOWS:5.0" (no quotes) to the command line if you don't want a console window to pop up. If you use a resource and xml manifest, this supports visual theme styles on XP+ too. (search MSDN if you want to learn more) (btw there's also database.d and mssql.d in there that might interest you. mssql.d uses ODBC, but the truth is I've never actually tested it, so I don't know if it even compiles.) This is cool! I am able to compile your example. It creates a small 225 KB executable! Btw, I had to comment out the lines that contain TextLabel and the .content in the example code as it fails to compile with following errors: - undefiend identifier TextLabel - no property 'content' for type 'arsd.minigui.LineEdit' I have not tried the database.d and mssql.d files yet. Thanks.
Re: D / GtkD for SQL Server
On 10/20/2013 01:56 PM, Jacob Carlborg wrote: You can use DWT: https://github.com/d-widget-toolkit/dwt For examples, just search for SWT. Thanks. Does it need Java runtime on end user's machine?
Re: D on Windows - linker question
On Sunday, 20 October 2013 at 21:47:53 UTC, Erik van Velzen wrote: My goal was to learn D and Direct3D at the same time. I've tried to set up DMD to do this, but I keep running into issues that the available DirectX11 and win32 headers are incomplete, or won't compile (tried both dmd 2.063 and 2.064, they halt on different type errors), or won't link. To be fair, these are only a few errors, but when the linker spews out some obfuscated function name I really don't know what to do. Will I have more luck with GDC? Or should I try to make headers on my own incrementally? (or take the easy route and use C++?) i'm currently trying to get up DirectX(d3d10(x),d3d11(x),xaudio2,x3daudio,d3dmath) up and running in free time, but i constantly encounter serious problems on my way. now i have some weird problems with COM(no COM - no DirectX). so i don't recommend anyone even try it(DirectX) now, unless one is truly skilled with C++ p.s. for working win32 with dmd 2.063.2 go there(don't forget to convert .lib's to OMF, use coffimplib from digitalmars ftp) - https://github.com/AndrejMitrovic/DWinProgramming/tree/master/WindowsAPI
Re: Call destructor directly.
On Monday, 21 October 2013 at 03:46:33 UTC, Jonathan M Davis wrote: On Monday, October 21, 2013 05:07:02 Agustin wrote: What about constructor?. My current code is: T allocate(T : Object, A...)(auto ref A arguments) { auto pMemory = rawAllocate(__traits(classInstanceSize, T), T.alignof); // Return void* emplace!T(cast(T *)pMemory, arguments); return cast(T) pMemory; } Doesn't seems to work, and i can't find any good documentation about it. IIRC, the constructor should be name __ctor. - Jonathan M Davis no property 'opCall' for type 'Main.MyClass' :(
Re: Call destructor directly.
On Monday, 21 October 2013 at 03:50:24 UTC, Agustin wrote: On Monday, 21 October 2013 at 03:46:33 UTC, Jonathan M Davis wrote: On Monday, October 21, 2013 05:07:02 Agustin wrote: What about constructor?. My current code is: T allocate(T : Object, A...)(auto ref A arguments) { auto pMemory = rawAllocate(__traits(classInstanceSize, T), T.alignof); // Return void* emplace!T(cast(T *)pMemory, arguments); return cast(T) pMemory; } Doesn't seems to work, and i can't find any good documentation about it. IIRC, the constructor should be name __ctor. - Jonathan M Davis no property 'opCall' for type 'Main.MyClass' :( Trait allMember return "__ctor", but seems like i cannot call it directly: (cast(T)pMemory).__ctor(arguments); // Being pMemory void*
Re: Call destructor directly.
On Monday, October 21, 2013 05:07:02 Agustin wrote: > What about constructor?. My current code is: > > T allocate(T : Object, A...)(auto ref A arguments) { > auto pMemory = rawAllocate(__traits(classInstanceSize, T), > T.alignof); // Return void* > > emplace!T(cast(T *)pMemory, arguments); > return cast(T) pMemory; > } > > Doesn't seems to work, and i can't find any good documentation > about it. IIRC, the constructor should be name __ctor. - Jonathan M Davis
Re: Call destructor directly.
On Monday, 21 October 2013 at 02:26:03 UTC, Agustin wrote: On Monday, 21 October 2013 at 02:17:54 UTC, Adam D. Ruppe wrote: On Monday, 21 October 2013 at 02:06:02 UTC, Agustin wrote: I'm implementing some custom memory allocator, is possible to call an object destructor directly? destroy(object); destroy is in the automatically imported object.dm so you don't have to import anything, The source code is in dmd2/src/druntime/src/object_.d, there's a few overloads if you are curious how it is implemented. Short answer is there's a pointer to the destructor in the TypeInfo and destroy calls it. Thank you :) What about constructor?. My current code is: T allocate(T : Object, A...)(auto ref A arguments) { auto pMemory = rawAllocate(__traits(classInstanceSize, T), T.alignof); // Return void* emplace!T(cast(T *)pMemory, arguments); return cast(T) pMemory; } Doesn't seems to work, and i can't find any good documentation about it.
Re: Call destructor directly.
On Monday, 21 October 2013 at 02:17:54 UTC, Adam D. Ruppe wrote: On Monday, 21 October 2013 at 02:06:02 UTC, Agustin wrote: I'm implementing some custom memory allocator, is possible to call an object destructor directly? destroy(object); destroy is in the automatically imported object.dm so you don't have to import anything, The source code is in dmd2/src/druntime/src/object_.d, there's a few overloads if you are curious how it is implemented. Short answer is there's a pointer to the destructor in the TypeInfo and destroy calls it. Thank you :)
Re: Call destructor directly.
On Monday, 21 October 2013 at 02:06:02 UTC, Agustin wrote: I'm implementing some custom memory allocator, is possible to call an object destructor directly? destroy(object); destroy is in the automatically imported object.dm so you don't have to import anything, The source code is in dmd2/src/druntime/src/object_.d, there's a few overloads if you are curious how it is implemented. Short answer is there's a pointer to the destructor in the TypeInfo and destroy calls it.
Call destructor directly.
I'm implementing some custom memory allocator, is possible to call an object destructor directly? For example void deallocate(T)(T object) { assert(object !is null); object.~this(); rawDeallocate(cast(void *)object); }
Re: globMatch: distinguish double ** (recursive) vs single *
To clarify, this is in agreement with D docs, but I'm not sure this is what makes most sense. On Sun, Oct 20, 2013 at 6:49 PM, Timothee Cour wrote: > I was hoping std.path.globMatch distinguished single * (non-recursive) vs > double ** (recursive) > so that: > "a1/a2/a3.txt".globMatch("*/a3.txt") returns false > "a1/a2/a3.txt".globMatch("**/a3.txt") returns true > as in good shells (and python 3.4 IRRC) but it's not the case. > > Is that intended? >
globMatch: distinguish double ** (recursive) vs single *
I was hoping std.path.globMatch distinguished single * (non-recursive) vs double ** (recursive) so that: "a1/a2/a3.txt".globMatch("*/a3.txt") returns false "a1/a2/a3.txt".globMatch("**/a3.txt") returns true as in good shells (and python 3.4 IRRC) but it's not the case. Is that intended?
Re: Weird error when compiling.
On Monday, 21 October 2013 at 00:13:59 UTC, bearophile wrote: Agustin: Sorry i clicked the post button :(. The full code is: I don't see your error with the following code, please give the code that gives the error, so we can fix the compiler bug: public class Component { /// Component's unique id. private hash_t id; Assertion failure: 'thisval && thisval->op == TOKclassreference' on line 4067 in file 'interpret.c' when compiling this. /// \brief Default constructor. /// /// \param[in] id The id of the component public this(hash_t id) { this.id = id; this.active = true; this.validated = true; } } public class ComponentDetail(T) : Component { /// Component's ID as static member. public static hash_t ID = typeid(T).toHash; /// \brief Default constructor. public this() { super(ID); } } private class InputComponent : ComponentDetail!InputComponent { } void main() { auto pComponent = new InputComponent(); writeln(pComponent.getId()); writeln(InputComponent.ID); } Bye, bearophile The code is: http://pastebin.com/510YK2Se Using (LDC 0.12.0-beta 1 Ubuntu): http://pastebin.com/2gAWnYyr Using (DMD Windows): Assertion failure: 'thisval && thisval->op == TOKclassreference' on line 4067 in file 'interpret.c' when compiling this.
Re: matrix business in D
On Thursday, 17 October 2013 at 20:31:38 UTC, Yura wrote: Dear D programmers, I am very new to D programming language. I just started to learn it as an alternative to python since the latter sometimes is too slow. My question is whether there some simple ways to solve linear algebra problems in D programming language? E.g. matrix multiplication, diagonalization, SVD decomposition? If there is something, I would definitely stick to D programming language in my projects. PS I am not a proffesinal programmer and I am sorry if this question has already been discussed. Thaks in advance! I have done some linear algebra in D. If you are comfortable calling C functions, you can easily call into existing solutions, because it is trivial to call into C from D. I use Gretl http://gretl.sourceforge.net/ because it offers a convenient interface to commonly used BLAS and LAPACK functionality. GSL is another good choice https://www.gnu.org/software/gsl/. This has worked well for me because I am using D as a drop-in replacement for C. If you do not know C or otherwise want a D solution, there is SciD https://github.com/kyllingstad/scid/wiki. I've never had a reason to use it so I do not know how well it works.
Re: Weird error when compiling.
Agustin: Sorry i clicked the post button :(. The full code is: I don't see your error with the following code, please give the code that gives the error, so we can fix the compiler bug: public class Component { /// Component's unique id. private hash_t id; /// \brief Default constructor. /// /// \param[in] id The id of the component public this(hash_t id) { this.id = id; this.active = true; this.validated = true; } } public class ComponentDetail(T) : Component { /// Component's ID as static member. public static hash_t ID = typeid(T).toHash; /// \brief Default constructor. public this() { super(ID); } } private class InputComponent : ComponentDetail!InputComponent { } void main() { auto pComponent = new InputComponent(); writeln(pComponent.getId()); writeln(InputComponent.ID); } Bye, bearophile
Re: matrix business in D
On Friday, 18 October 2013 at 13:04:51 UTC, bearophile wrote: Julia is a very new language, quite newer than D. I don't think it's a good idea to recommend it for real work. I don't think that the simple rule comparing age of the languages in question for risk assessment is very useful. Given all of the other variables, I'd be more likely to recommend Julia for numerical linear algebra today than D for the same role. That's not a slam on D, which I mostly like better than it's competition (C++, Rust, C, ...) but rather an observation that the Julia community is entirely focused on this domain. A really risk averse programmer who wouldn't consider Julia in this domain wouldn't consider D either -- Brian
Re: Weird error when compiling.
On Sunday, 20 October 2013 at 22:04:49 UTC, Agustin wrote: On Sunday, 20 October 2013 at 21:54:37 UTC, Agustin wrote: On Sunday, 20 October 2013 at 02:14:55 UTC, TheFlyingFiddle wrote: Anyway to evaluate the name of the class and return its hash at compile time? I couldn't find the built in hash unction for strings so i used the one from http://dlang.org/hash-map.html as an example. More advanced and better hash functions can be found online. public class ComponentDetail(T) : Component { /// Component's ID as static member. public static hash_t ID = hash!(T); } hash_t hash(T)() { hash_t hash; foreach (char c; T.stringof) hash = (hash * 9) + c; return hash; } Works perfectly :), now if i want to implement the same but rather do something like template GetHash(string character, hash_t hash = 0, size_t index = 0) { static if (character[index]) enum GetHash = GetHash(character, hash = (hash * 9) + character[index], ++index); else enum GetHash = hash; } How should i implement it? I came up with something like template GetHash(string character, hash_t hash = 0, size_t index = 0) { static if (index < character.length) enum GetHash = GetHash!(character, (hash * 9) + character[index], index + 1); else enum GetHash = hash; } And the final template is template Hash(string text, hash_t hash = 0, size_t index = 0) { static if (index < text.length) enum Hash = Hash!(text, (hash ^ text[index]) * 1099511628211UL, index + 1); else enum Hash = hash; } :D
Re: Weird error when compiling.
On Sunday, 20 October 2013 at 21:54:37 UTC, Agustin wrote: On Sunday, 20 October 2013 at 02:14:55 UTC, TheFlyingFiddle wrote: Anyway to evaluate the name of the class and return its hash at compile time? I couldn't find the built in hash unction for strings so i used the one from http://dlang.org/hash-map.html as an example. More advanced and better hash functions can be found online. public class ComponentDetail(T) : Component { /// Component's ID as static member. public static hash_t ID = hash!(T); } hash_t hash(T)() { hash_t hash; foreach (char c; T.stringof) hash = (hash * 9) + c; return hash; } Works perfectly :), now if i want to implement the same but rather do something like template GetHash(string character, hash_t hash = 0, size_t index = 0) { static if (character[index]) enum GetHash = GetHash(character, hash = (hash * 9) + character[index], ++index); else enum GetHash = hash; } How should i implement it? I came up with something like template GetHash(string character, hash_t hash = 0, size_t index = 0) { static if (index < character.length) enum GetHash = GetHash!(character, (hash * 9) + character[index], index + 1); else enum GetHash = hash; }
Re: Weird error when compiling.
On Sunday, 20 October 2013 at 02:14:55 UTC, TheFlyingFiddle wrote: Anyway to evaluate the name of the class and return its hash at compile time? I couldn't find the built in hash unction for strings so i used the one from http://dlang.org/hash-map.html as an example. More advanced and better hash functions can be found online. public class ComponentDetail(T) : Component { /// Component's ID as static member. public static hash_t ID = hash!(T); } hash_t hash(T)() { hash_t hash; foreach (char c; T.stringof) hash = (hash * 9) + c; return hash; } Works perfectly :), now if i want to implement the same but rather do something like template GetHash(string character, hash_t hash = 0, size_t index = 0) { static if (character[index]) enum GetHash = GetHash(character, hash = (hash * 9) + character[index], ++index); else enum GetHash = hash; } How should i implement it?
Re: D on Windows - linker question
My goal was to learn D and Direct3D at the same time. I've tried to set up DMD to do this, but I keep running into issues that the available DirectX11 and win32 headers are incomplete, or won't compile (tried both dmd 2.063 and 2.064, they halt on different type errors), or won't link. To be fair, these are only a few errors, but when the linker spews out some obfuscated function name I really don't know what to do. Will I have more luck with GDC? Or should I try to make headers on my own incrementally? (or take the easy route and use C++?)
Re: D / GtkD for SQL Server
On Sunday, 20 October 2013 at 17:24:30 UTC, John Joyus wrote: Regarding the GUI part, all I really need is a form and a bunch of buttons. Can I do that through pure Windows API in D to create a small stand-alone executable that does everything by itself? yup. I started a thing to do it, but haven't finished it yet https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff Grab the files simpledisplay.d, color,d and minigui.d. Lots of stuff doesn't work, and the stuff that does work is still subject to change... but if all ou need are the basics, it might be good enough as it is. Then compile: dmd yourapp.d simpledisplay.d color.d minigui.d and it should just work. If you avoid phobos throughout your code, you can get stand-alone executables about 230 KB in size. With phobos, you'll probably add 200-700 KB, depending on how much you use. Add " -L/SUBSYSTEM:WINDOWS:5.0" (no quotes) to the command line if you don't want a console window to pop up. If you use a resource and xml manifest, this supports visual theme styles on XP+ too. (search MSDN if you want to learn more) (btw there's also database.d and mssql.d in there that might interest you. mssql.d uses ODBC, but the truth is I've never actually tested it, so I don't know if it even compiles.) minigui.d uses native Windows functions for the most part, if you look at the source, you can see where there's HWNDs and so on (and simpledisplay.d creates the windows and manages the event loop, you can find a WndProc in there), but does its own layout based on min/max size, stretchiness, and a handful of other virtual functions. This is kinda a pain to customize at this point, but it works pretty ok if the default is good for you (fill all available space vertically). The event model is based on javascript, you use widget.addEventListener(type, handler). Here's an example program: import arsd.minigui; void main() { auto window = new MainWindow(); // the constructor often takes a label and a parent auto checkbox = new Checkbox("Useful?", window); // use HorizontalLayouts to put things side-by-side auto field = new HorizontalLayout(window); auto lbl = new TextLabel("Name:", field); auto edit = new LineEdit(field); auto buttonSet = new HorizontalLayout(window); auto cancelButton = new Button("Cancel", buttonSet); auto okButton = new Button("OK", buttonSet); // the triggered event is like click, but also works with keyboard activation // other possible events are click, mouseover, mouseenter, and a few others from javascript, search the minigui.d source for EventType for a list so far cancelButton.addEventListener(EventType.triggered, { window.close(); }); okButton.addEventListener(EventType.triggered, { // checking the checkbox state... if(checkbox.isChecked) // message boxes are done right now with custom windows and are modeless. you actually prolly shouldn't use them, perhaps use the raw Windows function instead auto mb = new MessageBox("You said your name is : " ~ edit.content); // the box's content property gets its text. only ASCII right now, i gotta fix this to use GetWindowTextW instead of A... else auto mb = new MessageBox("You said this is useless, " ~ edit.content); window.close(); }); // run the event loop. it terminates when the last window is closed by your program or by the user. window.loop(); } If it works for you, cool, let me know if there's anything I can do to make it better for you and I'll try to make it happen. There's also DWT you might want to look at, like Jacob said. It is a pretty complete port of the Java SWT toolkit so will probably offer more functionality than my incomplete, minimal file here.
Re: D / GtkD for SQL Server
On 2013-10-20 19:24, John Joyus wrote: Thank you all for the responses. Regarding the GUI part, all I really need is a form and a bunch of buttons. Can I do that through pure Windows API in D to create a small stand-alone executable that does everything by itself? If that is possible, any links to an example D code? You can use DWT: https://github.com/d-widget-toolkit/dwt For examples, just search for SWT. -- /Jacob Carlborg
Re: Error: no property 'sort' for type 'ulong[string]' , sometimes
On Sunday, 20 October 2013 at 16:06:54 UTC, bearophile wrote: Also, what do you mean sorting an associative array? Yep, that's the point. I fumbled further and came to the realization that maybe there is no such thing as a sorted associative array. That would have be something that, when you foreach on it, the keys (which in fact hold the valuable material) come in order, such as in assarr("alice")=12 assarr("bob")=0 assarr("charlie")=7 but I guess that's not really the point with associative arrays and that their in-memory location is somewhat random, maybe for a reason. the Phobos sort function of std.algorithm I still hope I'll survive 'till I get there ;-) thanks a lot
Re: D / GtkD for SQL Server
On 10/20/2013 09:39 AM, Mike Wey wrote: On 10/20/2013 10:13 AM, John Joyus wrote: 2). If I build with GtkD, it generates about 3.5 MB executable. Does this contain everything or do I still have to distribute anything with it to make it work on new Windows machines? Thanks in advance. You'll need to have the Gtk+ runtime installed on the machine. Thank you all for the responses. Regarding the GUI part, all I really need is a form and a bunch of buttons. Can I do that through pure Windows API in D to create a small stand-alone executable that does everything by itself? If that is possible, any links to an example D code? Thanks.
Re: Dynamic associative array, to hold many values per key
On Sunday, 20 October 2013 at 15:13:47 UTC, Logesh Pillay wrote: Thanks. Coming to D from python, I have to say D's tuples look difficult. I'm going to see how far I can get with structs writing my sudoku solver. They must be much more complicated because of clear distinction between compile-time entities and run-time ones in native compiled language, something that Python does not need to care about. That said, there unfortunately are also some design quirks too, mostly historical mistakes.
Re: Error: no property 'sort' for type 'ulong[string]' , sometimes
Derix: What did I miss ? Never use the built-in ".sort" property, it's deprecated, buggy and slow. It's still in the language for unknown reasons, perhaps to create nice traps for language newcomers. Also, what do you mean sorting an associative array? To sort the keys (notice the name with two leading "a" and the trailing () to call the Phobos sort function of std.algorithm that you have to import): auto sortedKeys = aarr.byKey.array.sort().release; auto sortedValues = aarr.byValua.array.sort().release; Bye, bearophile
Re: Dynamic associative array, to hold many values per key
Logesh Pillay: Thanks. Coming to D from python, I have to say D's tuples look difficult. I'm going to see how far I can get with structs writing my sudoku solver. I think defining the full correct hashing protocol manually for structs is harder than using tuples. There were many discussions to improve and simplify D tuples, but nothing has come out of them yet. Bye, bearophile
Re: Injecting code into methods based on UDA's
On Sunday, 20 October 2013 at 11:58:41 UTC, TheFlyingFiddle wrote: It's only possible to inject code using a template or string mixin. Ah, too bad. Thanks for the answer. Well, it is possible to do it if you use some kind of own framework for declarative stuff and call the function only from it (thus implementing check of attached UDA's inside of the framework). Actual function modification is not possible.
Re: Dynamic associative array, to hold many values per key
On Sunday, 20 October 2013 at 14:05:53 UTC, bearophile wrote: Andrej Mitrovic: struct kie { short a; short b; } short[kie] possibles; ... Try: short[][kie]; In D structs/classes usually start with an upper case letter: struct Kie { short a, b; } But if you want to use Kie as key in an associative array you have to add it the full hashing protocol of three functions: equality, hash function and comparison. A simpler solution is to use a Tuple, that already defines those three methods: alias Kie = Tuple!(short,"a", short,"b"); Bye, bearophile Thanks. Coming to D from python, I have to say D's tuples look difficult. I'm going to see how far I can get with structs writing my sudoku solver.
Error: no property 'sort' for type 'ulong[string]' , sometimes
Hi there, So I've just stated learning D. Playing with associative arrays, I wrote this simple function. No big deal. void associativeArrayFu(){ ulong[string] arr; arr["foo"]=1; arr["bar"]=2; arr["foo"]=45; foreach( thing;arr.sort){ writeln( thing ); } } Compiles and runs just fine. Stating to have a bunch of funtions in one file, I reorganised my sources among several files (in the same project in Eclipse). Now the same function yelds this error when compiling: Error: no property 'sort' for type 'ulong[string]' wether it is in a source file alongside other functions, alone in its own file, or even all alone in its own project. Not that I care that much about this poor function, but I am puzzled. What did I miss ?
Re: D / GtkD for SQL Server
On Sunday, 20 October 2013 at 08:13:35 UTC, John Joyus wrote: I am learning D and itching to create some small tools (basically Windows executables) for our internal use, but any tool I think of creating also needs some support for SQL Server! So my question is: 1). Does D has any support for MSSQL? Look at the OpenDBX bindings: https://github.com/rikkimax/Derelict3-Extras/tree/master/import/derelict/opendbx It supports a lot of databases, including SQL Server. Disclaimer: I didn't use it.
Re: Dynamic associative array, to hold many values per key
On Sunday, 20 October 2013 at 13:57:27 UTC, Andrej Mitrovic wrote: On Sunday, 20 October 2013 at 13:54:48 UTC, Logesh Pillay wrote: I want an associative array in d programming language. The key is a struct with two shorts. Easy so far. struct kie { short a; short b; } short[kie] possibles; Problem is I want to hold more than value per key. Dynamic would be useful so it can grow and shrink per key When I try to allocate a dynamic array as value to a to key i.e short[] temp; ... possibles[k] = temp; I get the understandable error. Error: cannot append type short[] to type short How do I declare an associative array where the values can be a dynamic array of numbers? Try: short[][kie]; Thanks, that worked.
Re: Dynamic associative array, to hold many values per key
Andrej Mitrovic: struct kie { short a; short b; } short[kie] possibles; ... Try: short[][kie]; In D structs/classes usually start with an upper case letter: struct Kie { short a, b; } But if you want to use Kie as key in an associative array you have to add it the full hashing protocol of three functions: equality, hash function and comparison. A simpler solution is to use a Tuple, that already defines those three methods: alias Kie = Tuple!(short,"a", short,"b"); Bye, bearophile
Re: Dynamic associative array, to hold many values per key
On Sunday, 20 October 2013 at 13:54:48 UTC, Logesh Pillay wrote: I want an associative array in d programming language. The key is a struct with two shorts. Easy so far. struct kie { short a; short b; } short[kie] possibles; Problem is I want to hold more than value per key. Dynamic would be useful so it can grow and shrink per key When I try to allocate a dynamic array as value to a to key i.e short[] temp; ... possibles[k] = temp; I get the understandable error. Error: cannot append type short[] to type short How do I declare an associative array where the values can be a dynamic array of numbers? Try: short[][kie];
Dynamic associative array, to hold many values per key
I want an associative array in d programming language. The key is a struct with two shorts. Easy so far. struct kie { short a; short b; } short[kie] possibles; Problem is I want to hold more than value per key. Dynamic would be useful so it can grow and shrink per key When I try to allocate a dynamic array as value to a to key i.e short[] temp; ... possibles[k] = temp; I get the understandable error. Error: cannot append type short[] to type short How do I declare an associative array where the values can be a dynamic array of numbers?
Re: D / GtkD for SQL Server
On 10/20/2013 10:13 AM, John Joyus wrote: 2). If I build with GtkD, it generates about 3.5 MB executable. Does this contain everything or do I still have to distribute anything with it to make it work on new Windows machines? Thanks in advance. You'll need to have the Gtk+ runtime installed on the machine. -- Mike Wey
Re: Injecting code into methods based on UDA's
It's only possible to inject code using a template or string mixin. Ah, too bad. Thanks for the answer.
Re: D / GtkD for SQL Server
On 2013-10-20 11:37, Jacob Carlborg wrote: You just need to fill in the constants at the top. Please let me know if you get the D version working. You need to change the actual SQL select statement as well. -- /Jacob Carlborg
Re: D / GtkD for SQL Server
On 2013-10-20 10:13, John Joyus wrote: I am learning D and itching to create some small tools (basically Windows executables) for our internal use, but any tool I think of creating also needs some support for SQL Server! So my question is: 1). Does D has any support for MSSQL? I need the ability to connect to a SQL Server and run a SQL script (the script I construct based on user inputs) and capture its return value, just a number. (No need to insert or update any records). I would say your best bet is to create bindings to FreeTDS. It's an open source library that can connect to SQL Server. I actually tried to do that once, but I never managed to connect to the server/database, for some reason. I C version worked fine but not when I ported it do D. This is the D version: http://pastebin.com/7tGyytDh This is the tds file: http://pastebin.com/JCA8XQH0 This is the C version: http://pastebin.com/FWJM4B6X You just need to fill in the constants at the top. Please let me know if you get the D version working. -- /Jacob Carlborg
Re: Injecting code into methods based on UDA's
On 2013-10-20 01:16, TheFlyingFiddle wrote: Is it possible to inject code into a method with UDA's? For example if i wanted a method to do some logging when it's called. It's only possible to inject code using a template or string mixin. -- /Jacob Carlborg
D / GtkD for SQL Server
I am learning D and itching to create some small tools (basically Windows executables) for our internal use, but any tool I think of creating also needs some support for SQL Server! So my question is: 1). Does D has any support for MSSQL? I need the ability to connect to a SQL Server and run a SQL script (the script I construct based on user inputs) and capture its return value, just a number. (No need to insert or update any records). Oh, btw, another question, unrelated to the above: 2). If I build with GtkD, it generates about 3.5 MB executable. Does this contain everything or do I still have to distribute anything with it to make it work on new Windows machines? Thanks in advance.