Re: How do I choose the correct primative?

2014-01-05 Thread TheFlyingFiddle
On Sunday, 5 January 2014 at 06:31:38 UTC, Jake Thomas wrote: And got 86,421 lines of assembly!! I expected a load instruction to load whatever was at loadMe's location into r0 (the return register) and not much else. Maybe 10 lines - tops - due to compiler fluffiness. I got about 8,641 times t

Re: Prevent Garbage Collector

2014-01-05 Thread Jacob Carlborg
On 2014-01-05 01:17, Jeroen Bollen wrote: Also a somewhat unrelated question, variables in D get initialized by default, do they also when you define them right after? Something like: int[] iryy = new int[](50); // Will the array elements be initialized to 0? Yes, have a look at: http://dlang

Re: Is it possible to handle 'magic' property assignments a'la PHP?

2014-01-05 Thread Philippe Sigaud
On Sat, Jan 4, 2014 at 10:08 PM, H. S. Teoh wrote: > Of course, these are arguably clever hacks than true, properly-motivated > examples, but still, they exemplify what Andrei meant when he said that > the power of opDispatch is largely still unexplored territory. As Adam showed, it's very nice

Re: Simplest way to create an array from an associative array which its contains keys and values?

2014-01-05 Thread bearophile
Andrej Mitrovic: However the [k, aa[k]] expression will allocate an array for each key you iterate over regardless if you use join or joiner. I posted a solution with "only", hope that works. :) Perhaps the "s" suffix (to define fixed-sized arrays) could avoid that problem: string[] r = aa

Re: Is it possible to handle 'magic' property assignments a'la PHP?

