Deserializing JSON as an abstract type
So I'm trying to make a D wrapper for Telegram's JSON API using libtdjson. All results coming from the JSON API take the following structure: { "@type": "className", "foo": "bar", "baz" { "@type": "otherClass" } } where every object, including nested ones, has a "@type" field which will correspond to a D class. There will be over 770 possible types. So what I'm trying to figure out is how to deserialize the JSON so that it automatically gets parsed into the correct type. I'm looking at asdf right now, but it doesn't seem like it has anything like that built in. Any ideas?
Re: Pro programmer
On Monday, 26 August 2019 at 06:46:04 UTC, GreatSam4sure wrote: What is the path of becoming very good at programming? Which language will one start with. Often it's the language that best solves the problem at hand for you, but it really depends on what you want to achieve. For fast scripting and modelling maybe Python would be a good choice. But Python can be a dead end when it comes to performance etc. If you want to develop apps for Android/iOS you're better off using Java or better still Kotlin (Android) and Swift (iOS). You should always decouple the business logic of your app from the UI. So you can write code in C/C++ or D and later link it to any UI. Anyway, always think of where you want to go, e.g. portability / cross-platform and see what best suits you. If you wanna go mobile use a language that runs on mobile platforms like Android and iOS. If you want to write for desktop or server only you have more choices. Unfortunately, Android/iOS support for D leaves much to be desired. I have some real-world situation I want to model but I am at a loss as to how to start. For instance, I do one build a GUI framework like adobe spark, javafx,etc with minimum dependency or no dependency from the ground up. The lack of easily customizable, platform native GUI in D is a real concern to me but I don't have the expertise to do it. There is DlangUI: https://github.com/buggins/dlangui Check it out. And there are D bindings to other UI frameworks. Where is the starting point of doing such amazing thing? The truth of the matter is that you only know after years of programming what you need and what you don't need. As you get wiser you become less excited about the latest fancy feature of language X. Basically all languages have similar core features to model the world and solve problems (hash maps, arrays, structs, classes etc.) Just start to write programs that solve problems and enjoy... Thanks for your reply
Re: [vibe.d/dub] Linker error
On Friday, 9 March 2018 at 13:46:33 UTC, Chris wrote: I got this error msg today (see below): DUB version 1.8.0, built on Mar 3 2018 vibe.d version 0.8.3 dmd 2.078.3 (the same with 2.079.0 and 2.077.0) .dub/build/server64_72_debug-debug-linux.posix-x86_64-dmd_2079-CAC4A12AC8FE4B4625A9511E4EFEB8F6/anscealai.o: In function `_D3std5range10primitives__T5doPutTSQBh6format__T11hasToStringTSQCj8typecons__T5TupleTAysTmZQnTaZ9__lambda1MFZ1STaZQDjFNaNbNiNfKQDpaZv': /usr/include/dlang/dmd/std/range/primitives.d:269: undefined reference to `_D3std6format__T11hasToStringTSQBd8typecons__T5TupleTAysTmZQnTaZ9__lambda1MFZ1S3putMFNaNbNiNfaZv' [...and loads of other similar messages...] collect2: error: ld returned 1 exit status Error: linker exited with status 1 /usr/bin/dmd failed with exit code 1. It is so massive that it must be something ridiculous. Ok, I've solved it now with a fresh head on my. I had `dflags "-allinst"` in the dub.sdl file which was there due to an old bug in dmd, I think. Once I had removed it, the linking worked. I knew it was something ridiculous.
[vibe.d/dub] Linker error
I got this error msg today (see below): DUB version 1.8.0, built on Mar 3 2018 vibe.d version 0.8.3 dmd 2.078.3 (the same with 2.079.0 and 2.077.0) .dub/build/server64_72_debug-debug-linux.posix-x86_64-dmd_2079-CAC4A12AC8FE4B4625A9511E4EFEB8F6/anscealai.o: In function `_D3std5range10primitives__T5doPutTSQBh6format__T11hasToStringTSQCj8typecons__T5TupleTAysTmZQnTaZ9__lambda1MFZ1STaZQDjFNaNbNiNfKQDpaZv': /usr/include/dlang/dmd/std/range/primitives.d:269: undefined reference to `_D3std6format__T11hasToStringTSQBd8typecons__T5TupleTAysTmZQnTaZ9__lambda1MFZ1S3putMFNaNbNiNfaZv' [...and loads of other similar messages...] collect2: error: ld returned 1 exit status Error: linker exited with status 1 /usr/bin/dmd failed with exit code 1. It is so massive that it must be something ridiculous.
Re: Undefined Reference to OpenSSL EVP functions
On Tuesday, 16 January 2018 at 00:52:09 UTC, Chris wrote: I am trying to hook up OpenSSL to a dlang project I'm working on, but I have hit a problem when trying to link. I currently get the following linking error: undefined reference to `EVP_CIPHER_CTX_init' I have made sure to include the module wrapping the c headers import deimos.openssl.evp; And I have made sure that I am linking to "libcrypto" and "libssl" in my "dub.json" file. I have even pointed the linker to my "/usr/lib" folder And I made sure that those libraries are installed on my system in "/usr/lib" libcrypto.o libssl.o Here is the code that I am trying to run: import deimos.openssl.evp void main() { EVP_CIPHER_CTX *ctx; EVP_CIPHER_CTX_init(ctx); } Here is the full verbose output of dub: https://pastebin.com/raw/4FnhCyr2 Here is my full dub.json file: https://pastebin.com/raw/1Z3WGBET Any help would be greatly appreciated! Thank you so much! Hi Everyone, this is not an error in D, or the OpenSSL wrapper code it's just me not reading the OpenSSL man pages... EVP_CIPHER_CTX_init is not longer the way to create the context in 1.1.0 - It has been replaced by: EVP_CIPHER_CTX *ctx; ctx = EVP_CIPHER_CTX_new() RTFM...
Undefined Reference to OpenSSL EVP functions
I am trying to hook up OpenSSL to a dlang project I'm working on, but I have hit a problem when trying to link. I currently get the following linking error: undefined reference to `EVP_CIPHER_CTX_init' I have made sure to include the module wrapping the c headers import deimos.openssl.evp; And I have made sure that I am linking to "libcrypto" and "libssl" in my "dub.json" file. I have even pointed the linker to my "/usr/lib" folder And I made sure that those libraries are installed on my system in "/usr/lib" libcrypto.o libssl.o Here is the code that I am trying to run: import deimos.openssl.evp void main() { EVP_CIPHER_CTX *ctx; EVP_CIPHER_CTX_init(ctx); } Here is the full verbose output of dub: https://pastebin.com/raw/4FnhCyr2 Here is my full dub.json file: https://pastebin.com/raw/1Z3WGBET Any help would be greatly appreciated! Thank you so much!
Pass range to a function
I'm using regex `matchAll`, and mapping it to get a sequence of strings. I then want to pass that sequence to a function. What is the general "sequence of strings" type declaration I'd need to use? In C#, it'd be `IEnumerable`. I'd rather not do a to-array on the sequence, if possible. (e.g. It'd be nice to just pass the lazy sequence into my categorize function.) What is the value of `???` in the following program: ``` import std.stdio, std.regex, std.string, std.algorithm.iteration; auto regexToStrSeq(RegexMatch!string toks) { return toks.map!(t => t[0].strip()); } void categorize(??? toks) { foreach (t; toks) { writeln(t); } } void main() { auto reg = regex("[\\s,]*(~@|[\\[\\]{\\}()'`~^@]|\"(?:.|[^\"])*\"|;.*|[^\\s\\[\\]{}('\"`,;)]*)"); auto line = "(+ 1 (* 2 32))"; auto baz = matchAll(line, reg); categorize(regexToStrSeq(baz).array); } ```
Re: Copying and moving directories
On Friday, 17 February 2017 at 11:40:35 UTC, Jonathan M Davis wrote: Well, there's a _long_ history of it being called rename on POSIX systems, and since the D function is a simple wrapper around rename, it makes sense that it's called rename, much as I agree that the name isn't the best for anyone not familiar with the C function. Regardless, changing it now would break code, and at this point, we pretty much never rename public symbols in Phobos just to improve their names. Nobody wants to rename `rename` :-) But an additional `move` function would be nice. [...] I agree. std.file needs more work.
Re: Copying and moving directories
On Thursday, 16 February 2017 at 17:06:30 UTC, Jonathan M Davis wrote: Well, there's zero difference between renaming the file or directory and moving it. It's simply a difference in name. rename actually comes from POSIX, where rename is used in C code, and mv is used in the shell. So, I guess that you can blame POSIX. But there really isn't any reason to have a mv or move function in addition to rename. `mv` or `move` would be more intuitive. I actually looked for names similar to the operations available in the shell (cp/copy, mv/move). It took me a few minutes to realize I had to use `rename` (which is poorly documented). But it is counter-intuitive. When you use a GUI, `rename` doesn't change the location. `rename` is a bit "techy", you have to go "wait a minute, when you think about it, rename should do the same". But that's not good enough for a library function. One of D's slogans is `simple things should be simple`, so moving a file should be `move(dir, toDir)`. Seriously, you don't want to spend much time on stuff like that. If you want mv instead, just alias rename to mv. However, I would point out that rename has the problem (at least on *nix - not sure about Windows) that it can't move across filesystem boundaries. I think that at some point, an alternative which did work across filesystem boundaries was proposed, and that may have been called move. It's not currently in Phobos though. - Jonathan M Davis That is actually a bit of a problem. First, I might want to store backup files on a different device. Second, loads of applications need this nowadays to interact with MP3 players, ebook readers etc.
Re: Copying and moving directories
On Thursday, 16 February 2017 at 16:41:48 UTC, Adam D. Ruppe wrote: On Thursday, 16 February 2017 at 16:38:51 UTC, Chris wrote: In `std.file`, I haven't found a function that allows me to move or at least copy directories, as in `mv dir /toDir`. Do I have to go the awkward way over `rename` or something? Have you already tried just renaming the directory? Yes, but that's a bit awkward. It'd be handier to have a function like `mv(dir, toDir)`.
Copying and moving directories
In `std.file`, I haven't found a function that allows me to move or at least copy directories, as in `mv dir /toDir`. Do I have to go the awkward way over `rename` or something?
Re: Other libraries - web site link, and other thoughts
Forgive if I'm suggesting something which was already discussed and dismissed, but I too would love a way to leverage C++ stuff into D. Can't we go to C++? Meaning there's a C++ compiler coming from the same hands as D. Couldn't we try to get the C++ compiler to compile in such a manner that D can easily pick up the result? I will only use libraries where I have the source code, so from my point of view, I don't need binary compatibility. I also don't need D to pollute itself with the past. But if the Digital Mars C++ compiler could help and assist with creating libs/dlls etc that are properly set up for D and possibly produce the import for D, then it would solve a lot of things. For instance, if a project is in C++, you will need to be able to track revisions to that project, meaning the D conversion should be reasonably painless. Take something like WxWidgets for instance, the D port is stale, but WxWidgets is compatible with Digital Mars. If any project doesn't support Digital Mars C++, then it would be a C++ to C++ port, which is always going to be easier and less volatile than a C++ to D port. Just wondering
Re: [Semi-OT] I don't want to leave this language!
On Thursday, 8 December 2016 at 11:09:12 UTC, ketmar wrote: [...] what can be done, tho, is article (or series of articles) describing what exactly druntime is, how it is compared to libc and libc++, why it doesn't hurt at all, how to do "bare metal" with custom runtime, why GC is handy (and how to limit GC impact if that is necessary), and so on. that is something D Foundation should do, i believe. Amen. Features should never become a religion (else you'll get Java :).
Re: [Semi-OT] I don't want to leave this language!
On Wednesday, 7 December 2016 at 16:43:54 UTC, bachmeier wrote: On Wednesday, 7 December 2016 at 16:15:32 UTC, Chris wrote: I don't understand this discussion at all. Why not have both? I don't need bare metal stuff at the moment but I might one day, and I perfectly understand that people may need it. At the same time, there are people who are happy with runtime/Phobos/GC. In my opinion it's not a question of "either or" but of "both and". I can only speak for myself, but the concern is that we'll move in the direction of Rust, where you're supposed to read a dissertation on memory management before writing "Hello, World". The current state of affairs should be the default. Those with more advanced uses in mind should be able to do what they need, but it should be done without pushing away non-hard core developers. The "hard way" (no runtime/Phobos/GC) should not be the default and I hope that nobody is seriously suggesting this. It should be available in case anyone needs it. I dare doubt, however, that C/C++ programmers will take to D like ducks take to water because of it. It's been said time and time again that D's mission is no longer to convert C/C++ programmers ("a better C++") but to provide a good tool for programming. I think D still suffers from the slogan that it's "a better C++". Bad marketing, because you'll always be compared to C++. Imagine you date a woman and tell her "I'm a better your ex-boyfriend/ex-husband".
Re: [Semi-OT] I don't want to leave this language!
On Wednesday, 7 December 2016 at 15:17:21 UTC, Picaud Vincent wrote: On Wednesday, 7 December 2016 at 11:48:32 UTC, bachmeier wrote: [...] I understand and I do agree with these points, honestly. These points are also the reason why I will maybe try to use D for my own codes (D is really much better than C++ concerning template, meta programming syntax, embedded unit tests etc...). However I think that to popularize/attract people to use D, it is very important, to have a mechanism/feature that allows you to be close to the "zero overhead" situation. If you have two concurrent libraries (even in different languages), people will adopt the fastest one... As an example, look at the BLAS lib, people do not try to read/understand the code to see how nice it is, they just look at benchmarks and take the fastest implementation for their architecture. IMHO that is the reason why D must let the opportunity, for those who want (library developers for instance) of coding down to the metal: the goal is to have visibility in benchmarks and to attract users. At least it is my point of view. -- Vincent I don't understand this discussion at all. Why not have both? I don't need bare metal stuff at the moment but I might one day, and I perfectly understand that people may need it. At the same time, there are people who are happy with runtime/Phobos/GC. In my opinion it's not a question of "either or" but of "both and".
Re: Switch ignores case (?)
On Thursday, 24 November 2016 at 10:12:40 UTC, ketmar wrote: thanks. tbh, i am surprised myself -- it is completely fubared, but nobody noticed. maybe that says something about real-world useability of dstring/wstring... ;-) Well, I came across it, because I wanted to work around autodecode, our old "friend" (who need enemies, if you have a friend like that?). Except, it doesn't work as expected. For my needs, I can work around it with `(c == "\u2019")`, because switch works for the rest of the (common) cases like full stop, question mark etc. The whole string handling issue in D needs to be fixed asap, because text processing is one of _the_ big things in IT these days. Think of all the data harvesting and evaluation and whatnot.
Re: Switch ignores case (?)
On Wednesday, 23 November 2016 at 22:13:38 UTC, ketmar wrote: On Wednesday, 23 November 2016 at 22:00:58 UTC, Steven Schveighoffer wrote: I can't see why you need to deal with the glue layer at all -- just tell the glue layer that it's a list of strings and not dstrings ;) 'cause that is how s2ir.d is done in dmd. ;-) it actually sorts *objects*, and objects knows how to order 'emselves. at this stage it is not trivial to treat objects as byte arrays (easy, but not a one-liner). sure, other compilers may do that differently, and it doesn't really matter how exactly the code for switch is generated until it works correctly. ;-) Great job, ketmar! I'm only surprised that this bug wasn't discovered earlier, I mean it goes back to (at least) dmd 2.040.
Re: Switch ignores case (?)
On Wednesday, 23 November 2016 at 19:30:01 UTC, ketmar wrote: On Wednesday, 23 November 2016 at 19:07:49 UTC, Chris wrote: It has something to do with the smart quote, e.g.: it is wrong binary search in `_d_switch_string()`. strings for switch are lexically sorted, and compiler calls `_d_switch_string()` to select one. the thing is that comparison in `_d_switch_string()` is done with `memcmp()`. still not clear? ok, let's see how cases are encoded: body _d_switch_dstring() 'U0027' (ca) table[0] = 1, 'U0027' table[1] = 1, 'U2019' or, in memory: table[0] = 1, 0x27, 0x00 table[1] = 1, 0x19, 0x20 so, memcmp for `table[1]` returns... 1! 'cause 0x27 is greater than 0x19. and binsearch is broken from here on. the same is true for `_d_switch_ustring()`, of course. this can be fixed either by using slow char-by-char comparisons in druntime, or by fixing codegen, so it would sort strings as byte arrays. Actually, I came across a compiler message that gave me something like \x19\x20 which I found odd. This sure needs fixing. After all, it's quite a basic feature. So it's back to the old `if` again (for now).
Re: Switch ignores case (?)
On Wednesday, 23 November 2016 at 18:34:28 UTC, Steven Schveighoffer wrote: Please file here: https://issues.dlang.org/enter_bug.cgi I think this has been there forever. Happens in 2.040 too (the earliest dmd I have on my system). -Steve Here it is: https://issues.dlang.org/show_bug.cgi?id=16739 (I think I marked it as "P1" (default option), maybe it's "P2", didn't know what to choose) It has something to do with the smart quote, e.g.: import std.array; import std.conv; import std.stdio; void main() { auto tokens = to!(dchar[][])(["D"d, "’"d, "Addario"d, "'"d, "."d]); // Or use this below: //~ dstring[] tokens = ["D"d, "’"d, "Addario"d, "'"d]; while (!tokens.empty) { switch (tokens[0]) { case "\u2019"d: writeln("Apostrophe smart " ~ tokens[0]); break; case "\u0027"d: writeln("Apostrophe straight " ~ tokens[0]); break; case "D"d: writeln("Letter 'D'"); break; case "."d: writeln("fullstop " ~ tokens[0]); break; default: writeln("Other " ~ tokens[0]); break; } tokens = tokens[1..$]; } } prints: Letter 'D' Other ’ // <== not expected Other Addario Apostrophe straight ' fullstop . Both LDC and DMD produce the same error. I discovered this while writing a tokenizer. It is a bit upsetting, because it is really an essential thing. The workaround for now would be if (token[0] == "\u2019"d) goto Wherever; which works, by the way.
Re: Switch ignores case (?)
On Wednesday, 23 November 2016 at 17:33:04 UTC, Steven Schveighoffer wrote: I tested this locally with different ideas. This definitely looks like a codegen bug. I was able to reduce it to: void main() { switch("'"d) { case "'"d: writeln("a"); break; case "’"d: writeln("b"); break; default: writeln("default"); } } prints "default" What seems to fix it is removing the case statement for the "smart apostrophe". So I'd look there for where the bug is triggering. -Steve Yep, removing one of the two cases works. I tried it with different versions of dmd back to 2.070.0, and it always gives me the same (wrong) result. I haven't tried ldc yet.
Switch ignores case (?)
Only one of the two cases is considered. What am I doing wrong? ` import std.array; import std.conv; import std.stdio; void main() { auto tokens = to!(dchar[][])(["D"d, "’"d, "Addario"d, "'"d]); // Or use this below: //~ dstring[] tokens = ["D"d, "’"d, "Addario"d, "'"d]; while (!tokens.empty) { switch (tokens[0]) { case "\u2019"d: writeln("Apostrophe smart " ~ tokens[0]); break; case "\u0027"d: writeln("Apostrophe straight " ~ tokens[0]); break; default: writeln("Other " ~ tokens[0]); break; } tokens = tokens[1..$]; } } ` Prints: Other D Apostrophe smart ’ Other Addario Other ' I would have expected: Other D Apostrophe smart ’ Other Addario Apostrophe straight ' <== expected
Re: Best approach to handle accented letters
On Friday, 28 October 2016 at 14:31:47 UTC, Chris wrote: On Friday, 28 October 2016 at 13:50:24 UTC, Alfred Newman wrote: It boils down to something like: if (c in _accent) return _accent[c]; else return c; Just a normal lambda (condition true) ? yes : no; I'd recommend you to use Marc's approach, though. What you basically do is you pass the logic on to `map` and `map` applies it to each item in the range (cf. [1]): map!(myLogic)(range); or (more idiomatic) range.map!(myLogic); This is true of a lot of functions, or rather templates, in the Phobos standard library, especially functions in std.algorithm (like find [2], canFind, filter etc.). In this way, instead of writing for-loops with if-else statements, you pass the logic to be applied within the `!()`-part of the template. // Filter the letter 'l' auto result = "Hello, world!".filter!(a => a != 'l'); // returns "Heo, word!" However, what is returned is not a string. So this won't work: `writeln("Result is " ~ result);` // Error: incompatible types for (("Result is ") ~ (result)): 'string' and // 'FilterResult!(__lambda2, string)' It returns a `FilterResult`. To fix this, you can either write: ` import std.conv; auto result = "Hello, world!".filter!(a => a != 'l').to!string; ` which converts it into a string. or you do this: ` import std.array; auto result = "Hello, world!".filter!(a => a != 'l').array; ` Then you have a string again and ` writeln("Result is " ~ result); ` works. Just bear that in mind, because you will get the above error sometimes. Marc's example is idiomatic D and you should become familiar with it asap. void main() { auto str = "très élégant"; immutable accents = unicode.Diacritic; auto removed = str // normalize each character .normalize!NFD // replace each diacritic with its non-diacritic counterpart .filter!(c => !accents[c]) // convert each item in FilterResult back to string. .to!string; writeln(removed); // prints "tres elegant" } [1] http://dlang.org/phobos/std_algorithm_iteration.html#.map [1] http://dlang.org/phobos/std_algorithm_searching.html#.find
Re: Best approach to handle accented letters
On Friday, 28 October 2016 at 13:50:24 UTC, Alfred Newman wrote: On Friday, 28 October 2016 at 11:40:37 UTC, Chris wrote: [...] @Chris As a new guy in the D community, I am not sure, but I think the line below is something like a Python's lambda, right ? auto removed = to!string(str.map!(a => (a in _accent) ? _accent[a] : a)); Can you please rewrite the line in a more didatic way ? Sorry, but I'm still learning the basics. Thanks in advance It boils down to something like: if (c in _accent) return _accent[c]; else return c; Just a normal lambda (condition true) ? yes : no; I'd recommend you to use Marc's approach, though.
Re: Best approach to handle accented letters
On Friday, 28 October 2016 at 12:52:04 UTC, Marc Schütz wrote: On Friday, 28 October 2016 at 11:24:28 UTC, Alfred Newman wrote: [...] import std.stdio; import std.algorithm; import std.uni; import std.conv; void main() { auto str = "très élégant"; immutable accents = unicode.Diacritic; auto removed = str .normalize!NFD .filter!(c => !accents[c]) .to!string; writeln(removed); // prints "tres elegant" } This first decomposes all characters into base and diacritic, and then removes the latter. Cool. That looks pretty neat and it should cover all cases.
Re: Best approach to handle accented letters
On Friday, 28 October 2016 at 11:24:28 UTC, Alfred Newman wrote: Hello, I'm getting some troubles to replace the accented letters in a given string with their unaccented counterparts. Let's say I have the following input string "très élégant" and I need to create a function to return just "tres elegant". Considering we need to take care about unicode chars, what is the best way to write a D code to handle that ? Cheers You could try something like this. It works for accents. I haven't tested it on other characters yet. import std.stdio; import std.algorithm; import std.array; import std.conv; enum { dchar[dchar] _accent = ['á':'a', 'é':'e', 'è':'e', 'í':'i', 'ó':'o', 'ú':'u', 'Á':'A', 'É':'E', 'Í':'I', 'Ó':'O', 'Ú':'U'] } void main() { auto str = "très élégant"; auto removed = to!string(str.map!(a => (a in _accent) ? _accent[a] : a)); writeln(removed); // prints "tres elegant" }
Re: vibe.d HTMLLogger
On Wednesday, 12 October 2016 at 14:19:36 UTC, Chris wrote: The answer is that `HTMLLogger` needs to be given the time in the `LogLine` struct, else it fails. The time stamp is not auto generated. I completely overlooked that. Here's the culprit: cf. m_logFile.writef(`%s`, msg.time.toISOExtString()); https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/core/log.d#L363 I wonder, if the design of HTMLLogger couldn't be improved in this respect. It's not an obvious error.
Re: vibe.d HTMLLogger
On Wednesday, 12 October 2016 at 11:54:14 UTC, Chris wrote: Why does FileLogger work while HTMLLogger crashes on the same thing? I've had a look at the source code, but couldn't find anything. It happens with vibe.d `0.7.30-beta1` and `0.7.29` alike (haven't tested lower versions). [Test code] auto logLine = LogLine(); logLine.level = LogLevel.info; // Fine auto l = new FileLogger("log/logger_test.log"); l.minLevel = LogLevel.info; l.beginLine(logLine); l.put("Hello!"); l.endLine(); htmlLogger = new HTMLLogger("log/logger_test.html"); htmlLogger.minLevel = LogLevel.info; // crashes here (at `beginLine`), if removed it works. htmlLogger.beginLine(logLine); htmlLogger.put("Hello!"); htmlLogger.endLine(); The answer is that `HTMLLogger` needs to be given the time in the `LogLine` struct, else it fails. The time stamp is not auto generated. I completely overlooked that. Here's the culprit: cf. m_logFile.writef(`%s`, msg.time.toISOExtString()); https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/core/log.d#L363
vibe.d HTMLLogger
Why does FileLogger work while HTMLLogger crashes on the same thing? I've had a look at the source code, but couldn't find anything. It happens with vibe.d `0.7.30-beta1` and `0.7.29` alike (haven't tested lower versions). [Test code] auto logLine = LogLine(); logLine.level = LogLevel.info; // Fine auto l = new FileLogger("log/logger_test.log"); l.minLevel = LogLevel.info; l.beginLine(logLine); l.put("Hello!"); l.endLine(); htmlLogger = new HTMLLogger("log/logger_test.html"); htmlLogger.minLevel = LogLevel.info; // crashes here (at `beginLine`), if removed it works. htmlLogger.beginLine(logLine); htmlLogger.put("Hello!"); htmlLogger.endLine();
vibe.d Logger
Is this the preferred logging module for vibe.d: http://vibed.org/api/vibe.core.log/ There is also: http://vibed.org/api/vibe.http.log/ which is there for backwards compatibility?
Re: vibe.d maxRequestSize
On Monday, 19 September 2016 at 18:13:12 UTC, Chris wrote: On Monday, 19 September 2016 at 17:54:05 UTC, Steven Schveighoffer wrote: On 9/19/16 1:34 PM, Chris wrote: [...] Here is the culprit: https://github.com/rejectedsoftware/vibe.d/blob/0.7.29/source/vibe/http/server.d#L1861 And the definition of MaxHTTPHeaderLineLength is: https://github.com/rejectedsoftware/vibe.d/blob/0.7.29/source/vibe/http/server.d#L1861 4096 bytes. I'm not super-familiar with HTTP protocol requirements, but a further diagnosis of your net traffic may reveal that your browser is doing something unorthodox, or vibe needs to adjust here. -Steve Thanks a million! I'll look into it tomorrow. FYI, I had to solve the issue by sending a form via a JS XMLHTTPRequest. maxRequestSize didn't help.
Re: vibe.d maxRequestSize
On Monday, 19 September 2016 at 17:54:05 UTC, Steven Schveighoffer wrote: On 9/19/16 1:34 PM, Chris wrote: [...] Here is the culprit: https://github.com/rejectedsoftware/vibe.d/blob/0.7.29/source/vibe/http/server.d#L1861 And the definition of MaxHTTPHeaderLineLength is: https://github.com/rejectedsoftware/vibe.d/blob/0.7.29/source/vibe/http/server.d#L1861 4096 bytes. I'm not super-familiar with HTTP protocol requirements, but a further diagnosis of your net traffic may reveal that your browser is doing something unorthodox, or vibe needs to adjust here. -Steve Thanks a million! I'll look into it tomorrow.
Re: vibe.d maxRequestSize
On Monday, 19 September 2016 at 16:55:05 UTC, Steven Schveighoffer wrote: Hm... you don't get a full stack trace? Hard to tell what max_bytes should be, it defaults to ulong.max, so no way you are exhausting that. Without knowing where readUntilSmall is called, it's hard to diagnose. -Steve I didn't want to litter the thread, here it is: 400 - Bad Request Bad Request Internal error information: object.Exception@../../.dub/packages/vibe-d-0.7.29/vibe-d/source/vibe/stream/operations.d(349): Reached maximum number of bytes while searching for end marker. /home/chris/.dvm/compilers/dmd-2.071.1/linux/bin/../../src/phobos/std/exception.d:405 pure @safe void std.exception.bailOut!(Exception).bailOut(immutable(char)[], ulong, const(char[])) [0x8f11a7] /home/chris/.dvm/compilers/dmd-2.071.1/linux/bin/../../src/phobos/std/exception.d:363 pure @safe bool std.exception.enforce!(Exception, bool).enforce(bool, lazy const(char)[], immutable(char)[], ulong) [0x8f112a] ../../.dub/packages/vibe-d-0.7.29/vibe-d/source/vibe/stream/operations.d:348 void vibe.stream.operations.readUntilSmall!(vibe.utils.array.AllocAppender!(ubyte[], ubyte).AllocAppender).readUntilSmall(vibe.core.stream.InputStream, ref vibe.utils.array.AllocAppender!(ubyte[], ubyte).AllocAppender, const(ubyte[]), ulong) [0xb06b00] ../../.dub/packages/vibe-d-0.7.29/vibe-d/source/vibe/stream/operations.d:137 void vibe.stream.operations.readUntil!(vibe.utils.array.AllocAppender!(ubyte[], ubyte).AllocAppender).readUntil(vibe.core.stream.InputStream, ref vibe.utils.array.AllocAppender!(ubyte[], ubyte).AllocAppender, const(ubyte[]), ulong) [0xb06a1f] ../../.dub/packages/vibe-d-0.7.29/vibe-d/source/vibe/stream/operations.d:53 void vibe.stream.operations.readLine!(vibe.utils.array.AllocAppender!(ubyte[], ubyte).AllocAppender).readLine(vibe.core.stream.InputStream, ref vibe.utils.array.AllocAppender!(ubyte[], ubyte).AllocAppender, ulong, immutable(char)[]) [0xb069c8] ../../.dub/packages/vibe-d-0.7.29/vibe-d/source/vibe/stream/operations.d:39 ubyte[] vibe.stream.operations.readLine!().readLine(vibe.core.stream.InputStream, ulong, immutable(char)[], vibe.utils.memory.Allocator) [0xb06984] ../../.dub/packages/vibe-d-0.7.29/vibe-d/source/vibe/http/server.d:1861 void vibe.http.server.parseRequestHeader(vibe.http.server.HTTPServerRequest, vibe.core.stream.InputStream, vibe.utils.memory.Allocator, ulong) [0xb5e827] ../../.dub/packages/vibe-d-0.7.29/vibe-d/source/vibe/http/server.d:1659 bool vibe.http.server.handleRequest(vibe.core.stream.Stream, vibe.core.net.TCPConnection, vibe.http.server.HTTPListenInfo, ref vibe.http.server.HTTPServerSettings, ref bool) [0xb5c5d0] ../../.dub/packages/vibe-d-0.7.29/vibe-d/source/vibe/http/server.d:1552 void vibe.http.server.handleHTTPConnection(vibe.core.net.TCPConnection, vibe.http.server.HTTPListenInfo) [0xb5be4e] ../../.dub/packages/vibe-d-0.7.29/vibe-d/source/vibe/http/server.d:1433 void vibe.http.server.listenHTTPPlain(vibe.http.server.HTTPServerSettings).doListen(vibe.http.server.HTTPListenInfo, bool, bool).__lambda4(vibe.core.net.TCPConnection) [0xb5b814] ../../.dub/packages/vibe-d-0.7.29/vibe-d/source/vibe/core/drivers/libevent2_tcp.d:610 void vibe.core.drivers.libevent2_tcp.ClientTask.execute() [0xbe8715] ../../.dub/packages/vibe-d-0.7.29/vibe-d/source/vibe/core/core.d:488 void vibe.core.core.makeTaskFuncInfo!(void delegate()).makeTaskFuncInfo(ref void delegate()).callDelegate(vibe.core.core.TaskFuncInfo*) [0xafea75] ../../.dub/packages/vibe-d-0.7.29/vibe-d/source/vibe/core/core.d:1119 void vibe.core.core.CoreTask.run() [0xb8dd79] ??:? void core.thread.Fiber.run() [0xc70ea5] ??:? fiber_entryPoint [0xc70c27] ??:? [0x]
Re: vibe.d maxRequestSize
On Thursday, 15 September 2016 at 13:26:48 UTC, Steven Schveighoffer wrote: On 9/15/16 9:11 AM, Chris wrote: On Wednesday, 14 September 2016 at 20:23:09 UTC, Steven Schveighoffer wrote: Hm.. I have adjusted this in my project, and it works (set to 50M). Needed it for uploading large images. Using version 0.7.29 -Steve It doesn't seem to make any difference in my case. I wonder what could be wrong Seems to be in use: https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/http/server.d#L1832 -Steve Finally, I could find where it happens. If I use "get" in a HTML form (instead of "post"), vibe.d complains. I set the max request and request header size to 25MB. ` 400 - Bad Request Bad Request Internal error information: object.Exception@../../.dub/packages/vibe-d-0.7.29/vibe-d/source/vibe/stream/operations.d(349): Reached maximum number of bytes while searching for end marker. ` https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/stream/operations.d#L349
Re: std.algorithm.iteration.each requires opApply to have ref elements?
On Thursday, 15 September 2016 at 18:23:14 UTC, Q. Schroll wrote: Why does it do that? And seemingly it does not require it for opApply with more than two arguments. Here's what the comment says: https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d#L929 // opApply with >2 parameters. count the delegate args. // only works if it is not templated (otherwise we cannot count the args) void each(Iterable)(Iterable r) if (!isRangeIterable!Iterable && !isForeachIterable!Iterable && __traits(compiles, Parameters!(Parameters!(r.opApply { auto dg(Parameters!(Parameters!(r.opApply)) params) { pred(params); return 0; // tells opApply to continue iteration } r.opApply(&dg); } Usually, if you change elements while iterating, you need to `ref` them. If you leave out `ref` the following loop will finish after 'd'. If you put in `ref` you have an infinite loop. void main() { import std.stdio : writefln; auto arr = ['a', 'b', 'c', 'd']; foreach (ref i, c; arr) { if (c == 'c') { --i; writefln("index = %d", i); } } }
Re: vibe.d maxRequestSize
On Friday, 16 September 2016 at 00:35:25 UTC, sarn wrote: I hope this isn't too obvious, but I have to ask because it's such a common gotcha: Are you reverse proxying through a server like nginx by any chance? There are default request size limits there. (For nginx specifically, it's this one: https://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size) No. Atm I'm running the server locally on my machine (for development), so I access vibe.d directly. But later it will run on Apache, and query string size will inevitably be an issue.
Re: vibe.d maxRequestSize
On Thursday, 15 September 2016 at 13:26:48 UTC, Steven Schveighoffer wrote: On 9/15/16 9:11 AM, Chris wrote: On Wednesday, 14 September 2016 at 20:23:09 UTC, Steven Schveighoffer wrote: Hm.. I have adjusted this in my project, and it works (set to 50M). Needed it for uploading large images. Using version 0.7.29 -Steve It doesn't seem to make any difference in my case. I wonder what could be wrong Seems to be in use: https://github.com/rejectedsoftware/vibe.d/blob/master/source/vibe/http/server.d#L1832 -Steve Hm, maybe the browsers are limiting the the length of the query string themselves, although that shouldn't be an issue with POST. I can send very long strings, if I enable HTTPServerOption.parseFormBody, but then I can no longer parse the URI at the same time (as far as I know). The browser always sends `Content-Length: 0` in the request header, which doesn't affect vibe.d (short strings work).
Re: vibe.d maxRequestSize
On Wednesday, 14 September 2016 at 20:23:09 UTC, Steven Schveighoffer wrote: Hm.. I have adjusted this in my project, and it works (set to 50M). Needed it for uploading large images. Using version 0.7.29 -Steve It doesn't seem to make any difference in my case. I wonder what could be wrong
vibe.d maxRequestSize
The vibe.d server rejects `XMLHttpRequest`s that are too long (in the eyes of the server). In the docs it says "maxRequestSize ulong Maximum number of transferred bytes per request after which the connection is closed with [sic!]" However, when you go to http://vibed.org/api/vibe.http.server/HTTPServerSettings.maxRequestSize it says "Maximum number of transferred bytes per request after which the connection is closed with an error; not supported yet" "not supported yet" and I think it is not supported yet. Can I still change the server settings so that it accepts longer query strings? Atm, the server rejects strings that are > ~2,500 characters, which is not much.
Re: Linker error
On Friday, 10 June 2016 at 13:17:32 UTC, Steven Schveighoffer wrote: On 6/10/16 8:04 AM, Chris wrote: I get the error below with code like this: auto res = ['1', '2'].map!(a => a.to!string); dmd 2.071.0 What's wrong here? I import std.algorithm, std.range, std.array, std.conv in the module. (.data._D65TypeInfo_xC3std5range10interfaces18__T10InputRangeTiZ10InputRange6__initZ+0x10): undefined reference to `_D64TypeInfo_C3std5range10interfaces18__T10InputRangeTiZ10InputRange6__initZ' collect2: error: ld returned 1 exit status This linker error is saying it can't find a required typeinfo initializer for std.range.interfaces.InputRange (of some type, not an expert in demangling D symbols). Generally this happens when you compile against a third-party library file but don't link to it (I think that type of symbol is stored in the module info). Your posted code has nothing to do with this, so I'm not sure this is the exact line you are having trouble with. Your posted map line should not be invoking this error at all. Have you tried Vladimir's DustMite tool? It can automatically whittle down your code into a minimal test case. https://github.com/CyberShadow/DustMite/wiki -Steve I've got it now. I remembered that it is to do with passing -allinst to the compiler. You're right, it's not `map!` as such. It's the template instantiation. However, the problem only appeared when I started to use `map!`
Re: Linker error
On Friday, 10 June 2016 at 13:00:23 UTC, ketmar wrote: On Friday, 10 June 2016 at 12:52:05 UTC, Chris wrote: I use dub and `dvm use 2.071.0`. hm. sorry, i can't help you with this. straight "dmd test.d" is ok, so it's probably something with dub/dvm interaction... It doesn't compile with `dmd file1.d file2.d` either. I'll have to look into this. Weird.
Re: Linker error
On Friday, 10 June 2016 at 12:12:17 UTC, ketmar wrote: On Friday, 10 June 2016 at 12:04:50 UTC, Chris wrote: I get the error below with code like this: auto res = ['1', '2'].map!(a => a.to!string); dmd 2.071.0 What's wrong here? I import std.algorithm, std.range, std.array, std.conv in the module. (.data._D65TypeInfo_xC3std5range10interfaces18__T10InputRangeTiZ10InputRange6__initZ+0x10): undefined reference to `_D64TypeInfo_C3std5range10interfaces18__T10InputRangeTiZ10InputRange6__initZ' collect2: error: ld returned 1 exit status post the whole code and command line, please. it looks like you doing separate compilation, and forgot to put something to command line, or there is some conflict between installed compiler versions (for example, dmd and ldc, and one somehow is trying to use libphobos from another). The whole code would be too much. This, however compiles and links perfectly well: ` import std.algorithm; import std.conv : to; void main() { auto res = [1, 2, 3].map!(a => a.to!string); } ` I use dub and `dvm use 2.071.0`. The code compiled perfectly well until I used `map!` I have no clue what causes it. I even used `dub clean`
Linker error
I get the error below with code like this: auto res = ['1', '2'].map!(a => a.to!string); dmd 2.071.0 What's wrong here? I import std.algorithm, std.range, std.array, std.conv in the module. (.data._D65TypeInfo_xC3std5range10interfaces18__T10InputRangeTiZ10InputRange6__initZ+0x10): undefined reference to `_D64TypeInfo_C3std5range10interfaces18__T10InputRangeTiZ10InputRange6__initZ' collect2: error: ld returned 1 exit status
Re: What's wrong with my usage of std.algorithm.map in this code example?
On Wednesday, 25 May 2016 at 19:07:32 UTC, Era Scarecrow wrote: On Wednesday, 25 May 2016 at 13:27:28 UTC, Chris wrote: Why can the tuple be iterated with foreach, as in my quick fix, and indexed with tuple[0..], but is not accepted as a range? What are the differences? Is there a way to rangify a tuple? The tuple is identified/used at compile-time, as such it's a compiler primitive and not a range. Foreach in this case will unroll the loop regardless how it looks. So... test(Args...)(Args args) { ... foreach (const ref i; items) itemstrings ~= i.to!string; Will become: (const and ref are pointless in this example, unless the args are referenced) test(int arg1, int arg2, int arg3, int arg4) { ... itemstrings ~= arg1.to!string; itemstrings ~= arg2.to!string; itemstrings ~= arg3.to!string; itemstrings ~= arg4.to!string; Trying to use map on it was literally expanding the entire input to map. Ah, I didn't know that it was just unrolled. That makes sense, of course. [snip]
Re: What's wrong with my usage of std.algorithm.map in this code example?
On Wednesday, 25 May 2016 at 14:48:14 UTC, ag0aep6g wrote: On 05/25/2016 04:39 PM, Chris wrote: I see. Maybe it would be worth adding a wrapper to typecons.Tuple or std.range that helps to rangify tuples. std.range.only is that wrapper. Duh! Of course! :-) I cannot think of any use case right now. I never needed this and in the example that started this thread, it would keep the function from converting mixed tuples (cf. my example above). I'm not sure what you're saying here. Should the wrapper support tuples with different element types? Can't be a range then as a range has just one element type. I'm saying that for the above example something like std.range.only doesn't make sense, because the user might want to turn anything into string as in test(1, 2, "v", 4, 'c'); Mixed type tuples cannot be rangified, of course (and std.range.only takes care of that).
Re: What's wrong with my usage of std.algorithm.map in this code example?
On Wednesday, 25 May 2016 at 14:32:11 UTC, ag0aep6g wrote: On 05/25/2016 03:27 PM, Chris wrote: Why can the tuple be iterated with foreach, as in my quick fix, and indexed with tuple[0..], but is not accepted as a range? What are the differences? popFront doesn't make sense with a tuple (aka expression list). When you remove the first element of a tuple, you get another tuple of a different type, but popFront can't change the type of the range. In code: void main() { import std.meta: AliasSeq; AliasSeq!(int, int, int) tuple = AliasSeq!(1, 2, 3); tuple.popFront(); /* How would this be implemented? Would have to change tuple's type to AliasSeq!(int, int). */ } Is there a way to rangify a tuple? std.range.only: void main() { import std.meta: AliasSeq; import std.range: only; AliasSeq!(int, int, int) tuple = AliasSeq!(1, 2, 3); auto range = only(tuple); range.popFront(); /* ok */ } I see. Maybe it would be worth adding a wrapper to typecons.Tuple or std.range that helps to rangify tuples. I cannot think of any use case right now. I never needed this and in the example that started this thread, it would keep the function from converting mixed tuples (cf. my example above).
Re: What's wrong with my usage of std.algorithm.map in this code example?
On Wednesday, 25 May 2016 at 13:27:28 UTC, Chris wrote: On Wednesday, 25 May 2016 at 12:08:20 UTC, Steven Schveighoffer wrote: On 5/25/16 6:24 AM, pineapple wrote: On Tuesday, 24 May 2016 at 20:18:34 UTC, Steven Schveighoffer wrote: Slice assignment from range to array is not supported. In your example, I'm curious why the efforts to specify the type? I think it would work with just saying auto itemstrings = ... I still get an error if I use auto instead. OK, I see the other issue now. map takes a range, whereas you are giving it a tuple. -Steve Why can the tuple be iterated with foreach, as in my quick fix, and indexed with tuple[0..], but is not accepted as a range? What are the differences? Is there a way to rangify a tuple? I should add : a homogeneous tuple, e.g. Tuple!(int, int, int);
Re: What's wrong with my usage of std.algorithm.map in this code example?
On Wednesday, 25 May 2016 at 12:08:20 UTC, Steven Schveighoffer wrote: On 5/25/16 6:24 AM, pineapple wrote: On Tuesday, 24 May 2016 at 20:18:34 UTC, Steven Schveighoffer wrote: Slice assignment from range to array is not supported. In your example, I'm curious why the efforts to specify the type? I think it would work with just saying auto itemstrings = ... I still get an error if I use auto instead. OK, I see the other issue now. map takes a range, whereas you are giving it a tuple. -Steve Why can the tuple be iterated with foreach, as in my quick fix, and indexed with tuple[0..], but is not accepted as a range? What are the differences? Is there a way to rangify a tuple?
Re: What's wrong with my usage of std.algorithm.map in this code example?
On Wednesday, 25 May 2016 at 11:14:26 UTC, FreeSlave wrote: Works with 'only', 'array' and static array slicing. import std.algorithm : map; import std.range : only; import std.conv : to; import std.stdio : writeln; import std.string : join; import std.array : array; string test(Args...)(in Args items){ immutable string[items.length] itemstrings = map!(to!string)(only(items)).array; return join(itemstrings[], ", "); } unittest{ writeln(test(1, 2, 3, 4)); } Nice, but I think it doesn't work with varying types. writeln(test(1, 2, "v", 4, 'c'));
Re: What's wrong with my usage of std.algorithm.map in this code example?
On Wednesday, 25 May 2016 at 10:24:19 UTC, pineapple wrote: On Tuesday, 24 May 2016 at 20:18:34 UTC, Steven Schveighoffer wrote: Slice assignment from range to array is not supported. In your example, I'm curious why the efforts to specify the type? I think it would work with just saying auto itemstrings = ... -Steve I still get an error if I use auto instead. If you really need it, this works: import std.algorithm : map; import std.conv : to; import std.stdio : writeln; import std.string : join; string test(Args...)(in Args items) { writeln(items.stringof); string[] itemstrings; foreach (const ref i; items) itemstrings ~= i.to!string; // auto itemstrings = items.map!(a => a.to!string); return join(itemstrings, ", "); } unittest { writeln(test(1, 2, "v", 4, 'c')); } If you use map!(), you get this error: Error: template map_error.test!(int, int, string, int, char).test.map!((a) => a.to!string).map cannot deduce function from argument types !()(const(int), const(int), const(string), const(int), const(char)), candidates are: /home/christoph/.dvm/compilers/dmd-2.071.0/linux/bin/../../src/phobos/std/algorithm/iteration.d(450): map_error.test!(int, int, string, int, char).test.map!((a) => a.to!string).map(Range)(Range r) if (isInputRange!(Unqual!Range)) The argument types don't match, i.e. they are const(int) etc. instead of int. The arguments are passed as a tuple: cf. writeln(items.stringof); tuple(_param_0, _param_1, _param_2, _param_3, _param_4)
Re: DlangIDE Themes
On Thursday, 12 May 2016 at 15:29:17 UTC, Vadim Lopatin wrote: Hello, External themes support is planned. It is not a hard task. Btw, try to copy your resource files (res directory) to the same place dlangui executable (e.g. dlangide) is located. Resources from this directory must be accessible from application. The only problem should be list of themes in UI settings. AFAIR, resources from directory should have higher priority than embedded ones. So for testing, you can rename theme to standard name. Best regards, Vadim I've tried that too, but changes I make are ignored.
Re: static import (v2.071.0)
On Thursday, 12 May 2016 at 12:45:38 UTC, Steven Schveighoffer wrote: On 5/11/16 10:11 AM, Chris wrote: No. static import just defines what symbols are accessible in what contexts. The (likely) reason you are getting this is because you are importing a module with a selective import: import std.uni : foo; And then using: std.uni.bar(); What the compiler is saying is that the fully qualified names are no longer going to be imported with selective imports. In order to "fix" this, you do: import std.uni : foo; static import std.uni; Note that another option is: import std.uni : foo, bar; and then changing the fully qualified name to just bar. Or you could use renamed imports. See this article for some explanation: http://www.schveiguy.com/blog/2016/03/import-changes-in-d-2-071/ -Steve Thanks for clarifying this. Indeed, I had a mixture of FQN and selective imports. This is due to things like std.uni.foo(); being in parts of older code and import std.uni : bar; So I would have bar() and std.uni.foo() in the same module and stuff like that. I've fixed it now, but I will have to revise things and see what's the best import strategy for each case (based on the newly gained insights).
Re: DlangIDE Themes
On Thursday, 12 May 2016 at 09:51:18 UTC, thedeemon wrote: On Thursday, 12 May 2016 at 09:17:24 UTC, Chris wrote: They shouldn't be hardwired. Best would be to load them dynamically with their respective names encoded in the xml file. In this way people could add their own themes as they see fit. I wouldn't mind creating themes and adding them to DlangIDE as a humble contribution. Don't forget that contents of all those files in resources.list is also "hardwired" into the executable, so there's not much difference between mentioning something in such list file and in the source code. Of course, dynamic loading would be a nice thing to do, in addition to what there is now. Sure, but changing `resources.list` is trivial and can be added to the docs like so "Add the path to your theme file to `resources.list` and restart DlangIDE." It has to be hardwired somewhere, but it shouldn't be the themes. Other editors/IDE's allow you to load your own themes. This is important, because apart from aesthetics, some people might find certain themes easier on the eye than others, e.g. color blind people or people with some sort of visual impairment.
Re: DlangIDE Themes
On Thursday, 12 May 2016 at 03:01:02 UTC, thedeemon wrote: On Wednesday, 11 May 2016 at 12:55:13 UTC, Chris wrote: Is there a way I can add my own themes? I've created a theme file and added it to views/resources.list However, it doesn't show up. "Default" and "Dark" seem to be hardwired somewhere in the source code. Indeed they are, just grep for "ide_theme_dark" and you'll find those two places (settings.d, idesettings.d). They shouldn't be hardwired. Best would be to load them dynamically with their respective names encoded in the xml file. In this way people could add their own themes as they see fit. I wouldn't mind creating themes and adding them to DlangIDE as a humble contribution.
Re: static import (v2.071.0)
On Wednesday, 11 May 2016 at 14:28:00 UTC, Vladimir Panteleev wrote: On Wednesday, 11 May 2016 at 14:26:37 UTC, Vladimir Panteleev wrote: To elaborate - this doesn't imply that the code of everything in that module will always be placed in the executable. The exact details depend on the implementation and configuration (see e.g. GCC's -ffunction-sections). I've updated the code now, but it takes some getting used to. Two questions: 1. Is it ok to have static imports locally or should they be on module level? class Bla { static import std.stdio; // ... std.stdio.writeln("import/export"); } 2. I still get a warning for calling a struct's member method. Why? E.g. struct Bla { public bool isBla(string str) { // ... return true; } } auto bla = Bla(); if (bla.isBla("string")) { // ... } Bla.isBla is not visible from module xyz. isBla is also defined somewhere else, but a member function of a locally allocated struct should not be confused with something like `std.uni.isBla`? Or should it?
Re: static import (v2.071.0)
On Wednesday, 11 May 2016 at 14:34:15 UTC, Edwin van Leeuwen wrote: On Wednesday, 11 May 2016 at 14:24:03 UTC, Chris wrote: I was wondering if `static import std.file;` `if (exists(file))` will only import `std.file.exists` or the whole lot of `std.file`? I want to find out what the best strategy for imports is now. I tend to do specified imports, although (AFAIK) it doesn't make a difference for the imported code: private import std.file : exists; if (exists(file)) Me too.
Re: static import (v2.071.0)
On Wednesday, 11 May 2016 at 14:28:00 UTC, Vladimir Panteleev wrote: On Wednesday, 11 May 2016 at 14:26:37 UTC, Vladimir Panteleev wrote: On Wednesday, 11 May 2016 at 14:24:03 UTC, Chris wrote: I was wondering if `static import std.file;` `if (exists(file))` will only import `std.file.exists` or the whole lot of `std.file`? I want to find out what the best strategy for imports is now. Modules are always imported wholesale as far as code generation / linking is concerned. To elaborate - this doesn't imply that the code of everything in that module will always be placed in the executable. The exact details depend on the implementation and configuration (see e.g. GCC's -ffunction-sections). Hm. What's the point then of using import std.string : strip; as opposed to static import std.string; std.string.strip();
Re: static import (v2.071.0)
On Wednesday, 11 May 2016 at 14:18:16 UTC, Vladimir Panteleev wrote: On Wednesday, 11 May 2016 at 14:11:46 UTC, Chris wrote: I'm updating my code to 2.071.0 at the moment. Naturally, I get a lot of warnings like `module std.uni is not accessible here, perhaps add 'static import std.uni;'` Will `static import` bloat my exe or simply access the members I use? It should have no effect on generated code. The warning is to inform you that your code relied on buggy behavior which will be removed in future versions, but still currently compiles as before. Adding the static import will simply fix the reliance on the buggy behavior. I was wondering if `static import std.file;` `if (exists(file))` will only import `std.file.exists` or the whole lot of `std.file`? I want to find out what the best strategy for imports is now.
static import (v2.071.0)
I'm updating my code to 2.071.0 at the moment. Naturally, I get a lot of warnings like `module std.uni is not accessible here, perhaps add 'static import std.uni;'` Will `static import` bloat my exe or simply access the members I use?
DlangIDE Themes
Is there a way I can add my own themes? I've created a theme file and added it to views/resources.list However, it doesn't show up. "Default" and "Dark" seem to be hardwired somewhere in the source code.
Re: Linker error for d.o: relocation R_X86_64_32 against `__dmd_personality_v0'
On Friday, 22 April 2016 at 09:49:02 UTC, Rene Zwanenburg wrote: On Thursday, 21 April 2016 at 16:29:14 UTC, rcorre wrote: - What happens when you compile a binary without phobos and druntime, and with a custom entry point? I've never done that myself and don't remember how to do that off the top of my head, but the info should be somewhere on dlang.org. I'll look into it. Declaring a C-like main and the -defaultlib switch do the trick: cmain.d extern(C) void main() nothrow {} --- dmd cmain.d -defaultlib="" If even that fails to link I honestly wouldn't know where to look next.. This seems odd. Have you tried to reinstall dmd? You could use dvm [1] to install different versions of dmd and see what happens. It seems as if there's something wrong with your installation. I have Ubuntu at work and ArchLinux at home. It works fine, there shouldn't be any problem with compiling your program. [1] https://github.com/jacob-carlborg/dvm
Re: Linker error for d.o: relocation R_X86_64_32 against `__dmd_personality_v0'
On Thursday, 21 April 2016 at 01:20:27 UTC, rcorre wrote: s/compile/link I _can_ compile a D library, but as soon as I try to link anything compiled with DMD it falls over. Sorry, I didn't see the code in your first post. I tried it myself (in only have 2.070.2) and it worked fine. Have you had a look at https://dlang.org/dll-linux.html
Re: Linker error for d.o: relocation R_X86_64_32 against `__dmd_personality_v0'
On Wednesday, 20 April 2016 at 12:04:45 UTC, rcorre wrote: === $ dmd /tmp/d.d /usr/bin/ld: d.o: relocation R_X86_64_32 against `__dmd_personality_v0' can not be used when making a shared object; recompile with -fPIC d.o: error adding symbols: Bad value collect2: error: ld returned 1 exit status --- errorlevel 1 === I'm seeing the above trying to compile a simple d program. /tmp/d.d: === void main() { } === Any idea what this might be? I'm on dmd 2.071.0 on Archlinux. I had a similar error. Could you show us the code? Do you refer/link to a dynamic library?
Re: DWT Cloning / Build fails
On Thursday, 14 April 2016 at 19:16:30 UTC, Jacob Carlborg wrote: On 2016-04-14 15:56, Chris wrote: I had to add ".a" to `-L-l:dwt-base` and `-L-l:org.eclipse.swt.gtk.linux.x86`, and add `-L-lgnomevfs-2` as well. I added `-L-lgnomevfs-2 to the example. I need to look into way the ".a" was needed. Yeah, it's strange alright. I was surprised that I had to add it.
Re: DWT Cloning / Build fails
For the record, on my Linux (Ubuntu 15), I had to tweak the command for the example: dmd main.d -I/imp -J/org.eclipse.swt.gtk.linux.x86/res -L-L/lib \ -L-l:org.eclipse.swt.gtk.linux.x86.a \ -L-l:dwt-base.a -L-lgtk-x11-2.0 -L-lgdk-x11-2.0 -L-latk-1.0 -L-lgdk_pixbuf-2.0 \ -L-lgthread-2.0 -L-lpangocairo-1.0 -L-lfontconfig -L-lXtst -L-lXext -L-lXrender \ -L-lXinerama -L-lXi -L-lXrandr -L-lXcursor -L-lXcomposite -L-lXdamage -L-lX11 \ -L-lXfixes -L-lpango-1.0 -L-lgobject-2.0 -L-lgmodule-2.0 -L-lgnomevfs-2 -L-ldl -L-lglib-2.0 \ -L-lcairo -L-lgnomeui-2 I had to add ".a" to `-L-l:dwt-base` and `-L-l:org.eclipse.swt.gtk.linux.x86`, and add `-L-lgnomevfs-2` as well.
Re: DWT Cloning / Build fails
On Wednesday, 13 April 2016 at 18:50:22 UTC, Jacob Carlborg wrote: On 2016-04-13 17:23, Jesse Phillips wrote: Looks like your firewall is blocking the git protocol. Checkout dwt without --recursive Modify the .gitmodules file so that https:// urls are used instead of git Run the git submodule update --init Updated to use HTTPS for the submodules. Thanks! It worked for me now, both cloning and building. I'm looking forward to testing it.
Re: Dynamic library
On Tuesday, 12 April 2016 at 10:11:27 UTC, Russel Winder wrote: Did you solve this problem? Does it go away using a newer JDK, e.g. 8_77? Have you tried the Oracle or Azul builds? If you have a small project you can send me that exhibits the problem for you, I can take a look at it. I could get it to work with 8_77. However, I get this message ("12" is the result I want): - 12 pure virtual method called terminate called without an active exception Aborted (core dumped) - As soon as I use any phobos relates stuff in the module, I get this error (libpthread.so is the issue): # JRE version: Java(TM) SE Runtime Environment (8.0_77-b03) (build 1.8.0_77-b03) # Java VM: Java HotSpot(TM) 64-Bit Server VM (25.77-b03 mixed mode linux-amd64 compressed oops) # Problematic frame: # C [libpthread.so.0+0x9c84] pthread_mutex_lock+0x4 I wonder is it a bug in Java?
Re: DWT Cloning / Build fails
On Tuesday, 12 April 2016 at 19:20:44 UTC, Jacob Carlborg wrote: The error messages are below. If I do it step by step (without --recursive) and then "git submodule update --init", I get more or less the same error: Cloning into 'base'... fatal: unable to connect to github.com: github.com[0: 192.30.252.130]: errno=Connection refused I use `git 2.5.0` There's always something with github, isn't there? On 2016-04-12 17:32, Chris wrote: This doesn't work: $ git clone --recursive git://github.com/d-widget-toolkit/dwt.git Error: git clone --recursive git://github.com/d-widget-toolkit/dwt.git Cloning into 'dwt'... fatal: unable to connect to github.com: github.com[0: 192.30.252.123]: errno=Connection refused $ git clone --recursive https://github.com/d-widget-toolkit/dwt.git Cloning into 'dwt'... remote: Counting objects: 119, done. remote: Total 119 (delta 0), reused 0 (delta 0), pack-reused 119 Receiving objects: 100% (119/119), 75.20 KiB | 0 bytes/s, done. Resolving deltas: 100% (54/54), done. Checking connectivity... done. Submodule 'base' (git://github.com/d-widget-toolkit/base.git) registered for path 'base' Submodule 'org.eclipse.swt.gtk.linux.x86' (git://github.com/d-widget-toolkit/org.eclipse.swt.gtk.linux.x86.git) registered for path 'org.eclipse.swt.gtk.linux.x86' Submodule 'org.eclipse.swt.snippets' (git://github.com/d-widget-toolkit/org.eclipse.swt.snippets.git) registered for path 'org.eclipse.swt.snippets' Submodule 'org.eclipse.swt.win32.win32.x86' (git://github.com/d-widget-toolkit/org.eclipse.swt.win32.win32.x86.git) registered for path 'org.eclipse.swt.win32.win32.x86' Cloning into 'base'... fatal: unable to connect to github.com: github.com[0: 192.30.252.123]: errno=Connection refused
Re: Dynamic library
On Tuesday, 12 April 2016 at 10:11:27 UTC, Russel Winder wrote: On Mon, 2016-04-11 at 14:15 +, Chris via Digitalmars-d-learn wrote: I wanted to test, if I could use D with JNA (Java Native Access). I get this error message: # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x7fd24ab66074, pid=15733, tid=140541714827008 # # JRE version: OpenJDK Runtime Environment (8.0_66-b17) (build 1.8.0_66-internal-b17) # Java VM: OpenJDK 64-Bit Server VM (25.66-b17 mixed mode linux-amd64 compressed oops) # Problematic frame: # C [libphobos2.so.0.69+0x467074] _d_dso_registry+0x59c libphobos is a "problematic frame". Did you solve this problem? Does it go away using a newer JDK, e.g. 8_77? Have you tried the Oracle or Azul builds? If you have a small project you can send me that exhibits the problem for you, I can take a look at it. I haven't solved the problem yet. I'll try 8_77, if I can get it for Ubuntu (which I use at work). It is not even a project yet, just a "Hello, world!" kind of test. I guess I got it wrong somehow when I compiled / linked the D .so file. I'll have another look and if I cannot get it to work I'll send you the files. Thanks for the offer.
Re: djvm fails to build
On Tuesday, 12 April 2016 at 15:54:10 UTC, rikki cattermole wrote: I'll look into it tomorrow, but I suspect I'm gonna need to do some serious work to get it work with the new import rules. Also maybe best to take this to gitter[0] or github issue so that I get an alert. [0] https://gitter.im/rikkimax/chatWithMe Ok. I think some Java interop would be great (both ways). It's a widely used language after all and with the advent of Java 8 it looks like it's becoming usable again. Java has lambdas and Streams now: "The Stream interface supports the map/filter/reduce pattern and executes lazily, forming the basis (along with lambdas) for functional-style programming in Java 8." [1] Sounds familiar to a D programmer. Funny how OOP ideology has finally made concessions to more pragmatic / flexible approaches. [1] https://leanpub.com/whatsnewinjava8/read#leanpub-auto-streams
DWT Cloning / Build fails
This doesn't work: $ git clone --recursive git://github.com/d-widget-toolkit/dwt.git $ git clone --recursive https://github.com/d-widget-toolkit/dwt.git (cf. https://github.com/d-widget-toolkit/dwt) If I just download the master or clone without `--recursive`, files are missing and I cannot compile it. Does anyone know what I'm doing wrong?
djvm fails to build
@Rikki I can't get djvm to build (dmd 2.069.1 and higher) https://github.com/rikkimax/djvm [Error Message] Performing "debug" build using dmd for x86_64. djvm ~master: building configuration "library"... String (Constructor!string, Constructor!(), Method!(char, "charAt", int), Method!(string, "concat", string), StaticMethod!(string, "valueOf", bool)) source/wrappers/djvm/bind/helpers.d(17,38): Error: type string has no value source/wrappers/djvm/bind/generator.d-mixin-246(246,1): Error: template instance djvm.bind.helpers.getJavaMethodSignature!(void, string) error instantiating source/wrappers/djvm/bind/generator.d(41,3):instantiated from here: parseDefinition!(Constructor!string, false) source/wrappers/djvm/bind/defs.d(42,46):instantiated from here: generateJavaClass!("String", Constructor!string, Constructor!(), Method!(char, "charAt", int), Method!(string, "concat", string), StaticMethod!(string, "valueOf", bool)) source/wrappers/djvm/bind/generator.d-mixin-246(246,1): Error: CTFE failed because of previous errors in getJavaMethodSignature source/wrappers/djvm/bind/helpers.d(17,38): Error: type int has no value source/wrappers/djvm/bind/generator.d-mixin-161(161,84): Error: template instance djvm.bind.helpers.getJavaMethodSignature!(char, int) error instantiating source/wrappers/djvm/bind/generator.d(41,3):instantiated from here: parseDefinition!(Method!(char, "charAt", int), false) source/wrappers/djvm/bind/defs.d(42,46):instantiated from here: generateJavaClass!("String", Constructor!string, Constructor!(), Method!(char, "charAt", int), Method!(string, "concat", string), StaticMethod!(string, "valueOf", bool)) source/wrappers/djvm/bind/generator.d-mixin-161(161,84): Error: CTFE failed because of previous errors in getJavaMethodSignature source/wrappers/djvm/bind/helpers.d(17,38): Error: type string has no value source/wrappers/djvm/bind/generator.d-mixin-161(161,84): Error: template instance djvm.bind.helpers.getJavaMethodSignature!(string, string) error instantiating source/wrappers/djvm/bind/generator.d(41,3):instantiated from here: parseDefinition!(Method!(string, "concat", string), false) source/wrappers/djvm/bind/defs.d(42,46):instantiated from here: generateJavaClass!("String", Constructor!string, Constructor!(), Method!(char, "charAt", int), Method!(string, "concat", string), StaticMethod!(string, "valueOf", bool)) source/wrappers/djvm/bind/generator.d-mixin-161(161,84): Error: CTFE failed because of previous errors in getJavaMethodSignature source/wrappers/djvm/bind/helpers.d(17,38): Error: type bool has no value source/wrappers/djvm/bind/generator.d-mixin-161(161,84): Error: template instance djvm.bind.helpers.getJavaMethodSignature!(string, bool) error instantiating source/wrappers/djvm/bind/generator.d(41,3):instantiated from here: parseDefinition!(StaticMethod!(string, "valueOf", bool), false) source/wrappers/djvm/bind/defs.d(42,46):instantiated from here: generateJavaClass!("String", Constructor!string, Constructor!(), Method!(char, "charAt", int), Method!(string, "concat", string), StaticMethod!(string, "valueOf", bool)) source/wrappers/djvm/bind/generator.d-mixin-161(161,84): Error: CTFE failed because of previous errors in getJavaMethodSignature source/wrappers/djvm/bind/defs.d(42,46): Error: CTFE failed because of previous errors in generateJavaClass source/wrappers/djvm/bind/defs.d(42,2):while evaluating pragma(msg, generateJavaClass("java.lang")) source/wrappers/djvm/bind/defs.d(43,40): Error: CTFE failed because of previous errors in generateJavaClass source/wrappers/djvm/bind/defs.d(43,40): Error: argument to mixin must be a string, not (generateJavaClass("java.lang")) of type string source/wrappers/java/lang/String.d(4,1): Error: mixin java.lang.String.JavaClass!("String", "java.lang", Constructor!string, Constructor!(), Method!(char, "charAt", int), Method!(string, "concat", string), StaticMethod!(string, "valueOf", bool)) error instantiating dmd failed with exit code 1.
Re: Dynamic library
I wanted to test, if I could use D with JNA (Java Native Access). I get this error message: # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x7fd24ab66074, pid=15733, tid=140541714827008 # # JRE version: OpenJDK Runtime Environment (8.0_66-b17) (build 1.8.0_66-internal-b17) # Java VM: OpenJDK 64-Bit Server VM (25.66-b17 mixed mode linux-amd64 compressed oops) # Problematic frame: # C [libphobos2.so.0.69+0x467074] _d_dso_registry+0x59c libphobos is a "problematic frame".
Re: Dynamic library
On Monday, 11 April 2016 at 13:45:42 UTC, Adam D. Ruppe wrote: On Monday, 11 April 2016 at 13:40:14 UTC, Chris wrote: For the record, I fixed it by changing the contents of libphobos2.so from How did you do that btw? The file there should really just be a link to some binary file, maybe it got mangled in copying at some point. Turns out that it was due to dvm (the D version manager). Somehow the libraries (in linux/lib64/) are not unzipped properly when dvm installs a version of D/dmd. I unzipped them manually and now it works without changing "libphobos2.so" as it is now recognizes as a "link to libphobos2.so.0.xx.x". In the dvm installation libphobos2.so is recognized as "shared library" while it is only a line of text (interpreted as linker script).
Re: Dynamic library
On Monday, 11 April 2016 at 11:42:22 UTC, Chris wrote: I followed these steps: https://dlang.org/dll-linux.html#dso7 What I get is this error: libphobos2.so: file format not recognized; treating as linker script I don't know why it is not recognized. Any ideas? For the record, I fixed it by changing the contents of libphobos2.so from libphobos2.so.069.2 [or whatever] to GROUP (libphobos2.so.0.69.2)
Dynamic library
I followed these steps: https://dlang.org/dll-linux.html#dso7 What I get is this error: libphobos2.so: file format not recognized; treating as linker script I don't know why it is not recognized. Any ideas?
Re: C.h to D conversion (structs)
On Tuesday, 15 March 2016 at 18:47:22 UTC, Adam D. Ruppe wrote: Like you would another D library. Now I get it! Yes, that works as expected. The problem isn't the struct itself, but the D initializer. Structs in C don't have initalizers but do in D: struct Foo { int a = 10; /* illegal in C, legal in D */ }; Note that extern(C) doesn't actually do anything on a struct, it really only applies to functions and global variables. That's where I got it wrong! D realizes this by creating a variable called _DStructName__init which has the initial value of the struct. When you make a variable of that type, it copies the value of this hidden init thing over to your new variable to initialize it. C does nothing of the sort, so the C library will not provide this - you need to link in the one from D. You might be thinking "but I don't use = anything in this struct", but there's a few places where D will put one in automatically: float and double = NaN by default char, wchar, and dchar = -1 (well, 0xff) by default And everything else =0 (or null) by default. If *everything* in a struct is initialized to 0, the __init variable is left out and memset(&struct, struct.sizeof, 0) is called instead. But if *anything* in there is non-zero, the __init variable is created and referenced when you declare the variable (unless you =void it at the usage point). Which causes the undefined reference problem you're seeing - the usage code is trying to initialize, but the C library doesn't provide that (since it isn't a C feature) and the D library isn't linked in. Thanks a million! Now I understand why it didn't work with my implementation. [snip]
Re: C.h to D conversion (structs)
On Tuesday, 15 March 2016 at 17:10:03 UTC, Adam D. Ruppe wrote: On Tuesday, 15 March 2016 at 16:56:00 UTC, Chris wrote: Do you mean I need to void initialize them in the C code or in D? And if in D, how would I do that, with `static this`? in D, at the usage point with =void where you declare the variable of that type. So in your code: struct C { A a = void; B b = void; } though I'm pretty sure it wouldn't matter in this specific instance because they would be all zeroes anyway... your real code probably has a char or a float in it, right? I do not recommend trying that though, it is better to actually compile+link in the modules. I'm not 100% sure what you mean with compile+link in the modules. The structs are all defined in the original (third party) C header file. It's nothing I added (in which case I would have to recompile the C library). The C structs in the C library should be visible to the linker, shouldn't they? Just as when you define: extern (C): size_t strlen(const char *str); and the linker will find it automatically. The error I get is as if the structs were not defined (or as if the lib weren't linked to).
Re: C.h to D conversion (structs)
On Tuesday, 15 March 2016 at 16:44:10 UTC, Adam D. Ruppe wrote: On Tuesday, 15 March 2016 at 16:32:56 UTC, Chris wrote: The error I get is something like undefined reference to `_D3test7testmodule13A6__initZ' undefined reference to `_D3test7testmodule13B6__initZ' You still need to compile/link in the module (or in this specific case, void initialize the structs) so any little functions or initializers are present. In C, structs need to be initialized manually, but in D they are automatically set to some initial value for each field. That initial value is the referenced __init symbol and still comes out of the .o file, like a function would. Do you mean I need to void initialize them in the C code or in D? And if in D, how would I do that, with `static this`?
C.h to D conversion (structs)
I've converted a C.h file to D according to this guide: http://wiki.dlang.org/Converting_C_.h_Files_to_D_Modules and examples in deimos: https://github.com/D-Programming-Deimos/ However, I get an error when trying to use a struct that uses structs. struct A { size_t i; } struct B { size_t x; } struct C { A a; B b; } The error I get is something like undefined reference to `_D3test7testmodule13A6__initZ' undefined reference to `_D3test7testmodule13B6__initZ' // The C header would look like this: typedef struct _A { size_t i; } A; typedef struct _B { size_t x; } B; typedef struct _C { A a; B b; } C; Also, what do I do with C structs that contain the following: typedef struct _A { struct _A *next; struct _A *prev; } A; Thanks.
Re: Assoc Array for Concurrency
On Monday, 29 February 2016 at 17:38:11 UTC, ZombineDev wrote: On Monday, 29 February 2016 at 12:43:39 UTC, Chris wrote: [...] I'm almost sure that built-in AAs don't provide automatic synchronization (in my tests I hit a deadlock), but you can easily wrap the AA into a struct that does the necessary synchronization. However be aware that even then you are not going to be safe, because more than one thread can try to access the keys or the values of the AA. Also note that because the built-in AAs rely on the GC, you may get poor scaling because every memory allocation can potentially take the global GC lock, which will block all threads from doing any work. So do your own tests and if you find the need to improve the performance, I would suggest investigating replacing the built-in AA with (for example) the hashmap from https://github.com/economicmodeling/containers in combination with a thread-local allocator. Here's an example of how to wrap an AA into a moderately safe accessor. In the following example I create an additional thread which concurrently adds odd numbers into the AA, while the main threads add even nubmers: http://dpaste.dzfl.pl/06025e6374eb It segfaults on DPaste because you can't create threads there, however it works ok on my machine. The output look like this: "0" : 0.140450140112896 "1" : 1.140450129700608 "2" : 2.140450140112896 "3" : 3.140450129700608 "4" : 4.140450140112896 "5" : 5.140450129700608 "6" : 6.140450140112896 "7" : 7.140450129700608 ... Thanks a million. In my case, I would no longer manipulate the assoc array after creating and filling it. It would be read only (sorry, if I didn't make that clear in my initial post). If I did manipulate it, however, I would either opt for something like https://github.com/economicmodeling/containers or opt for a different solution altogether.
Assoc Array for Concurrency
What's the best way to make an assoc array fit for multi-threading? If this is not possible what would be the best alternative? Say, for example, `data` is used by a class that is globally accessible to all threads. E.g. like this: string[string] data; // defined somewhere public string getData(string key) { if (key in data) return data[key]; else return ""; }
Re: What's wrong with my debugger?
On Thursday, 24 December 2015 at 09:30:24 UTC, Rainer Schuetze wrote: In the locals window, mago displays all instances of variables, but with the same value (which might be some uninitialized value of a different declaration than expected). The Visual Studio debug engine shows different values, though. Hi, thanks for the reply but not actually, no, if I change the debug engine to VS and rebuild I get the same behaviour.
What's wrong with my debugger?
Please see the linked screenshot: http://i.imgur.com/SpkXu5m.png As you can see, the inside, outside and collision arrays don't seem to work with the debugger. They show a bogus lenght and a bogus memory address. Extracting the lenghts to separate variables outl, insl and coll show that the arrays actually behave properly, though. Is that a debugger bug? Or maybe something I can fix? Thanks in advance. DMD 2.069.2, Mago debugger, VisualD 3.43, compiling for 32 bits if that makes a difference (can't get either 64 bit compilation or LDC to work)
Re: Invalid foreach aggregate
On Tuesday, 17 November 2015 at 13:49:58 UTC, Marc Schütz wrote: On Tuesday, 17 November 2015 at 12:41:45 UTC, Chris wrote: On Tuesday, 17 November 2015 at 12:22:22 UTC, Marc Schütz wrote: In any case, I'd suggest you fix your opIndex(), except if there's a really good reason it is as it is. I see. Thanks for the explanation. What would be the easiest fix for this example? Do you actually need the opIndex()? If not, just remove it. I suppose that would be the easiest solution. I think I doesn't really need to be as it is.
Re: Invalid foreach aggregate
On Tuesday, 17 November 2015 at 12:22:22 UTC, Marc Schütz wrote: Ok, that's a strange implementation of opIndex(). Usually, a parameter-less opIndex() is supposed to return a slice into the full range, but yours returns a size_t, which of course can't be iterated over. The change that made this stop working is: https://github.com/D-Programming-Language/dmd/pull/4948 This contains, among others a fix for issue 14625 "opIndex() doesn't work on foreach container iteration": https://issues.dlang.org/show_bug.cgi?id=14625 This allows to iterate directly over containers, without needing to slice them first. I guess it's a bit too eager, because if the object is already iterable without slicing (as in your example), it could just do that. On the other hand, it's a corner case, and it might actually be preferable to slice always, if the iterable supports it... In any case, I'd suggest you fix your opIndex(), except if there's a really good reason it is as it is. I see. Thanks for the explanation. What would be the easiest fix for this example?
Re: Invalid foreach aggregate
On Tuesday, 17 November 2015 at 11:58:22 UTC, Chris wrote: Sorry that should be: @property void popFront() { r = r[1..$]; cnt++; }
Re: Invalid foreach aggregate
On Tuesday, 17 November 2015 at 11:26:19 UTC, Marc Schütz wrote: That really depends on the details, that's why I asked. It could be a regression, or it could be that the compiler now does stricter checking than before, and your implementation wasn't completely correct, or it could be a bug in Phobos if you use that to create the range. If you can post a minimal example that works in 2.067.1, but doesn't with the current version, I can try to find the change that broke it. I did just that and I could find the culprit. It's opIndex(). It works up until 2.068.0, with 2.068.1 I already get this error: "primitives.d(7): Error: invalid foreach aggregate doSomething(items).opIndex()" Here's the example: = import std.stdio : writeln; import std.range.primitives; void main() { string[] items = ["a", "b", "c"]; foreach (ref it; items.doSomething()) { writeln(it); } } auto doSomething(InputRange)(ref InputRange r) { struct DoSomething { private { InputRange r; size_t cnt; } this(InputRange r) { this.r = r; } @property bool empty() { return r.length == 0; } @property auto front() { return r[0]; } @property void popFront() { r = r[1..$]; } @property size_t length() const { return r.length; } @property size_t opIndex() { return cnt; } @property auto save() const { return this; } } return DoSomething(r); }
Re: Invalid foreach aggregate
I've checked several options now and it doesn't work. Here (http://dlang.org/statement.html#foreach-with-ranges) it is stated that it suffices to have range primitives, if opApply doesn't exist. My code worked up to 2.068.0, with the introduction of 2.068.1 it failed. I wonder why that is. I have empty, front and popFront in my range which is a struct, and it used to work.
Re: Invalid foreach aggregate
On Monday, 16 November 2015 at 17:57:53 UTC, opla wrote: On Monday, 16 November 2015 at 16:55:29 UTC, Chris wrote: On Monday, 16 November 2015 at 16:49:19 UTC, Marc Schütz wrote: On Monday, 16 November 2015 at 16:44:27 UTC, Chris wrote: Updating my code from 2.067.1 to 2.069.1 (I skipped 2.068, because I was too busy). I get this error: invalid foreach aggregate, define opApply(), range primitives, or use .tupleof for code like foreach (ref it; myArray.doSomething) {} Probably not the best idea anyway. What's the best fix for this? Thanks. Well, what does `doSomething` return? It returns a range that modifies individual items in myArray, i.e. it assigns values to fields in each item of the array. have you... tried without ref tried by adding a pair of parens after doSomething ? tried std.algorithm.each or map on doSomething ? checked the primitives ? checked that isInputRange!(ReturnType!doSomething) == true? I think ref is necessary, else the items are not changed. I will try the other options tomorrow (Tuesday). Thanks. I wonder was the change overdue (and I got away with it till 2.068.1) or is it a new policy due to changes in D?
Re: Invalid foreach aggregate
On Monday, 16 November 2015 at 16:49:19 UTC, Marc Schütz wrote: On Monday, 16 November 2015 at 16:44:27 UTC, Chris wrote: Updating my code from 2.067.1 to 2.069.1 (I skipped 2.068, because I was too busy). I get this error: invalid foreach aggregate, define opApply(), range primitives, or use .tupleof for code like foreach (ref it; myArray.doSomething) {} Probably not the best idea anyway. What's the best fix for this? Thanks. Well, what does `doSomething` return? It returns a range that modifies individual items in myArray, i.e. it assigns values to fields in each item of the array.
Invalid foreach aggregate
Updating my code from 2.067.1 to 2.069.1 (I skipped 2.068, because I was too busy). I get this error: invalid foreach aggregate, define opApply(), range primitives, or use .tupleof for code like foreach (ref it; myArray.doSomething) {} Probably not the best idea anyway. What's the best fix for this? Thanks.
Re: bearophile is back! :) was: Re: conver BigInt to string
On Thursday, 5 November 2015 at 19:38:23 UTC, Ali Çehreli wrote: Good one! ;) I'm really happy that he is still around. Ali So am I! The more, the merrier!
Re: bearophile is back! :) was: Re: conver BigInt to string
On Thursday, 5 November 2015 at 19:30:02 UTC, Ali Çehreli wrote: On 11/05/2015 09:40 AM, bearophile wrote: Bye, bearophile Were you immersed in another language? Rust? Ali His D doesn't seem to be Rusty though!
Re: good reasons not to use D?
On Friday, 30 October 2015 at 10:35:03 UTC, Laeeth Isharc wrote: Interesting. Two points suggest that you should use D only for serious programming: "cases where you want to write quick one-off scripts that need to use a bunch of different libraries not yet available in D and where it doesn't make sense to wrap or port them" - quick and dirty "where you have many inexperienced programmers and they need to be productive very quickly." - quick and awkward [what does this tell us about financial programming ...] This reason is true of any other language: "where you have a lot of code in another language (especially non C, non Python) and defining an interface is not so easy;" In fact, the reasons you give (apart from the point about GUI) are true of C++, C#, Java etc. too. It's a bit generic. I was thinking of D specific reasons like lack of support for mobile platforms (not 100% yet). So your average stock broker couldn't calculate some bogus numbers on his iPad while having a latte and a Pelegrino in a posh cafe off Wallstreet. He he he. GC and lack of mobile are real reasons not to use D.
Re: LuaD: creating a flexible data filter system
On Saturday, 17 October 2015 at 02:02:16 UTC, Jakob Ovrum wrote: On Friday, 16 October 2015 at 10:45:52 UTC, Chris wrote: Later you call the function with the Lua C API like "lua_pcall(L, 0, 1, 0);". It's a bit tricky to move things around on the Lua stack, but you'll get there! ;) Or you could use LuaD which doesn't require you to mess around with the relatively unproductive, bug-prone C API :) I've used both, LuaD and DerelictLua + my own smaller D library that wraps all these nasty Lua stack operations (e.g. creating, accessing and adding to tables). The better I got to know the Lua C API while writing my own wrappers, the more I came to appreciate LuaD :-) However, LuaD is still 5.1 and I didn't want to be stuck with 5.1. So I rolled my own. It's not as comprehensive as LuaD but did the trick. The purpose was to experiment with Lua server pages + vibe.d which worked fine. Rikki gave me the idea to compile each page as a Lua function into memory for faster execution (etLua style[1]). It works fine with both LuaD and my own wrappers. In my own version I use the Lua C API directly in some places, though I don't know, if that's really a big speedup. If I set up my own homepage, I'd probably give vibe.d + Lua a shot. No more PHP and sh*t like that. [1] https://github.com/leafo/etlua
Re: LuaD: creating a flexible data filter system
On Friday, 16 October 2015 at 09:01:57 UTC, yawniek wrote: hi, i'm reading in a stream of data that is deserialized into individual frames. a frame is either of: a) a specific D datastructure ( struct with a few ulong,string,string[string] etc members), known at compile time b) json (preferably stdx.data.json) i now want to implement something where i can dynamically add lua filters that then get data out of these frames, create a new lua object send it back to D code where its either sent to another lua filter or at last being serialized again to json und then being processed further. ideally i would not like to copy all the data into a lua object but directly access it from lua. is there an elegant approach to do this and support both a and b cases? so far i did some benchmarks, mainly with string comparisons and it turned out that luaD is about 10x faster than mruby and python D bridges. You could use the Lua C API directly. I have a small project where I use DerelictLua[1] and access the Lua C API directly for fast processing (cf. http://www.lua.org/manual/5.3/ or http://www.lua.org/manual/5.2/ "C API"). Another performance trick is to compile lua functions and store them in memory, rather than having lua read and execute everything. lua_State* L = luaL_newstate(); auto func = luaL_loadstring(L, "Lua code as C-string\0"); // Lua file compiled as a function Later you call the function with the Lua C API like "lua_pcall(L, 0, 1, 0);". It's a bit tricky to move things around on the Lua stack, but you'll get there! ;) [1] https://github.com/DerelictOrg/DerelictLua
Re: OT: why do people use python when it is slow?
On Thursday, 15 October 2015 at 09:47:56 UTC, Ola Fosheim Grøstad wrote: On Thursday, 15 October 2015 at 09:24:52 UTC, Chris wrote: Yep. This occurred to me too. Sorry Ola, but I think you don't know how sausages are made. I most certainly do. I am both doing backend programming and we have a farm... :-) Well, you know how gourmet sausages are made (100% meat), because you make them yourself apparently. But I was talking about the sausages you get out there ;) A lot of websites are not "planned". They are quickly put together to promote an idea. The code/architecture is not important at that stage. The idea is important. The website has to have dynamic content that can be edited by non-programmers (Not even PHP! HTML at most!). If you designed a website from a programming point of view first, you'd never get the idea out in time.
Re: OT: why do people use python when it is slow?
On Wednesday, 14 October 2015 at 18:17:29 UTC, Russel Winder wrote: The thing about Python is NumPy, SciPy, Pandas, Matplotlib, IPython, Jupyter, GNU Radio. The data science, bioinformatics, quant, signal provessing, etc. people do not give a sh!t which language they used, what they want is to get their results as fast as possible. Most of them do not write programs that are to last, they are effectively throw away programs. This leads them to Python (or R) and they are not really interested in learning anything else. Scary, but I agree with you again. In science this is exactly what usually happens. Throw away programs, a list here, a loop there, clumsy, inefficient code. And that's fine, in a way that's what scripting is for. The problems start to kick in when the same guys get the idea to go public and write a program that everyone can use. Then you have a mess of slow code (undocumented) in a slow language. This is why I always say "Use C, C++ or D from the very beginning" or at least document your code in a way that it can easily be rewritten in D or C. But well, you know, results, papers, conferences ... This is why many innovations live in an eternal Matlab or Python limbo.
Re: OT: why do people use python when it is slow?
On Wednesday, 14 October 2015 at 18:37:40 UTC, Mengu wrote: On Wednesday, 14 October 2015 at 05:42:12 UTC, Ola Fosheim Grøstad wrote: On Tuesday, 13 October 2015 at 23:26:14 UTC, Laeeth Isharc wrote: https://www.quora.com/Why-is-Python-so-popular-despite-being-so-slow Andrei suggested posting more widely. That's flaimbait: «Many really popular websites use Python. But why is that? Doesn't it affect the performance of the website?» No. Really popular websites use pre-generated content / front end caches / CDNs or wait for network traffic from distributed databases. really popular portals, news sites? yes. really popular websites? nope. like booking.com, airbnb.com, reddit.com are popular websites that have many parts which have to be dynamic and responsive as hell and they cannot use caching, pre-generated content, etc. using python affect the performance of your website. if you were to use ruby or php your web app would be slower than it's python version. and python version would be slower than go or d version. Yep. This occurred to me too. Sorry Ola, but I think you don't know how sausages are made. Do you really think that all the websites out there are performance tuned by network programming specialists? You'd be surprised!
Re: Linker error with dmd
On Friday, 2 October 2015 at 14:03:08 UTC, John Colvin wrote: On Friday, 2 October 2015 at 09:43:54 UTC, Chris wrote: Why do I get this error msg with dmd 2.067.1 and 2.068.0 in release mode: $ dub --build=release (.data._D65TypeInfo_xC3std5range10interfaces18__T10InputRangeTiZ10InputRange6__initZ+0x10): undefined reference to `_D64TypeInfo_C3std5range10interfaces18__T10InputRangeTiZ10InputRange6__initZ' collect2: error: ld returned 1 exit status --- errorlevel 1 dmd failed with exit code 1. It works fine with the latest version of ldc2. What is it that you are building? An executable. I mainly use a code base that compiles perfectly well in release mode. I couldn't find the reason for this error message, plus, ldc2 has no problem with it.