Re: Cannot compile program with DMD built from source
On Wednesday, 9 March 2016 at 16:13:38 UTC, Minas Mina wrote: Hello, I have followed the instructions here (http://wiki.dlang.org/Starting_as_a_Contributor#POSIX) to install DMD, druntime and phobos from source. My platform is Ubuntu 15.10 x64. This is the error I get: http://pastebin.com/kWCv0ymn Sorry I didn't explain well. All 3 components (DMD, druntime and phobos) were built successfully. The error I posted above is when trying to compile this code: import std.stdio; import std.experimental.logger; void main() { auto logger = new FileLogger("log"); logger.info("test"); }
Cannot compile program with DMD built from source
Hello, I have followed the instructions here (http://wiki.dlang.org/Starting_as_a_Contributor#POSIX) to install DMD, druntime and phobos from source. My platform is Ubuntu 15.10 x64. This is the error I get: http://pastebin.com/kWCv0ymn
Application with WinMain does not start
I added a WinMain function to my application because I don't want it to open a console when running on windows. But now it doesn't even start... extern (Windows) int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { bool b = true; while (b) { sync(Clock.currTime(utcTimeZone())); Thread.sleep(getNextTimeToRun() - Clock.currTime(utcTimeZone())); } return 0; } And this is my DUB configuration: name "..." description "..." copyright "..." authors "..." targetType "executable" lflags "/SUBSYSTEM:windows" "/EXETYPE:NT" platform="windows" I got those flags from here: http://wiki.dlang.org/D_for_Win32 Any ideas:
Re: efficient and safe way to iterate on associative array?
On Friday, 4 March 2016 at 13:53:22 UTC, aki wrote: Is it okay to modify associative array while iterating it? import std.stdio; void main() { string[string] hash = [ "k1":"v1", "k2":"v2" ]; auto r = hash.byKeyValue(); while(!r.empty) { auto key = r.front.key; auto value = r.front.value; r.popFront(); writefln("key=%s, value=%s", key, value); // may not modify 'hash' here ? hash = null; } } I guess probably it's not. Then, my question is are there an efficient and safe way to iterate on an associative array even if there are possibility to be modified while iterating? I'm writing interpreter and want to make my language to be safe; even malicious script cannot fall it in 'core dump' state. It is okay if it causes undefined behavior like throw or instant exit from loop, but not crash. Thanks, Aki. I think what you can do is extract its contents to an array, iterate it and modify it as you like, and then insert back to another associative array. I don't think it's efficient but I don't know if it's possible to do something else.
Trouble installing DCD on Windows
Hello. I'm trying to install DCD on windows 8.1 using DUB but I get an error. When executing "dub build --build=release --config=client" I get the following error: => Root package dcd contains reference to invalid package libdparse >=0.5.0 <0.6.0 <=
Re: std.experimental.logger.Logger writeLogMsg is @safe?
On Monday, 22 February 2016 at 23:03:38 UTC, Jonathan M Davis wrote: On Monday, February 22, 2016 22:22:01 Minas Mina via Digitalmars-d-learn wrote: [...] Short answer: [...] Great, thanks.
std.experimental.logger.Logger writeLogMsg is @safe?
I'm trying to inherit from Logger, and I my custom logger to print to stdout using writeln(). But I can't because writeLogMsg is @safe, whereas writeln() is @system. Why is writeLogMsg @safe? This is too restrictive.
Re: is increment on shared ulong atomic operation?
On Sunday, 7 February 2016 at 19:43:23 UTC, rsw0x wrote: On Sunday, 7 February 2016 at 19:39:27 UTC, rsw0x wrote: On Sunday, 7 February 2016 at 19:27:19 UTC, Charles Hixson wrote: If I define a shared ulong variable, is increment an atomic operation? E.g. shared ulong t; ... t++; It seems as if it ought to be, but it could be split into read, increment, store. I started off defining a shared struct, but that seems silly, as if the operations defined within a shared struct are synced, then the operation on a shared variable should be synced, but "+=" is clearly stated not to be synchronized, so I'm uncertain. https://dlang.org/phobos/core_atomic.html#.atomicOp Just noticed that there's no example. It's used like shared(ulong) a; atomicOp!"+="(a, 1); Wow, that syntax sucks a lot.
Re: Proper Use of Assert and Enforce
On Wednesday, 14 March 2012 at 05:44:24 UTC, Chris Pons wrote: I'm new, and trying to incorporate assert and enforce into my program properly. My question revolves around, the fact that assert is only evaluated when using the debug switch. I read that assert throws a more serious exception than enforce does, is this correct? I'm trying to use enforce in conjunction with several functions that initialize major components of the framework i'm using. However, i'm concerned with the fact that my program might continue running, while I personally would like for it to crash, if the expressions i'm trying to check fail. Here is what i'm working on: void InitSDL() { enforce( SDL_Init( SDL_Init_Everything ) > 0, "SDL_Init Failed!"); SDL_WN_SetCaption("Test", null); backGround = SDL_SetVideoMode( xResolution, yResolution, bitsPerPixel, SDL_HWSURFACE | SDL_DOUBLEBUF); enforce( backGround != null, "backGround is null!"); enforce( TTF_Init() != -1, "TTF_Init failed!" ); } Is it proper to use in this manner? I understand that I shouldn't put anything important in an assert statement, but is this ok? Use assertions when a variable's value should not depend on external factors. For example, let's say you want to write a square root function. The input must be >= 0, and because this depends on external factors (e.g. user input), you must check it with `enforce()`. The output of the function must should always be >= 0 as well, but this does not depend on any external factor, so use assert for it (a negative square root is a program bug). auto sqrt(float val) { enfore(val >= 0f); float result = ... assert(result >= 0f); return result; }
Re: Most performant way of converting int to string
On Wednesday, 23 December 2015 at 22:29:31 UTC, Andrew Chapman wrote: On Wednesday, 23 December 2015 at 11:46:37 UTC, Jakob Ovrum wrote: On Wednesday, 23 December 2015 at 11:21:32 UTC, Jakob Ovrum wrote: Dynamic memory allocation is expensive. If the string is short-lived, allocate it on the stack: See also std.conv.toChars[1] for stringifying lazily/on-demand. http://dlang.org/phobos/std_conv#toChars Thanks Jakob! I did try toChars but I couldn't quite figure out a syntax of calling it that the compiler was happy with. From memory I tried things along the lines of: string v = toChars!(16,char,LetterCase.lower)(i); to convert an integer to Hex for example, but the compiler wasn't happy with it. How would I convert an int to a string using this? Cheers. I haven't tested it, but: `toChars` doesn't return a string -- that's the whole point :) It returns a range, so you have to call it something like: auto v = toChars!(16,char,LetterCase.lower)(i);
Re: Using executeShell in multiple thread causes access violation error
bump
Using executeShell in multiple thread causes access violation error
I have written a script that visits all directories in the current directory and executes a command. In my case, git pull. When running the script serially, everything is fine. All git repositories are pulled. But I'd like to pull multiple repositories in parallel to speed things up. So I've changed my loop from foreach(entry; dirs) to foreach(entry; parallel(dirs)) After a while that the program is running I get: std.exception.ErrnoException@std\stdio.d(638): Could not close file `HANDLE(C0)' (No error) 0x00411E5C 0x0040B8AB 0x0040A146 0x00402288 0x00403A99 0x00413B95 0x004095FC 0x00439AA0 0x770992B2 in RtlInitializeExceptionChain 0x77099285 in RtlInitializeExceptionChain object.Error@(0): Access Violation 0x00439429 0x0043A277 0x00411ECD 0x763A9B2C in GetFileAttributesW Here is the code: http://pastebin.com/Tk0TBGxs
How do I use dub?
I intent to use D to make a small 2D game. I have downloaded eclipse, DDT plugin and dub. I also set the path to dub in eclipse. So I made a new project, tested a writeln and it worked. The next step was to add some dependencies for derelict. I need SFML for now (and DerelictUtils of course). So this is what I've done: { name : DTest, description : A minimal D bundle., dependencies : { derelict-util: =1.0.3, derelict-sfml2: ~2.1 }, versions-x86_64: [UseAmd64Impl], lflags: [-I/home/minas/.dub/packages/derelict-sfml2-2.1/lib, -LDerelictSFML2] } The way I specified the library seems very ugly to me. Essentially it's a full path... How can I tell dub to use it by locating it automatically from its local repository?
Re: How do I use dub?
Oh and another thing: The program compiles right now but I can't execute it because for some reason: Failed to create a child process. Cannot run program /home/minas/Projects/eclipse_workspace/DTest/dtest (in directory /home/minas/Projects/eclipse_workspace/DTest): error=13, Permission denied Running from terminal yields the same error.
Re: Global const variables
On Tuesday, 21 October 2014 at 08:02:52 UTC, bearophile wrote: Currently this code gets rejected: const int[] a = [1]; void main() pure { auto y = a[0]; } test2.d(3,14): Error: pure function 'D main' cannot access mutable static data 'a' test2.d(3,14): Error: pure function 'D main' cannot access mutable static data 'a' But is this a good idea? Isn't it better to accept it? Bye, bearophile Aren't pure functions supposed to return the same result every time? If yes, it is correct to not accept it.