Re: simple assignment statement compiles but becomes a run time error
On Sunday, 18 January 2015 at 19:51:02 UTC, WhatMeWorry wrote: On Sunday, 18 January 2015 at 19:42:33 UTC, WhatMeWorry wrote: I've got a OpenGL function returning a pointer // const GLubyte *version = glGetString(GL_VERSION); // C++ and openLG code // the following compiles with no errors or warnings char openglVersion[100] = fromStringz(glGetString(GL_VERSION)); // ABENDS HERE! // documentation from std.string shows // pure @system inout(char)[] fromStringz(inout(char)* cString); // Seems pretty innocuous to me. Debugger returns: Unhandled exception at 0x76AC2F71 (KernelBase.dll) in WhatVersionOfOpenGL.exe Hi, try replacing the fromStringz with to!string from std.conv
Re: On Variable References
On Wednesday, 21 January 2015 at 17:14:29 UTC, Meta wrote: On Wednesday, 21 January 2015 at 08:23:44 UTC, Per Nordlöw wrote: On Wednesday, 21 January 2015 at 08:22:44 UTC, Per Nordlöw wrote: int x; auto ref xr; Correction: I, of course mean, int x = 42; auto ref xr = x; Walter is strongly against adding references a la C++ to D, as he believes they are too complicated and bug prone. He's made several posts on this, but I can't find them now. Artificial constraints like this and no default constructor implementations for structs makes D annoying to use for programming that relies heavily on deterministic resource management tbh.
When to use typecons.proxy vs alias this?
I can't find much documentation/usage of typecons.proxy, but it seems extremely similar to alias this. The documentation page( http://dlang.org/library/std/typecons/proxy.html ) doesn't really seem to elaborate on this at all.
Re: When to use typecons.proxy vs alias this?
On Sunday, 25 January 2015 at 03:55:18 UTC, Adam D. Ruppe wrote: Use alias this if you want implicit conversions too. Proxy keeps the types separate void foo(Base b) { } struct Modified { Base b; alias b this; } foo(Modified()); //works That wouldn't work if it was proxied though, which you sometimes want to force everything to go through your modification. So the only difference is that proxy doesn't have implicit conversions? Hm. Might be worth pointing out on the docs.
Re: ubyte array to uint?
On Friday, 6 February 2015 at 05:18:45 UTC, Gan wrote: Is there a simple way of conversion? Something like: uint length = to!uint(buffer[0 .. 4]); Right now I have: uint length = *cast(uint*)buffer[0 .. 4].ptr; Which I'm not entirely sure is the correct way to do that. Hi, check out std.bitmanip.read http://dlang.org/phobos/std_bitmanip.html#.read
Re: Better native D 2D graphics library?
On Saturday, 7 February 2015 at 22:09:03 UTC, Gan wrote: Is there a better D graphics library in the works? I'm using SFML(which is very easy and has lots of features) but it seems to use a lot of ram(if you leave it running for a while on a graphic intensive scene) and trying to make it include the dependencies with the compiled executable is complicated. Is there a D 2D graphics library that's just as easy, cross platform, doesn't use X11, allows drawing to off-screen buffers and drawing those to screen? (plus supports nice drawing of shapes, circles, rectangles, lines) I'm probably asking too much- I doubt such a thing exists. Not what you're asking for, but you could always use SDL - I believe it has two or three bindings to D. Check on dub. I doubt you're going to find anything like SFML written in D as it's a lot of work to maintain such a project, and just duplication of effort. It's why most projects in most languages just wrap SDL in some form.
Re: How to write asia characters on console?
On Sunday, 8 February 2015 at 05:57:31 UTC, Lave Zhang wrote: Hi, My first D program is like this: --- import std.stdio; void main(string[] args) { dstring s1 = "hello你好"d; writeln(s1); } --- But the output is not correct(and my console codepage is 936): C:\D\dmd2\samples\d>dmd hello.d -offilename hello.exe C:\D\dmd2\samples\d>hello.exe hello浣犲ソ thanks. Hi, I tried your code and it works fine for me. I think the windows console only supports UTF-16, try using wchar/wstring instead of dchar/dstring.
Intended to be able to RefCount an interface?
Thread title. interface Itest{ } class testclass : Itest{ } void main() { import std.typecons; auto test = RefCounted!Itest(new testclass()); } If you change the refcounted to type testclass it doesn't compile because refcounted doesn't support classes. Is this a bug, or intended?
Re: Intended to be able to RefCount an interface?
On Tuesday, 10 February 2015 at 05:09:00 UTC, Jakob Ovrum wrote: On Tuesday, 10 February 2015 at 04:44:55 UTC, weaselcat wrote: Thread title. interface Itest{ } class testclass : Itest{ } void main() { import std.typecons; auto test = RefCounted!Itest(new testclass()); } If you change the refcounted to type testclass it doesn't compile because refcounted doesn't support classes. Is this a bug, or intended? I think this is a bug, and that the current RefCounted needs to reject interfaces. I assumed as much, thanks. AFAIK, it is intended that RefCounted!SomeClass is supposed to reference-count the actual class instance, not its reference, which is what RefCounted!SomeInterface currently does. Is there currently an enhancement request open for this on the bug tracker? I cannot find anything.
Question about scope of @nogc
(Scope might have been a bad word choice...) Is @nogc intended to only stop from calling functions that allocate with the GC, or from interacting with the GC altogether? Is there a technical reason that functions such as addrange, etc cannot be @nogc if the former since AFAIK such functions do not allocate. Thanks.
Re: GC has a "barbaric" destroyng model, I think
On Thursday, 12 February 2015 at 08:33:35 UTC, Kagamin wrote: Truth be told, D has no guideline for deterministic destruction of managed resources. +1 don't complain about people wondering why class destructors don't work when there's no _real_ way to do it in D beyond 'drop down to C level and get going.' D is absolutely horrid for resource management.
Re: What is the Correct way to Malloc in @nogc section?
On Friday, 13 February 2015 at 22:55:27 UTC, anonymous wrote: On Thursday, 12 February 2015 at 23:52:41 UTC, Foo wrote: This is something I've done recently. Would be glad if my code will help you: https://github.com/Dgame/m3 Especially the m3.d module could be useful for you. /* Class and Struct */ emplace: You can't assume zero-initialization for structs. destruct: Is not memory-safe, and must not be marked @trusted. /* Array */ make: You can't assume zero-initialization. T.sizeof is not the size of an element. reserve: Not safe (you're freeing the old memory), must not be @trusted. append: T.sizeof is not the size of an element. You're multiplying twice with T.sizeof; in `append`, and also in `reserve`. destruct: Not safe, must not be @trusted. Low level memory management isn't easy. Bugs like these wouldn't exist if D had decent smart pointer implementations in its standard library. You seem knowledgeable enough, care to lend a hand? ; )
Re: What is the Correct way to Malloc in @nogc section?
On Saturday, 14 February 2015 at 06:38:19 UTC, ketmar wrote: On Sat, 14 Feb 2015 00:57:33 +, weaselcat wrote: On Friday, 13 February 2015 at 22:55:27 UTC, anonymous wrote: On Thursday, 12 February 2015 at 23:52:41 UTC, Foo wrote: This is something I've done recently. Would be glad if my code will help you: https://github.com/Dgame/m3 Especially the m3.d module could be useful for you. /* Class and Struct */ emplace: You can't assume zero-initialization for structs. destruct: Is not memory-safe, and must not be marked @trusted. /* Array */ make: You can't assume zero-initialization. T.sizeof is not the size of an element. reserve: Not safe (you're freeing the old memory), must not be @trusted. append: T.sizeof is not the size of an element. You're multiplying twice with T.sizeof; in `append`, and also in `reserve`. destruct: Not safe, must not be @trusted. Low level memory management isn't easy. Bugs like these wouldn't exist if D had decent smart pointer implementations in its standard library. You seem knowledgeable enough, care to lend a hand? ; ) how "smart pointers" can help here? they don't magically hiding all the low-level mechanics. The file he was referring to was a smart pointer implementation.
Re: Will D have a serious dedicated well supported IDE like Visual Studio or Eclipse?
On Friday, 27 February 2015 at 04:12:50 UTC, AJ wrote: On Thursday, 26 February 2015 at 20:23:10 UTC, Rinzler wrote: I a beginner with D, actually I have almost done nothing. I am using a Mac, and Xamarin Studio seem to be the best choice, but I am not even able to make it auto-complete the standard library. Does anybody know how to do it? I am in the same boat and totally agree. It's tough going from the user-experience of IntelliJ IDEA or Visual Studio back to vi on OS X with D. There seems to be a large hole in support for D debugging outside of Visual D (line numbers, variable values, etc). I was hoping to use D for a new project, but I don't feel the tools are ready yet. GDB works fine with D, I use it regularly. http://wiki.dlang.org/Open_Source_Projects#Debugging_support_by_compiler:
Is std.signals deprecated?
Seems barely maintained and there was a proposed replacement claiming it was broken(http://wiki.dlang.org/Review/std.signal) that never got approved. Is std.signals worth using over a dub package?
Re: is struct delete deterministic? (cf used in Unique)
On Saturday, 7 March 2015 at 23:48:39 UTC, Timothee Cour wrote: I'm a little confused about the following: clear,delete,destroy. My understanding is that clear is deprecated and delete is planned to be deprecated, so we should only ever use destroy (which deterministic calls the destructor but doesn't release memory). Unique uses delete however in the destructor. Is that still guaranteeing deterministic destruction when the uniqued element is either a class or struct? (ie if the destructor has a file handle resource, will it be deterministically freed?) structs are allocated on the stack(unless instantiated with new), and call their destructor when you leave their scope. Unique still guarantees deterministic destruction because it's wrapped around a struct, it's a fairly common 'D idiom' I'd say(i.e, look at how File is implemented - D's runtime and standard library are surprisingly well documented and easy to read.) I'm not sure why Unique uses delete, might just be bitrot.
Re: is struct delete deterministic? (cf used in Unique)
On Sunday, 8 March 2015 at 01:20:57 UTC, Timothee Cour wrote: To clarify, I'm only asking about a struct allocated via new. Unique!T is wrapped around a struct, but it allocates a struct T via 'new', so my question still holds: does 'delete t' (where t is a struct allocated via new) guarantee deterministic destruction? I'm guessing yes, otherwise Unique would be broken, but where is that specified in the docs? And if delete is to be deprecated (according to the docs), what is the correct way to do that (despite fact that Unique relies on delete). On Sat, Mar 7, 2015 at 4:02 PM, weaselcat via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: On Saturday, 7 March 2015 at 23:48:39 UTC, Timothee Cour wrote: I'm a little confused about the following: clear,delete,destroy. My understanding is that clear is deprecated and delete is planned to be deprecated, so we should only ever use destroy (which deterministic calls the destructor but doesn't release memory). Unique uses delete however in the destructor. Is that still guaranteeing deterministic destruction when the uniqued element is either a class or struct? (ie if the destructor has a file handle resource, will it be deterministically freed?) structs are allocated on the stack(unless instantiated with new), and call their destructor when you leave their scope. Unique still guarantees deterministic destruction because it's wrapped around a struct, it's a fairly common 'D idiom' I'd say(i.e, look at how File is implemented - D's runtime and standard library are surprisingly well documented and easy to read.) I'm not sure why Unique uses delete, might just be bitrot. Unique!T allocates via new, but itself is meant to be allocated on the stack. When it leaves the scope it calls delete on its contents(if they're still valid - i.e, haven't been moved to a different Unique!T) delete guarantees deterministic destruction because structs guarantee deterministic destruction, and Unique!T itself is a struct. http://dlang.org/cpptod.html#raii To answer your questions, 1. Yes, Unique!T guarantees deterministic destruction of T(unless there are bugs I'm unaware of.) 2. It's on the deprecated page. http://dlang.org/deprecate.html#delete
Re: auto function attributes based on type
On Thursday, 12 March 2015 at 03:12:15 UTC, amber wrote: ... http://dlang.org/function.html#function-attribute-inference might be a good read if you haven't read it already.
Re: auto function attributes based on type
On Thursday, 12 March 2015 at 05:01:50 UTC, amber wrote: On Thursday, 12 March 2015 at 04:51:42 UTC, amber wrote: On Thursday, 12 March 2015 at 04:04:28 UTC, weaselcat wrote: On Thursday, 12 March 2015 at 03:12:15 UTC, amber wrote: ... http://dlang.org/function.html#function-attribute-inference might be a good read if you haven't read it already. I did read it but didn't really understand it, so I've come to D.learn for more help. I think it means I can just write the function like so: struct S(T) { someFunc(int i) {// impl} } and if possible it will be pure, nothrow, @safe and @nogc. thanks, amber This works nicely after checking with __traits(getFunctionAttributes, S!T.someFunc) Very cool :) bye, amber You can also use the __PRETTY_FUNCTION__ keyword to display information about a function. http://dlang.org/traits.html#specialkeywords
Re: moving from c++ to D is easy?
On Thursday, 12 March 2015 at 13:01:31 UTC, ayush wrote: Is D a lot like c++ ? I am currently midway through learning c++ and I also want to learn D . So should i focus on one or learn both together? Will I find learning D easy if I already know c++ ? D is very much like C++, but the biggest issue I found moving from C++ to D was trying to apply C++ idioms that only existed to work around ugly C++ warts(i.e, CRTP)
Re: Memoization in compile-time
On Friday, 13 March 2015 at 13:16:27 UTC, weaselcat wrote: On Friday, 13 March 2015 at 12:49:48 UTC, Dennis Ritchie wrote: On Friday, 13 March 2015 at 02:38:18 UTC, Rikki Cattermole wrote: You could assign it to e.g. an enum. Or force it over using meta-programming. And this code can be rewritten to D? template struct Factorial { enum { value = n * Factorial::value }; }; template <> struct Factorial<0> { enum { value = 1 }; }; int main() { constexpr auto x = Factorial<5>::value; constexpr auto y = Factorial<7>::value; } confusingly, D uses enum for named compile-time constants. http://ddili.org/ders/d.en/enum.html If you take Rikki's example and apply it to an enum(i.e, enum x = factorial(5); ) the program will fail to compile if it can't be computed at compile-time. woops, walked away to get coffee before I submitted and got beaten to the punch by a better answer : )
Re: Memoization in compile-time
On Friday, 13 March 2015 at 12:49:48 UTC, Dennis Ritchie wrote: On Friday, 13 March 2015 at 02:38:18 UTC, Rikki Cattermole wrote: You could assign it to e.g. an enum. Or force it over using meta-programming. And this code can be rewritten to D? template struct Factorial { enum { value = n * Factorial::value }; }; template <> struct Factorial<0> { enum { value = 1 }; }; int main() { constexpr auto x = Factorial<5>::value; constexpr auto y = Factorial<7>::value; } confusingly, D uses enum for named compile-time constants. http://ddili.org/ders/d.en/enum.html If you take Rikki's example and apply it to an enum(i.e, enum x = factorial(5); ) the program will fail to compile if it can't be computed at compile-time.
Re: Dlang seems like java now,but why not let d more like C# Style?
On Saturday, 14 March 2015 at 23:46:28 UTC, Ellery Newcomer wrote: And C# has LINQ, which when combined with the last point is fricken awesome. what does LINQ offer that UFCS-style functional programming does not?
Re: get from tuple by type
On Sunday, 15 March 2015 at 22:21:04 UTC, ketmar wrote: On Sun, 15 Mar 2015 21:59:16 +, Charles Cooper wrote: C++14 has: template constexpr T& get(tuple& t); Which allows you to get a member of the tuple struct by type. Is there an idiomatic / library way to do this in D? Preferably by indexing. why indexing? functional programming is fun! import std.typecons : tuple; template GetByType(Type, Tuple...) { import std.typecons : isTuple; static if (Tuple.length == 0) static assert(false, Type.stringof~" not found"); else static if (Tuple.length == 1 && isTuple!(typeof(Tuple[0]))) enum GetByType = GetByType!(Type, Tuple[0].expand); else static if (is(typeof(Tuple[0]) == Type)) enum GetByType = Tuple[0]; else enum GetByType = GetByType!(Type, Tuple[1..$]); } static assert(2.5 == GetByType!(double, 1, 2.5)); static assert(2.5 == GetByType!(double, 1, 2.5, 3.1)); //static assert(2.5 == GetByType!(char, 1, 2.5, 3.1)); static assert(2.5 == GetByType!(double, std.typecons.tuple(1, 2.5))); static assert(2.5 == GetByType!(double, std.typecons.tuple(1,2.5,3.1))); Seems like a useful feature(useful enough to get past the C++ standards committee,) consider submitting a phobos PR?
Re: final methods by default
On Friday, 20 March 2015 at 14:25:22 UTC, ref2401 wrote: Why aren't methods of class final by default? history use final class, it should devirtualize all methods. see: https://github.com/D-Programming-Language/dmd/pull/4427
Re: Template reference parameter
On Monday, 23 March 2015 at 22:39:28 UTC, rumbu wrote: I have only one template and I think it's impossible to define specializations since it's supposed that a random member of A... will be passed sometime by reference: auto ref? http://dlang.org/template.html#auto-ref-parameters
Re: D's type classes pattern ?
On Tuesday, 24 March 2015 at 15:51:00 UTC, matovitch wrote: Hi, It's been a long time since I coded some d code... sorry I take the lazy way asking for advices. :D Lets say I want to implement some generic algorithm. I would like to checks the types passed to my algorithm implements a specific interface. interface IStuff(Stuff) { void foo(); } class TypeClass(T, I) : I(T) { alias this T; } void myAwesomeAlgo(Stuff) (TypeClass!(Stuff, IStuff) stuff) { stuff.foo(); } Well it seems that I have worked out my question in trying to formulate it...Would something like this work ? interface Foo{ } void Bar(T : Foo)(T t){ } but interfaces enable runtime polymorphism, you can just accept the interface itself void Fun(Foo foo){ }
Re: Passing myself, a struct, as a C callback context
On Monday, 30 March 2015 at 02:53:36 UTC, Paul O'Neil wrote: As of dmd 2.067, doing "&this" is deprecated. where is this documented? I don't see it in the release notes.
Re: Passing myself, a struct, as a C callback context
On Monday, 30 March 2015 at 03:02:07 UTC, Paul O'Neil wrote: On 03/29/2015 10:57 PM, weaselcat wrote: On Monday, 30 March 2015 at 02:53:36 UTC, Paul O'Neil wrote: As of dmd 2.067, doing "&this" is deprecated. where is this documented? I don't see it in the release notes. I don't see it in the release notes either, but it's happening. Maybe it's an instance of a more general thing? if it works in 2.066 you should submit a bug report, either this shouldn't be a deprecation or it should be in the release notes.
using exceptions in @nogc
was this ever solved? I did some research and saw static immutable ones suggested a few times, but they can't be chained AFAIK.
Re: using exceptions in @nogc
On Tuesday, 31 March 2015 at 03:12:42 UTC, ketmar wrote: On Tue, 31 Mar 2015 01:40:52 +, weaselcat wrote: was this ever solved? nope. there were some suggestions, but no decision was made. sigh do you know if there's an open enhancement request for this?
Re: Maxime's micro allocation benchmark much faster ?
On Tuesday, 31 March 2015 at 20:56:09 UTC, Laeeth Isharc wrote: Trying on a different beefier machine with 2.066 and 2.067 release versions installed: 1mm allocations: 2.066: 0.844s 2.067: 0.19s 10mm allocations 2.066: 1m 17.2 s 2.067: 0m 1.15s So numbers were ballpark right before, and allocation on this micro-benchmark much faster. Wow! props to the people that worked on the GC.
Re: Reading whitespace separated strings from stdin?
On Tuesday, 21 April 2015 at 01:31:58 UTC, TheGag96 wrote: Hi guys! I had this homework assignment for data structures that has a pretty easy solution in C++. Reading input like this... 1 2 3 # $ 4 3 * ! # 20 3 / # $ # 62 # $ 2 3 8 * + # 4 48 4 2 + / # SUM # $ 1 2 3 4 5 # R # @ ...where "@" denotes the end of input is fairly simple in C++: string token = ""; while (token != "@") { //handle input } Note that having newlines doesn't matter at all; every token is just assumed to be separated by "whitespace". However in D, I looked around could not find a solution better than this: foreach (line; stdin.byLine) { foreach (token; line.split) { //handle input } } Is there any way to do this without two loops/creating an array? "readf(" %d", &token);" wasn't cutting it either. Thanks. import std.stdio; import std.array; void main(){ auto tokens = stdin.readln('@').split; writeln(tokens); } ["1", "2", "3", "#", "$", "4", "3", "*", "!", "#", "20", "3", "/", "#", "$", "#", "62", "#", "$", "2", "3", "8", "*", "+", "#", "4", "48", "4", "2", "+", "/", "#", "SUM", "#", "$", "1", "2", "3", "4", "5", "#", "R", "#", "@"]
Re: Structural exhaustive matching
On Tuesday, 21 April 2015 at 15:36:28 UTC, Jadbox wrote: What's the best equivalent to Rust's structural enum/pattern (match)ing? Is it also possible to enforce exhaustive matches? Basically, I'm curious on what the best way to do ADTs in D. D's ADTs are in std.variant, the equivalent of matching is the .visit property AFAIK
Re: Structural exhaustive matching
On Wednesday, 22 April 2015 at 04:54:39 UTC, Martin Nowak wrote: On Tuesday, 21 April 2015 at 15:36:28 UTC, Jadbox wrote: What's the best equivalent to Rust's structural enum/pattern (match)ing? Is it also possible to enforce exhaustive matches? Basically, I'm curious on what the best way to do ADTs in D. If it needs to be really fast, use final switch on the tag of a discriminated union. enum Tag { A, B, C } struct Val { Tag tag; union { A a; B b; C c; } } void too(Val val) { final switch (val.tag) { case Tag.A: writeln(val.a); break; case Tag.B: writeln(val.b); break; case Tag.C: writeln(val.c); break; } } there's no reason this should be faster than Algebraic(restricted variant) from std.variant, is there? implementation issue?
Re: std.json questions
On Sunday, 26 April 2015 at 17:14:22 UTC, extrawurst wrote: On Saturday, 25 April 2015 at 18:30:33 UTC, Baz wrote: On Saturday, 25 April 2015 at 09:56:25 UTC, tired_eyes wrote: I think this is ugly and clunky approach, what is the beautiful one? What you clearly need is a serializer: look at these: http://wiki.dlang.org/Libraries_and_Frameworks#Serialization and also: https://github.com/search?utf8=✓&q=serializer+language%3AD&type=Repositories&ref=searchresults some of them might have an API to save load an object or a struct in a single call. too bad D:YAML links are broken, do you know where to find that project ? https://github.com/kiith-sa/D-YAML
Re: Create a case-insensitive startsWith
On Tuesday, 28 April 2015 at 21:45:10 UTC, PhilipDaniels wrote: Beginner question. Given if (startsWith(input, "0x", "0X")) How do I turn that into a case-insensitive startsWith? startsWith says it takes a predicate but I can't figure out how to pass it one. The examples all use "a == b" !? These attempts below, and other things I have tried, fail with "cannot deduce function from argument types". if (startsWith!"icmp(a, b) == 0"(input, "0x")) if (startsWith!"std.uni.icmp(a, b) == 0"(input, "0x")) if (startsWith!((a,b) => icmp(a,b) == 0)(input, "0x")) I believe the issue is that the predicate expects a boolean, icmp returns an int. Try a == toLower(b) as your predicate(there's probably a better solution somewhere hidden in phobos though.)
Re: Destruction in D
On Thursday, 30 April 2015 at 20:07:11 UTC, bitwise wrote: After reading GC page in the reference, it seems that class destructors are called on a separate thread, in parallel to the main thread. Is this correct? There's no guarantee what thread will be used in the standard GC implementation AFAIK. What about structs? Are the destructors called when they go out of scope in a C++ RAII fashion, or do they happen on a separate thread too? If they're on the stack(not allocated with `new`), then they have their destructor called upon leaving scope ala C++ RAII, otherwise see above.
Re: Signs by which to recognize D1
On Wednesday, 6 May 2015 at 07:56:53 UTC, Daren Scot Wilson wrote: Someone looks at a chunk of D code of murky origin. Possibly, it is old, maybe D1 not D2. Inadequately commented, believe it or not, and not other information. What are some easy to spot details in the syntax by which the onlooker can know it's D1 not D2? a lot of keywords(pure,nothrow, shared, etc) aren't available in D1 afaik, you generally see those sprinkled all over any modern D code.
Re: Memory usage tracking
On Sunday, 10 May 2015 at 10:43:37 UTC, tcak wrote: On Sunday, 10 May 2015 at 09:44:42 UTC, tcak wrote: I am testing my web server right now. I started 5 separate consoles and continuously sending request by using "curl" to it. It uses shared memory as well, thought from `ipcs -a`, I don't see more than necessary amount of allocation. At the moment, server received about 1.5M requests, and memory usage has reached to 128MB according to System Monitor of Ubuntu. (top gives a similar value as well). I saw now on `top` command that about 650KB shared memory is used only. Is there any way to find out what is using that big space in memory? Would `-profile` do that? Problem is that if I was to be using `-profile` flag, server would slow down, and I wouldn't be able to test it correctly already. Hmm. Server was compiled in debug mode. Right now, it is 2.2M requests, and 174MB memory is in use. Which compiler are you using? Also, debug mode might have linked against debug phobos - do a ldd on your executable.
Re: Cannot find -lphobos
On Sunday, 10 May 2015 at 14:41:17 UTC, Ali Çehreli wrote: On 05/10/2015 12:45 AM, Marko Grdinic wrote: I works just fine on Windows, but I am having difficulty figuring out what the trouble is on my Bodhi 1.4 Virtual Box. I've followed the instruction on the Codeblocks Wiki and set the parameters, but when I try to compile, it complains that it can't find Phobos. /usr/bin/ld: cannot find -lphobos2 I've checked the search directories and the library directories are where it says they would be. I am not particularly familiar with Linux so I am not sure how to proceed from here. Any advice? dmd's -v flag may give some clues: $ dmd foo.d -v dmd outputs the config file that it uses and the linker flags that it passes. Ali additionally if not using dmd it may have the libraries named differently. a quick google says Bodhi linux is based on Ubuntu which doesn't ship dmd due to licensing issues AFAIK.
Re: problem with parallel foreach
On Wednesday, 13 May 2015 at 09:01:05 UTC, Gerald Jansen wrote: On Wednesday, 13 May 2015 at 03:19:17 UTC, thedeemon wrote: In case of Python's parallel.Pool() separate processes do the work without any synchronization issues. In case of D's std.parallelism it's just threads inside one process and they do fight for some locks, thus this result. Okay, so to do something equivalent I would need to use std.process. My next question is how to pass the common data to the sub-processes. In the Python approach I guess this is automatically looked after by pickling serialization. Is there something similar in D? Alternatively, would the use of std.mmfile to temporarily store the common data be a reasonable approach? Assuming you're on a POSIX compliant platform, you would just take advantage of fork()'s shared memory model and pipes - i.e, read the data, then fork in a loop to process it, then use pipes to communicate. It ran about 3x faster for me by doing this, and obviously scales with the workloads you have(the provided data only seems to have 2.) If you could provide a larger dataset and the python implementation, that would be great. I'm actually surprised and disappointed that there isn't a fork()-backend to std.process OR std.parallel. You have to use stdc
Re: functors with template lambdas
On Saturday, 16 May 2015 at 02:06:45 UTC, weaselcat wrote: very long standing compiler bug https://issues.dlang.org/show_bug.cgi?id=3051 see also https://issues.dlang.org/show_bug.cgi?id=5710 unsure if they're duplicate bugs, never really looked into it.
Re: functors with template lambdas
On Saturday, 16 May 2015 at 02:04:39 UTC, Vlad Levenfeld wrote: I think this code should be allowed, but it isn't: struct Functor (T) { T a; auto ref fmap (alias f)() { return Functor (f(a)); } } auto ref identity (T)(auto ref T a) { return a; } void main() { Functor!int a; static auto id (T)(T x) {return x;} a.fmap!identity; // ok a.fmap!id; // ok a.fmap!((int x) => x); // ok a.fmap!(x => x); // Error: template instance fmap!((x) => x) cannot use local '__lambda1' as parameter to non-global template fmap(alias f)() } This seems like one of those things that doesn't work because of some compiler implementation detail rather than a consequence of the language rules but I'm not sure. Opinion? very long standing compiler bug https://issues.dlang.org/show_bug.cgi?id=3051
Re: Dual conditions in D and Python
On Thursday, 21 May 2015 at 23:14:47 UTC, Dennis Ritchie wrote: On Thursday, 21 May 2015 at 21:35:22 UTC, Ali Çehreli wrote: We're almost there. :) bool is_between(T0, T1, T2)(T0 what, T1 min, T2 max) { return (what >= min) && (what <= max); } void main() { if (5.is_between(4, 6)) { // ... } } Ali A condition is that if, for example, that? :) if (5 > 2 > -9 > -13 < 10 == 10 < 21 != 45): print("OK") this looks like gibberish upon first sight and is not something I'd want to see in code I inherit.
Re: fwiw - quora on stroustrup/static if/D
On Thursday, 21 May 2015 at 17:36:00 UTC, Laeeth Isharc wrote: https://www.quora.com/What-does-Bjarne-Stroustrup-think-about-different-programming-languages The C++ standard committee already reviewed static_if IIRC Andrei and Walter said they were being incredibly unfair. http://forum.dlang.org/thread/cdgzdesltjefjvnjb...@forum.dlang.org#post-cdgzdesltjefjvnjbspk:40forum.dlang.org pretty long thread on it if you want to dig through it. And I'll end my post with an excerpt from the ISOCPP paper, and IMO the reason C++ is the way it is: Being a new and realtively simple-to-use new feature, static_if would un- doubtedly be used by many who have no need for the relatively small increme- natal improvement in performance offered.
Re: Python's features, which requires D
On Friday, 22 May 2015 at 00:23:30 UTC, Dennis Ritchie wrote: Hi, I've collected some of Python's features. It seems to me that they are not in the D! Surely all this is in the D? :) http://rextester.com/CNQQR D doesn't have list comprehensions, so it's difficult to directly port these. off the top of my head, the last one can easily be done with std.range.stride P.S. I think that all of this is written in D is much more lines of code! and they can be done in less with APL and J.
Re: Python's features, which requires D
On Friday, 22 May 2015 at 01:52:30 UTC, Dennis Ritchie wrote: On Friday, 22 May 2015 at 01:17:17 UTC, weaselcat wrote: D doesn't have list comprehensions, so it's difficult to directly port these. I can not imagine how difficult it is to implement it in D, but I'm pretty sure that nested for loops to fill arrays (in D, you can call them differently, for example, force :)) will be very useful thing, because Python is a veryIt is often used. Besides, I do not understand what could be the problem with nested loops in arrays, because std.algorithm.map works on the principle of nested loops. I think that the biggest problem in the implementation of this should not be. Excuse me if I'm wrong. off the top of my head, the last one can easily be done with std.range.stride import std.stdio, std.range; void main() { int[] a = [ 1, 2, 3, 4, 5, 6 ]; writeln(stride(a, 2)); // [1, 3, 5] #odd #print(x[::2]) #OK // [2, 4, 6] #even #print(x[1::2]) #no equivalent in D writeln(stride(a[1..$], 2)); auto x = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; // [2, 6, 10] #print(x[1::4]) #no equivalent in D writeln(stride(a[1..$], 4)); }
Re: opIndex vs. opSlice for empty slices
On Friday, 22 May 2015 at 05:47:28 UTC, Mike Parker wrote: I've always used opSlice to produce empty slices, but having recently read the documentation at [1], I see this: "To overload a[], simply define opIndex with no parameters:" And no mention that opSlice can fill the same role. Am I right to infer that we should prefer opIndex over opSlice for this? If so, what's the rationale? [1] http://dlang.org/operatoroverloading.html#slice http://forum.dlang.org/thread/luadir$t0g$1...@digitalmars.com#post-luadir:24t0g:241:40digitalmars.com
Re: How to append range to array?
On Saturday, 23 May 2015 at 08:35:45 UTC, weaselcat wrote: On Saturday, 23 May 2015 at 07:03:35 UTC, Vladimir Panteleev wrote: int[] arr = [1, 2, 3]; auto r = iota(4, 10); // ??? assert(equal(arr, iota(1, 10))); import std.array : array; arr ~ r.array; woops, meant ~= but this is probably fairly inefficient. Working with ranges and arrays at the same time feels really badly designed.
Re: How to append range to array?
On Saturday, 23 May 2015 at 07:03:35 UTC, Vladimir Panteleev wrote: int[] arr = [1, 2, 3]; auto r = iota(4, 10); // ??? assert(equal(arr, iota(1, 10))); import std.array : array; arr ~ r.array;
Re: Dual conditions in D and Python
On Saturday, 23 May 2015 at 17:17:17 UTC, Andrei Alexandrescu wrote: On 5/21/15 2:35 PM, Ali Çehreli wrote: On 05/21/2015 12:44 PM, Meta wrote: All we need is user-defined opIs and then we're really cooking with gas. if (5 is between(4, 6)) { //... } We're almost there. :) bool is_between(T0, T1, T2)(T0 what, T1 min, T2 max) { return (what >= min) && (what <= max); } void main() { if (5.is_between(4, 6)) { // ... } } In fact we'll be there with 2.068: http://dlang.org/phobos-prerelease/std_algorithm_sorting.html#.ordered if (ordered(4, 5, 6)) { ... } if (strictlyOrdered(4, 5, 6)) { ... } Andrei I didn't realize this got pulled, I remember it being discussed a while back on the general NG. Good addition.
Re: Python's features, which requires D
On Friday, 22 May 2015 at 00:23:30 UTC, Dennis Ritchie wrote: Hi, I've collected some of Python's features. It seems to me that they are not in the D! Surely all this is in the D? :) http://rextester.com/CNQQR After another review, I think some of these conversions to D could be expressed much easier if the built-in slice had multidimensional slicing It was added in 2.066* but I don't think there's any plans to add support for it to slices. * - you can see an example at http://denis-sh.bitbucket.org/unstandard/unstd.multidimarray.html
Re: Utf8 to Utf32 cast cost
On Monday, 8 June 2015 at 10:49:59 UTC, Ilya Yaroshenko wrote: On Monday, 8 June 2015 at 10:42:00 UTC, Kadir Erdem Demir wrote: I want to use my char array with awesome, cool std.algorithm functions. Since many of this algorithms requires like slicing etc.. I prefer to create my string with Utf32 chars. But by default all strings literals are Utf8 for performance. With my current knowledge I use to!dhar to convert Utf8[](or char[]) to Utf32[](or dchar[]) dchar[] range = to!dchar("erdem".dup) How costly is this? Is there a way which I can have Utf32 string directly without a cast? 1. dstring range = to!dstring("erdem"); //without dup 2. dchar[] range = to!(dchar[])("erdem"); //mutable 3. dstring range = "erdem"d; //directly 4. dchar[] range = "erdem"d.dup; //mutable what's wrong with http://dlang.org/phobos/std_utf.html#.toUTF32
Re: Shortest way to allocate an array and initialize it with a specific value.
On Thursday, 11 June 2015 at 07:57:47 UTC, Per Nordlöw wrote: On Wednesday, 10 June 2015 at 22:03:52 UTC, Ali Çehreli wrote: Another option: void main() { auto a2 = new ubyte[5]; But this causes an extra zero-initialization of a2. just an fyi, gdc optimizes this away(looks like it overwrites the typeinfo,) ldc does not.
Re: AMD & Windows 7
On Friday, 12 June 2015 at 10:54:46 UTC, Chris wrote: Has anyone run into problems with D on AMD processors? I'm talking about Windows 7 on a HP625 laptop in particular. Can you be any more specific? What kind of problems?
Re: Does anyone get line numbers in stack traces on Linux?
On Wednesday, 17 June 2015 at 11:07:29 UTC, weaselcat wrote: On Wednesday, 17 June 2015 at 07:53:16 UTC, Atila Neves wrote: I thought it was because I was weird and I use gold as my linker, but ld.bfd produced the same results. The most I could find in bug reports was someone complaining it used to work but the consensus was that it never did? Atila addr2line BTW, I use the backtrace API from glibc to dump a stack trace that is filtered through addr2line and demangled.
Re: Does anyone get line numbers in stack traces on Linux?
On Wednesday, 17 June 2015 at 07:53:16 UTC, Atila Neves wrote: I thought it was because I was weird and I use gold as my linker, but ld.bfd produced the same results. The most I could find in bug reports was someone complaining it used to work but the consensus was that it never did? Atila addr2line
Re: Program exited with code -11
On Tuesday, 23 June 2015 at 03:29:14 UTC, Charles Hawkins wrote: Thanks, Adam. I'm coming from OCaml and haven't seen a seg fault in years. Didn't recognize it. :D Hopefully I can figure it out from here. Try to compile with either ldc or gdc and the -g flag, it should give you a backtrace. dmd seems to not like linux wrt backtraces.
Re: Program exited with code -11
On Tuesday, 23 June 2015 at 06:50:28 UTC, Charles Hawkins wrote: On Tuesday, 23 June 2015 at 03:31:37 UTC, weaselcat wrote: On Tuesday, 23 June 2015 at 03:29:14 UTC, Charles Hawkins wrote: [...] Try to compile with either ldc or gdc and the -g flag, it should give you a backtrace. dmd seems to not like linux wrt backtraces. Thanks. I wish! I haven't had any success in compiling with anything but dub. gdc, dmd, rdmd always give me "module mylib is in file 'mylib.d' which cannot be read" on my "import mylib;" statement. I've tried every permutation of -I and -L that I can think of. It almost appears that one either uses dub for everything or nothing and I'm getting pretty frustrated with it as well. Perhaps I should just go back to old-fashioned make files? you can instruct dub to use other compilers with the --compiler option valid options include dmd,ldc,gdc,gdmd,ldmd
Re: Program exited with code -11
On Wednesday, 24 June 2015 at 07:52:10 UTC, Charles Hawkins wrote: On Wednesday, 24 June 2015 at 06:54:57 UTC, weaselcat wrote: On Tuesday, 23 June 2015 at 06:50:28 UTC, Charles Hawkins wrote: [...] you can instruct dub to use other compilers with the --compiler option valid options include dmd,ldc,gdc,gdmd,ldmd Ah, a "sort of" hidden option. I've only been typing "dub" and thus, "dub --help". Didn't think to do "dub build --help". Is there a quick way to get gdc to recognize std.experimental.logger? I'm already spoiled by it. Choosing between it and a backtrace is difficult. I believe it's available as a dub package albeit outdated, should be roughly similar though.