2014-01-05 Thread TheFlyingFiddle
Another simple example that have helped me tremendously when debugging OpenGL calls. A simple dispatcher that checks glGetError after every call. struct GL { auto opDispatch(string name, Args...)(Args args) { enum glName = "gl" ~ name; mixin(format(" static if(is

Re: Simplest way to create an array from an associative array which its contains keys and values?

2014-01-05 Thread Philippe Sigaud
On Sat, Jan 4, 2014 at 1:08 AM, Ali Çehreli wrote: > 3) The member rangeFront is needed because Tuple does not have opIndex for > dynamic indexes. I can do range.front[0] but I cannot do > range.front[currentIndex]. Is there any plan to add indexing on runtime indices to Tuple? It can be done, b

Re: Simplest way to create an array from an associative array which its contains keys and values?

2014-01-05 Thread Andrej Mitrovic
On 1/5/14, bearophile wrote: > Perhaps the "s" suffix (to define fixed-sized arrays) could avoid > that problem: > > string[] r = aa.byKey.map!(k => [k, aa[k]]s).join; I would prefer a prefix though, to make it immediately obvious you're creating a static array. string[] r = aa.byKey.map!(k => s

Re: Simplest way to create an array from an associative array which its contains keys and values?

2014-01-05 Thread Timon Gehr
On 01/05/2014 03:55 PM, Philippe Sigaud wrote: Is there any plan to add indexing on runtime indices to Tuple? It can be done, by generating a specific runtime opIndex for Tuple, if the types held in the tuple have a common type. It would override the current index operator.

Re: Is it possible to handle 'magic' property assignments a'la PHP?

2014-01-05 Thread Jacob Carlborg
On 2014-01-05 14:09, Philippe Sigaud wrote: As Adam showed, it's very nice to make some clean API (or DSL). Another example I like is generating queries: auto result = table.findByFirstName; If Table has a "FirstName" field, then opDispatch will catch any findByX and generate the related

Re: VC linker - unresolved external symbols - runtime

2014-01-05 Thread Palmic
Same problem here. Configuration: Windows 8.1, with 8.1 SDK, and visual studio 2013. I tried to link manually phobos64 with no success. Anyway there is the windows page saying that WinMain automatically forces the compiler to link phobos. What is even more strange is that if you take Has a

Re: VC linker - unresolved external symbols - runtime

2014-01-05 Thread Palmic
Replying to myself: In my case at lease, I don't think it's a bug... I have just used the build tool binary that comes with the DWinProgramming samples, added a new folder with my source in the Samples directory, and the tool managed to build it properly... I will now look at the souces of t

Re: Is it possible to handle 'magic' property assignments a'la PHP?

2014-01-05 Thread Artur Skawina
On 01/05/14 15:36, TheFlyingFiddle wrote: > Another simple example that have helped me tremendously when debugging OpenGL > calls. A simple dispatcher that checks glGetError after every call. > > struct GL > { > auto opDispatch(string name, Args...)(Args args) > { > enum glName =

Shared library extern (C) variables

2014-01-05 Thread Mineko
I keep getting mixed results searching for this. :\ Just as the title says, is it safe to extern (C) variables? Something like this: extern (C) auto foo = 800; And then call that from another program? Also, just because this has been bugging me for a while.. Is export broken, or it it not sup

Re: VC linker - unresolved external symbols - runtime

2014-01-05 Thread Erik van Velzen
It works if you recompile phobos64.lib So it seems the standard DMD 2.064.2 download comes with an outdated version of phobos64.lib which is out of sync with the included source code.

Re: VC linker - unresolved external symbols - runtime

2014-01-05 Thread Erik van Velzen
@Palmic the DWinProgramming samples use the overload Runtime.initialize(ExceptionHandler) Which gives a warning that it is deprecated and you should use this overload instead: Runtime.initialize() But this is not compiled in phobos64.lib, while it is included in the source code. So the libr

Re: Shared library extern (C) variables

2014-01-05 Thread Jeremy DeHaan
On Sunday, 5 January 2014 at 18:22:54 UTC, Mineko wrote: I keep getting mixed results searching for this. :\ Just as the title says, is it safe to extern (C) variables? Something like this: extern (C) auto foo = 800; And then call that from another program? Also, just because this has been bu

Re: VC linker - unresolved external symbols - runtime

2014-01-05 Thread FreeSlave
On Sunday, 5 January 2014 at 19:05:58 UTC, Erik van Velzen wrote: @Palmic the DWinProgramming samples use the overload Runtime.initialize(ExceptionHandler) Which gives a warning that it is deprecated and you should use this overload instead: Runtime.initialize() But this is not compiled in

Re: Shared library extern (C) variables

2014-01-05 Thread Mineko
On Sunday, 5 January 2014 at 19:08:44 UTC, Jeremy DeHaan wrote: On Sunday, 5 January 2014 at 18:22:54 UTC, Mineko wrote: I keep getting mixed results searching for this. :\ Just as the title says, is it safe to extern (C) variables? Something like this: extern (C) auto foo = 800; And then cal

Re: VC linker - unresolved external symbols - runtime

2014-01-05 Thread Erik van Velzen
Filed under "installer" https://d.puremagic.com/issues/show_bug.cgi?id=11871 You could add the linux thing as a comment if you're sure it's the same issue.

Re: Shared library extern (C) variables

2014-01-05 Thread FreeSlave
On Sunday, 5 January 2014 at 18:22:54 UTC, Mineko wrote: I keep getting mixed results searching for this. :\ Just as the title says, is it safe to extern (C) variables? Something like this: extern (C) auto foo = 800; And then call that from another program? Also, just because this has been bu

Re: Shared library extern (C) variables

2014-01-05 Thread Mineko
On Sunday, 5 January 2014 at 19:47:46 UTC, FreeSlave wrote: Some code snippets of what you try to do would help. Maybe this example explain you something: //mod.d extern(C) int foo = 42; void changeFoo(int val) { foo = val; } //main.d import std.stdio; import mod; int main() { write

Re: VC linker - unresolved external symbols - runtime

2014-01-05 Thread FreeSlave
On Sunday, 5 January 2014 at 19:30:46 UTC, Erik van Velzen wrote: Filed under "installer" https://d.puremagic.com/issues/show_bug.cgi?id=11871 You could add the linux thing as a comment if you're sure it's the same issue. Well, I'm not sure this is same. I explored something new to me and b

libphobos.so and loading libraries at runtime

2014-01-05 Thread FreeSlave
import core.runtime; int main() { Runtime.loadLibrary("does not care"); Runtime.unloadLibrary(null); return 0; } When I try to compile this code with 'dmd main.d', I get errors main.o: In function `_D4core7runtime7Runtime17__T11loadLibraryZ11loadLibraryFxAaZPv': main.d:(.text._D4co

Re: Shared library extern (C) variables

2014-01-05 Thread Jeremy DeHaan
On Sunday, 5 January 2014 at 19:55:50 UTC, Mineko wrote: On Sunday, 5 January 2014 at 19:47:46 UTC, FreeSlave wrote: Some code snippets of what you try to do would help. Maybe this example explain you something: //mod.d extern(C) int foo = 42; void changeFoo(int val) { foo = val; } //mai

dirEntries throws exception on broken symlinks

2014-01-05 Thread dennis
I a using dirEntries to list recursively build a list of all files in all subdirectories but dirEntries is throwing an exception when it encounters a broken link. I want just report the exception, then ignore the broken link and then continue processing the rest of the dir's and files. Do I

Re: Shared library extern (C) variables

2014-01-05 Thread TheFlyingFiddle
On Sunday, 5 January 2014 at 19:55:50 UTC, Mineko wrote: Ahh I appreciate it, but I already have that part down and good. :) I was wondering about how to use export correctly, I apologize for not being clear. Also I'll keep in mind the __gshared, never even knew about it. Export is current

Re: Is it possible to handle 'magic' property assignments a'la PHP?

2014-01-05 Thread TheFlyingFiddle
On Sunday, 5 January 2014 at 17:17:27 UTC, Artur Skawina wrote: While 'void' is not a first class type in D, there /is/ a special case for returning 'void' from functions - so all of the above can simply be written as: struct gl { static auto ref opDispatch(string name, Args...)(Args

Re: dirEntries throws exception on broken symlinks

2014-01-05 Thread FreeSlave
You must not cast base class to derived class, when you don't know actual type (and even if you know exact type it's still bad practice to cast instance of more generic type to more specific one). Use multiple catch statements instead: catch(FileException o) { //handle FileException } catch(Ex

Re: Is it possible to handle 'magic' property assignments a'la PHP?

2014-01-05 Thread Philippe Sigaud
On Sun, Jan 5, 2014 at 5:18 PM, Jacob Carlborg wrote: > Just for the record. In Rails, that's the old, now discourage, Rails 2 > syntax. I didn't know that, thanks. I read it during the holidays in Martin Fowler's book on DSL, but indeed that book is from 2005, IIRC. > In Rails 3 and later the

Re: Simplest way to create an array from an associative array which its contains keys and values?

2014-01-05 Thread Philippe Sigaud
On Sun, Jan 5, 2014 at 4:49 PM, Timon Gehr wrote: > On 01/05/2014 03:55 PM, Philippe Sigaud wrote: >> >> Is there any plan to add indexing on runtime indices to Tuple? It can >> be done, by generating a specific runtime opIndex for Tuple, if the >> types held in the tuple have a common type. > > >

Implicitly converting a newly allocated array to immutable

2014-01-05 Thread Meta
The following doesn`t work: immutable(string[]) strArr = new string[](10); But I feel that it probably should work. I know we have assumeUnique, but I remember awhile ago that some work was done toward making the result of unique expressions (like those using new) implicitly convertible to im

Re: Implicitly converting a newly allocated array to immutable

2014-01-05 Thread Ali Çehreli
On 01/05/2014 05:19 PM, Meta wrote:> The following doesn`t work: > > immutable(string[]) strArr = new string[](10); A pure function is a workaround. The return value of a pure function is implicitly convertible to immutable: pure string[] foo() { return new string[](10); } void main() {

Re: dirEntries throws exception on broken symlinks

2014-01-05 Thread dennis
On Sunday, 5 January 2014 at 21:33:56 UTC, FreeSlave wrote: You must not cast base class to derived class, when you don't know actual type (and even if you know exact type it's still bad practice to cast instance of more generic type to more specific one). Use multiple catch statements instead: