Re: Warn on unused imports?
On Tuesday, 25 September 2018 at 13:03:30 UTC, FeepingCreature wrote: I'm playing with a branch of DMD that would warn on unused imports: Would just like to say that I love the idea and would use it immediately. Currently going through old code that evolved too organically, with imports too far away from where they were originally (but no longer) used.
Re: with and shadowing variables
On Monday, 23 July 2018 at 17:26:16 UTC, Steven Schveighoffer wrote: On 7/22/18 8:13 AM, Anonymouse wrote: Can this be made a compiler warning? struct Foo { int i; } void main() { Foo foo; with (foo) { i = 42; int i; i = 24; } } I'm hesitant to file a bug because it'll just be immediately closed with a link to https://dlang.org/spec/statement.html#WithStatement. I understand that's how it works, but it's weird and weak to human mistakes. I'm with Jonathan, it should be an error. It shouldn't matter what scope you declared `i` in, just when you use it, the ambiguity should trigger. The fix is super-simple, name it something else! Filed as https://issues.dlang.org/show_bug.cgi?id=19113.
Re: with and shadowing variables
On Monday, 23 July 2018 at 12:01:19 UTC, Jim Balter wrote: Do you have an actual case where it was a problem, as opposed to a contrived example with semantically empty identifiers? I recently saw another comment objecting to `with` altogether as being obfuscating because you can't tell which symbols are qualified by the symbol in the with clause, when the obfuscation was clearly due to the meaningless names in the poster's example. Copy/pasted but changed some bits for clarity. struct IRCServer { // ... string prefixchars; string prefixes; // <-- } struct IRCBot { // ... IRCServer server; } struct IRCParser { // ... IRCBot bot; } IRCParser parser; // string content == "EXCEPTS INVEX PREFIX=(Yqaohv)!~&@%+"; foreach (entry; content.splitter(" ")) { // Roughly rewritten splitting auto split = entry.findSplit("="); string key = split[0]; string value = split[2]; with (parser.bot.server) switch (key) { case "PREFIX": // PREFIX=(Yqaohv)!~&@%+ import std.format : formattedRead; string modes; string prefixes; // <-- value.formattedRead("(%s)%s", modes, prefixes); foreach (immutable i; 0..modes.length) { prefixchars[prefixes[i]] = modes[i]; // parser.bot.server.prefixchars prefixes ~= modes[i]; // <-- accidental local prefixes instead of parser.bot.server.prefixes } break; // ... default: break; } https://github.com/zorael/kameloso/blob/93002da193eac2dfbfeb6c8756feb2d74a345530/source/kameloso/irc.d#L1887
with and shadowing variables
Can this be made a compiler warning? struct Foo { int i; } void main() { Foo foo; with (foo) { i = 42; int i; i = 24; } } I'm hesitant to file a bug because it'll just be immediately closed with a link to https://dlang.org/spec/statement.html#WithStatement. I understand that's how it works, but it's weird and weak to human mistakes.
Compiler segfaults if not compiling with -debug #dbugfix
I'd like to bring #dbugfix attention to issue 18026: Stack overflow in ddmd/dtemplate.d:6241, TemplateInstance::needsCodegen()[0]. Put simply, I can only compile my code with -debug. Without it, dmd and ldc segfault on all of Linux, Windows and OSX. The smallest I can dustmite it to is to 66 lines (according to dscanner) across a few modules. ag0aep6g managed to reduce it further into one file at https://issues.dlang.org/show_bug.cgi?id=18026#c10, which he notes mostly segfaults but sometimes manages to compile. I can't reproduce his snippet on my machines, it may or may not work for you. The fickleness is a theme. There's no place to point and say "ah, there's the bug". It's just something emergent from a hundred little things that together make up something that segfaults compilers. I only know that it started when I added a big named enum with a few hundred members, and after that it's been popping up regularly. Sometimes it just goes away after I make some innocent, unrelated change. git clone https://github.com/zorael/kameloso.git -b 2080-overflow1-ldc You can try the full thing either with dub (plain or release), or just directly. $ dub build -b plain /usr/bin/dmd failed with exit code -11. $ dmd -c source/kameloso/*.d source/kameloso/plugins/*.d Segmentation fault (core dumped) $ ldc source/kameloso/*.d source/kameloso/plugins/*.d Segmentation fault Help. Please. :c [0]: https://issues.dlang.org/show_bug.cgi?id=18026
Re: Dscanner - DCD - Dfix ... Editor support or the lack of it.
On Friday, 26 January 2018 at 16:30:19 UTC, Benny wrote: On Friday, 26 January 2018 at 07:08:50 UTC, Johannes Loher wrote: Take this all with a grain of salt: I have only tested this on Linux and OS X, I have no clue about the situation on Windows. In general a lot of plugins tend to work better in POSIX systems then Windows. I think its more a issue about Windows platform testing. Just want to pipe in that I run linux and yeah, I can't relate to any of the OP's grievances, using Visual Studio Code. I installed serve-d and the D tools on the side from repositories, then a few clicks for the code-d beta in vscode, and it just works. Arch/Manjaro. No real complaints about the features offered either. Autocomplete can be a bit too eager at times maybe, suggesting equals_t and various enum members when typing else, recently unitTest (from ModuleInfo) instead of unittest, etc. Syntax highlighting points out unbalanced parens, braces and quotes. Mouseover for documentation works, looking up/peeking at definitions does too. If I could magically wish for one thing it would be UFCS support.
Re: [OT] vim tip with column limits
On Monday, 9 October 2017 at 00:24:02 UTC, Jonathan M Davis wrote: However, I just went digging around again to see if I could find an alternate solution, and I've now figured out that while there is only one cc you can set, you can actually give it multiple values. e.g. :set cc=81,121 will give you vertical lines on both columns 81 and 121, which is exactly what I've been trying to do (and you can provide more comma-separate numbers if you have a reason for more than two lines). Big thanks. Still exploring vim and this is something I hadn't thought possible.
Re: D Tour is down
On Tuesday, 29 August 2017 at 08:37:23 UTC, Petar Kirov [ZombineDev] wrote: Try clearing your browser cache and try again. Yesterday I experienced the same problem, but after I cleared my cache it was gone. Can confirm, Chromium 60 on Windows and something less on Linux. On a related note, where can I make the official request to allow specifying command-line arguments when running snippets? Optionally also text via stdin. dpaste has this but is obviously being superseded.
Re: Editor recommendations for new users.
On Sunday, 27 August 2017 at 12:11:14 UTC, Petar Kirov [ZombineDev] wrote: vim or SublimeText I want to get into vim. It has to be vim, can't be Neovim or gvim or any other clone; I'm doing it for a Linux class. I'm on Arch Linux (or Manjaro), so I have plenty available from the official repos and plenty more from the user AUR repos. The wiki page on vim[1] lists several plugins which I assume are mutually exclusive. DSnips[2] was very easy to install by just installing UltiSnips and placing d.snippets in its appropriate place, but it seems to only provide, as the name suggests, boilerplate snippets. Dutyl[3] seems much more interesting but also more daunting, considering that my vim knowledge so far largely consists of :wq and :q!. Are those the two alternatives available to me? [1]: https://wiki.dlang.org/D_in_Vim [2]: https://github.com/kiith-sa/DSnips [3]: https://github.com/idanarye/vim-dutyl
Re: import std.stdio; void main() { size_t count; bool[8191] flags; writeln("10 iterations"); // using iter as a throwaway variable foreach (iter; 1 .. 11) { count = 0; flags[] = 1
On Tuesday, 1 August 2017 at 14:08:26 UTC, enter per ner wrote: whats the mistake For everyone's sanity: https://run.dlang.io/is/bjlaNy
Re: Why is phobos so wack?
On Sunday, 9 July 2017 at 12:56:55 UTC, FoxyBrown wrote: [...] Your example is incomplete but this literally works for me. import std.stdio; import std.string; void main() { string[] words = [ "hello", "world", "!" ]; writeln(words.join(" ")); } You probably passed a string instead of a string[]. Virtually every other programming language just works as expected. You can pretty much just jump in there and pretty much guess at the function name, the arguments, and it will work. In my experience this simply isn't true. Error messages could be worlds better but no language lets you use it for more than toy purposes without ever having to look at some form of documentation.
Re: Foreach loops on static arrays error message
On Thursday, 6 July 2017 at 08:49:33 UTC, Stefan Koch wrote: I'd say this is not often encoutered. One should avoid using a different type then size_t for the index, as it can have negative performance implications. I thought size_t was what it lowered down to using if you used something else. What should I use instead?
Re: What is your favorite D feature?
On Thursday, 22 June 2017 at 00:48:25 UTC, Seb wrote: Hi, I am currently trying to modernize the D code example roulette on the dlang.org front page [1]. Hence, I would love to hear about your favorite feature(s) in D. Ideas: - favorite language construct - favorite code sample - "only possible in D" Before you ask, yes - I want to add a couple of cool examples to dlang.org (and yep the roulette rotation is currently broken [2]). [1] https://github.com/dlang/dlang.org/pulls?q=is%3Apr+is%3Aopen+label%3A%22Frontpage+example%22 [2] https://github.com/dlang/dlang.org/pull/1757 Fairly specific, but foreach (member; someStruct.tupleof). Part of my work on my IRC bot has been to serialise structs into configuration files (since std.json was *non-trivial* to deal with), and foreaching a someStruct.tupleof or a __traits(allMembers, symbol) allows for really, really interesting stuff.
Re: Help compiling discord bot from dub, vibe.d linker errors
On Thursday, 15 June 2017 at 15:50:06 UTC, Anonymouse wrote: I wanted to make a Hello World discord bot, and I found dscord[1] on dub. It even has an example bot Jeff[2], but it won't build. The machine is running Manjaro/Arch linux x64. Apologies, this was meant to go into Learn. I'll post it there instead.
Help compiling discord bot from dub, vibe.d linker errors
I wanted to make a Hello World discord bot, and I found dscord[1] on dub. It even has an example bot Jeff[2], but it won't build. The machine is running Manjaro/Arch linux x64. $ ./build.py Building with 0 plugins... Building jeff... ... dscord ~master: target for configuration "dscord-linux-static-x64" is up to date. jeff ~master: building configuration "jeff-linux-static-x64"... Linking... ../../../.dub/packages/vibe-d-0.8.0-beta.6/vibe-d/stream/.dub/build/generic-debug-linux.posix-x86_64-dmd_2074-2FC725C8AA6EF22B1FB09E2271B4E136/libvibe-d_stream.a(openssl.o): In function `_D4vibe6stream7openssl18_sharedStaticCtor2FZv': /home/src/discord/jeff/../../.dub/packages/vibe-d-0.8.0-beta.6/vibe-d/stream/vibe/stream/openssl.d:863: undefined reference to `SSL_load_error_strings' /home/src/discord/jeff/../../.dub/packages/vibe-d-0.8.0-beta.6/vibe-d/stream/vibe/stream/openssl.d:864: undefined reference to `SSL_library_init' /home/src/discord/jeff/../../.dub/packages/vibe-d-0.8.0-beta.6/vibe-d/stream/vibe/stream/openssl.d:866: undefined reference to `CRYPTO_num_locks' /home/src/discord/jeff/../../.dub/packages/vibe-d-0.8.0-beta.6/vibe-d/stream/vibe/stream/openssl.d:874: undefined reference to `CRYPTO_set_id_callback' /home/src/discord/jeff/../../.dub/packages/vibe-d-0.8.0-beta.6/vibe-d/stream/vibe/stream/openssl.d:880: undefined reference to `SSL_get_ex_new_index' ../../.dub/packages/vibe-d-0.8.0-beta.6/vibe-d/stream/.dub/build/generic-debug-linux.posix-x86_64-dmd_2074-2FC725C8AA6EF22B1FB09E2271B4E136/libvibe-d_stream.a(openssl_10df_569.o): In function `_D4vibe6stream7openssl14OpenSSLContext6__ctorMFNfE4vibe6stream3tls14TLSContextKindE4vibe6stream3tls10TLSVersionZ9__lambda3MFNbNeZv': /home/src/discord/jeff/../../.dub/packages/vibe-d-0.8.0-beta.6/vibe-d/stream/vibe/stream/openssl.d:419: undefined reference to `SSLv23_client_method' /home/src/discord/jeff/../../.dub/packages/vibe-d-0.8.0-beta.6/vibe-d/stream/vibe/stream/openssl.d:420: undefined reference to `SSLv23_client_method' /home/src/discord/jeff/../../.dub/packages/vibe-d-0.8.0-beta.6/vibe-d/stream/vibe/stream/openssl.d:424: undefined reference to `SSLv23_client_method' /home/src/discord/jeff/../../.dub/packages/vibe-d-0.8.0-beta.6/vibe-d/stream/vibe/stream/openssl.d:425: undefined reference to `SSLv23_client_method' /home/src/discord/jeff/../../.dub/packages/vibe-d-0.8.0-beta.6/vibe-d/stream/vibe/stream/openssl.d:432: undefined reference to `SSLv23_server_method' /home/src/discord/jeff/../../.dub/packages/vibe-d-0.8.0-beta.6/vibe-d/stream/vibe/stream/openssl.d:433: undefined reference to `SSLv23_server_method' /home/src/discord/jeff/../../.dub/packages/vibe-d-0.8.0-beta.6/vibe-d/stream/vibe/stream/openssl.d:435: undefined reference to `SSLv23_server_method' /home/src/discord/jeff/../../.dub/packages/vibe-d-0.8.0-beta.6/vibe-d/stream/vibe/stream/openssl.d:436: undefined reference to `SSLv23_server_method' ... Is that vibe.d not linking with openssl? There are more errors but it would be a bit long to paste them all. [1]: https://code.dlang.org/packages/dscord [2]: https://github.com/b1naryth1ef/jeff
Re: std.csv Performance Review
On Saturday, 3 June 2017 at 04:25:27 UTC, Jesse Phillips wrote: Even though the issue can be ignored, the overhead of parsing to identify issues still remains. I haven't attempted write the algorithm assuming proper data structure so I don't know what the performance would look like, but I suspect it isn't negligible. There is also likely some overhead for providing the tokens through range interfaces. Immediate idea is to have the cake and eat it too with parseXML!(Yes.validate)(...), but more work.
Re: Interpolated strings
On Friday, 21 April 2017 at 12:45:39 UTC, Gary Willoughby wrote: Multiple ways of doing the same thing are not valuable or progressive. Go and Rust are both smashing D in popularity and user share, maybe we could learn why that's the case. Corporate backing and word-of-mouth? I recall reading a KDE blog article about the problems of internationalizaton where you have large tables of pattern strings (think WelcomeMessage[EN]="Welcome $user to $hostname") where the tokens were very much in different ordering depending on language, or how some may even be considered implicit and ommitted outright. (Japanese springs to mind.) It was way back now so I don't even know where to begin to start looking, but it highlighted how the ordering did not translate well into printf patterns. Citation needed but it's a use-case this would address.
Re: creating a temporary fifo (tmpfile but for fifo)
On Thursday, 16 February 2017 at 17:49:07 UTC, John Colvin wrote: For some reason it doesn't seem to be on the website, but the source is here to read: https://github.com/dlang/druntime/blob/master/src/core/sys/posix/stdlib.d Use the Source, Luke!
Re: Seemingly patternless optlink premature termination
On Monday, 9 January 2017 at 07:05:27 UTC, Walter Bright wrote: If you don't report bugs, they are guaranteed to not get fixed. There's nothing anyone can do with the statement you made. A good quote is "unreported bugs can only be fixed by accident."
Re: Multiple return value as requirements for safety and performance
On Tuesday, 20 December 2016 at 13:47:50 UTC, Ilya Yaroshenko wrote: One good thing for safety and CTFE is allow multiple return value. In combination with `auto ref` it is _very_ powerful: auto ref front() { // Returns 2 values, each value is returned by reference if possible return (a.front, b.front); } Nested Voldemort structs? Horcruxified, to work around the symbol name length explosion. I always imagined allowing for multiple values (in multiple fields) was part of the point behind them. For instance, consider the several discrete pieces of data you get from the Result of std.regex matching. (Not all of it is via opIndex.)
Re: DIP10005: Dependency-Carrying Declarations is now available for community feedback
On Wednesday, 14 December 2016 at 17:24:29 UTC, Anonymouse wrote: The with keyword then? bool equal(R1, R2) with (std.range : isInputRange, isOutputRange) && (std.stdio : writeln) && (std.algorithm) if (isInputRange!R1 && isInputRange!R2) { ... } I guess the &&s there don't make sense. Maybe with a semicolon delimeter instead. bool equal(R1, R2) with (std.range : isInputRange, isOutputRange; std.stdio : writeln; std.algorithm) if (isInputRange!R1 && isInputRange!R2) { ... }
Re: DIP10005: Dependency-Carrying Declarations is now available for community feedback
On Wednesday, 14 December 2016 at 17:09:44 UTC, ketmar wrote: On Wednesday, 14 December 2016 at 17:01:50 UTC, Andrej Mitrovic How about: bool equal(R1, R2) : std.range if (isInputRange!R1 && isInputRange!R2) { ... } It's nice and concise, and you could in theory also allow multiple imports with a comma bool equal(R1, R2) : std.range, std.traits if (isInputRange!R1 && isInputRange!R2 && isArray!R2) { ... } breaks possible selective import. if both modules exports some symbol, we will need to selectively import and/or rename it. The with keyword then? bool equal(R1, R2) with (std.range : isInputRange, isOutputRange) && (std.stdio : writeln) && (std.algorithm) if (isInputRange!R1 && isInputRange!R2) { ... } A problem with that is that it reads "bool equal with std.stdio if something", suggesting something decides whether or not to import std.stdio.
Re: CTFE Status
On Sunday, 11 December 2016 at 08:37:28 UTC, Stefan Koch wrote: Disregard That! I wasn't paying attention The lower numbers are produced by ldc! The performance fixes did lower the overall overhead even more though. Which means bytecode generation will not even show up among the top 50 functions in dmd, Would you say it has ended up being more or less (or roughly equal) work than you initially expected? And keep up the good work!
Re: OT: Tiobe Index - December Headline: What is happening to good old language C?
On Thursday, 8 December 2016 at 13:19:31 UTC, Meta wrote: On Thursday, 8 December 2016 at 08:46:07 UTC, Nordlöw wrote: On Tuesday, 6 December 2016 at 07:40:44 UTC, Nick B wrote: source: http://www.tiobe.com/tiobe-index/ (Dec 2016) Glad to see D at 21. I believe this an improvement compared to previous year. Does anybody got any hard numbers for this? Actually I think D has slipped. I believe it used to be at 18, but I can't remember when that was. It's nice to see D in the ballpark of 1%+. That said, I also think the whole index should be taken with more than one grain of salt. Sources and metrics. Lies, damned lies and statistics. As their disclaimer says, it's the languages most mentioned and with the most search hits that score the highest, not the most used. Maybe it was particularly high when dconf coverage circulated reddit and HN.
Re: CTFE Status
On Sunday, 20 November 2016 at 09:02:30 UTC, Stefan Koch wrote: On Saturday, 19 November 2016 at 11:22:18 UTC, Stefan Koch wrote: [...] I would buy you a beer but the Internet is in the way.
Re: send doesn't work
On Wednesday, 16 November 2016 at 13:10:06 UTC, unDEFER wrote: On Wednesday, 16 November 2016 at 10:54:32 UTC, Era Scarecrow wrote: I just have to wonder every time I look at this... how long is 1 hnsecs? I'd assume not very long. Either blocking unless there's no more messages, or having a longer timeout period seems a better bet. Might make it 1-5ms. Really I have wanted to write 0ms, but don't sure that it is possible. receiveTimeout(0.seconds, /* ... */ );
Re: Trailing catch on function?
On Wednesday, 9 November 2016 at 09:49:08 UTC, Daniel N wrote: On Tuesday, 8 November 2016 at 16:02:25 UTC, Manu wrote: scope(failure) doesn't catch... how is that function nothrow? Seems like you overlooked Anonymouse's comment? scope(failure) catches just fine. scope(failure) return -1; throw new Exception("failure"); return 0; This will return -1, with no need for extra indentation. I understand its convenience, but as long as it also catches Errors I'm not sure this is something you want to do though. You won't be able to differentiate between invalid input and bugs in the code, potentially continuing in an invalid state. Subsetting failure into a scope(exception) would work, but I'm not sure how the interplay between them would work. Or are Errors so fatal that it should always immediately crash the program, ignored by scope(failure)?
Re: Trailing catch on function?
On Tuesday, 8 November 2016 at 01:50:26 UTC, Walter Bright wrote: Who to get the Exception thrown in the scope(failure) You don't. The exception is also rethrown, so it isn't an exact replacement. (The 'nothrow' is a mistake on my part.) You can eat the exception by returning in the scope guard. Since it seems to trigger on Throwables it also eats Errors, sadly. void fun() nothrow { scope(failure) { // cleanup logic return; } throw new Exception("I don't get rethrown"); }
Re: If Statement with Declaration
On Sunday, 6 November 2016 at 05:07:10 UTC, Andrei Alexandrescu wrote: // possible future D if ((auto variable = fun()) != 42) { ... } Defining a variable in an expression wouldn't be allowed everywhere (but might be contemplated later as an possibility, which is a nice thing about this syntax). I like it but it would have to require the parantheses, or you could get ambiguities like: if (auto variable = noParensGetSomeT == true) { // is variable of type T or bool, if T can be implicitly cast? } A more approachable thing to do is allow variable definitions in switch statements: switch (auto x = fun() { ... } It is surprising that doesn't work, which is a good argument in favor of the feature (removal of an undue limitation, rule of least astonishment etc). This I can get behind, would start using it right away. Andrei
Re: Documentation unittests are seriously awesome
On Friday, 23 September 2016 at 20:42:26 UTC, Nick Sabalausky wrote: Just had to say it. Been using it a lot this week. Referring to this stuff: /// Does foo stuff void foo() {} /// unittest { // Tests and docs in one, 2-for-1 win! } And all just built-in. Freaking sweet. ELI5 please. What does this do and how is it different from normal practice? (I assume having the docs together with the tests is what's special here.)
Re: Accessing types by context
On Wednesday, 29 June 2016 at 05:06:08 UTC, Hiemlick Hiemlicker wrote: On Wednesday, 29 June 2016 at 03:50:35 UTC, Carl Vogel wrote: On Wednesday, 29 June 2016 at 03:11:52 UTC, Hiemlick [...] Doesn't the with statement solve your problem here? with (myEnum) { test(A); test(B); test(C); } Not really it's, only half the way there. Why not extend the language the extra step? I'm not sure I understand how it doesn't. Inside the with scope you could refer to myEnum members by their (unqualified) names alone. Isn't this the behaviour you're asking for? As a pet peeve of mine, it's unfortunate that with: cannot be used as attributes can, to last until the end of the current scope without adding a new one. void foo() { with(myEnum): // doesn't work test(A); test(B); test(C); }
Re: Results of Rust Survey 2016
On Thursday, 23 June 2016 at 08:39:35 UTC, Ola Fosheim Grøstad wrote: On Thursday, 23 June 2016 at 08:33:39 UTC, qznc wrote: An interesting fact "currently 19.8% use Rust at work either part-time or full-time". That is 395 of 1994 people. People who use it at work are more likely to respond. Yes, sadly sampling bias is a thing. Would participate in survey, sounds fun.
Re: dpaste and warning upon leaving page
On Wednesday, 11 May 2016 at 22:18:47 UTC, Jack Stouffer wrote: On Tuesday, 10 May 2016 at 16:39:05 UTC, Anonymouse wrote: I just had a PEBCAK moment where I was composing a large-ish snippet on dpaste, then accidentally left the page by clicking the back button on my mouse. Going back to the page I see my changes were lost. Could we maybe add a warning when leaving the page if the content has been changed? I think it's the onbeforeunload event, but I don't know javascript well. http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onbeforeunload_dom IIRC chrome does this automatically. This was using Chrome, version 50 or thereabouts. Tested it again now and it doesn't warn.
dpaste and warning upon leaving page
I just had a PEBCAK moment where I was composing a large-ish snippet on dpaste, then accidentally left the page by clicking the back button on my mouse. Going back to the page I see my changes were lost. Could we maybe add a warning when leaving the page if the content has been changed? I think it's the onbeforeunload event, but I don't know javascript well. http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onbeforeunload_dom
Re: sorting a mutable array of immutable objects
On Wednesday, 20 April 2016 at 12:34:28 UTC, Anonymouse wrote: On Wednesday, 20 April 2016 at 10:32:42 UTC, Jeff Thompson [...] Also note that sort (std.algorithm.sorting : sort) returns a range and doesn't sort in place. (Lastly this is probably more at home in the Learn forum.) It does sort in place as well apparently, my bad.
Re: sorting a mutable array of immutable objects
On Wednesday, 20 April 2016 at 10:32:42 UTC, Jeff Thompson wrote: On Wednesday, 20 April 2016 at 09:54:13 UTC, Jeff Thompson wrote: I can create a mutable array of immutable objects, thanks to the answers to my other question https://forum.dlang.org/post/nf57f5$e6v$1...@digitalmars.com . Now I want to sort the array. I found a solution, but I'm not sure it is the best way. Instead of overriding opCmp, class C just defines a static comparison to use with sort (which automatically works with Rebindable). Is there a way to do this where I don't need to specify C.isLess every time I sort? class C { this(int x) immutable { this.x = x; } static bool isLess(const C a, const C b) @safe pure nothrow { return a.x < b.x; } int x; } void main(string[] args) { auto array = new Rebindable!(immutable(C))[2]; array[0] = new immutable C(20); array[1] = new immutable C(10); sort!(C.isLess)(array); } int opCmp(immutable Object o) immutable {} That seems to work for me. You want to make it const Object and inout if you want it to work on const and mutable C's as well. Also note that sort (std.algorithm.sorting : sort) returns a range and doesn't sort in place. (Lastly this is probably more at home in the Learn forum.)
Re: mutable array of immutable objects
On Tuesday, 19 April 2016 at 10:41:05 UTC, Jeff Thompson wrote: I want to create a mutable array of immutable objects, but the code below gives the error shown below. It seems that "new immutable(C)[1]" makes the entire array immutable, but it seems I should be able to change the elements of an array of pointers to an object even though the objects are immutable. How to do that? class C { this(int x) immutable { this.x = x; } int x; } void main(string[] args) { auto array = new immutable(C)[1]; array[0] = new immutable C(10); // Error: Cannot modify immutable expression array[0]. } Mind that this is akin to declaring a string (immutable(char)[]) and trying to modify an element. You can append, though. Or rather, make a new array/slice with the new elements concatenated into it.
Re: Oh, no UFCS for member functions
On Tuesday, 29 March 2016 at 14:56:53 UTC, Luís Marques wrote: Too bad this doesn't work: struct Player { MapTile[] playerMap; // partial private knowledge of map Location destination; auto tile(Location loc) { return playerMap[loc]; } void foo() { if(destination.tile.hasMonster) ... } } By design. I don't remember the rationale, though. The ugly workaround if you really don't want to reorganise things (and/or use the tile function directly) is to make a top-level alias tile = Player.tile;
Re: Is C++ trying to be like D?
On Sunday, 20 March 2016 at 01:18:06 UTC, Walter Bright wrote: Would one rather have a Ferrari Daytona replica made from a Corvette, or a Ferrari Daytona? Said crowd is made of die hard Corvette fans, who have been historically downplaying the extra spiffs of the Ferraris as useless. So now that they get them for their own cars, they are amazing new ideas and/or have retroactively been important the entire time. Reasons to get Ferraris instead are invalidated accordingly. I don't agree with them, but I've seen it in other contexts so I imagine it's a common fallacy.
Re: Is C++ trying to be like D?
On Saturday, 19 March 2016 at 13:23:55 UTC, Bauss wrote: Looking at C++14 and the proposed features for C++17 - https://en.wikipedia.org/wiki/C%2B%2B17 It looks a lot like C++ is trying to become similar to D. I believe that shows D's design pattern has been superior to C++'s from the start and there's no way C++ will ever be able to implement the same features of D in the same smooth and "user-friendly" behavior. What's your opinion? A much more common take on it is "why use D at all now that C++ is getting similar features", ignoring convenience. (I don't subscribe to it.)
Re: write to file array by lines
On Tuesday, 15 March 2016 at 10:58:16 UTC, Suliman wrote: I have got: string [] total_content; I am appending to it data on every iteration. total_content ~= somedata File file = File(`D:\code\2vlad\result.txt`, "a+"); file.write(total_content); I need to write it's to file by lines. Like: somedataline1 somedataline2 somedataline3 I tried to do like: total_content ~= somedata ~ "\n" but in result I am getting all data in one line: somedataline1 "\n" somedataline2 "\n" somedataline3 "\n" what I am doing wrong? I know about split, but how it can be called on writing time? Windows CRLF line endings, perhaps?
Re: Wannabe contributor frustrations
On Thursday, 11 February 2016 at 02:07:54 UTC, Etienne wrote: On Wednesday, 10 February 2016 at 23:30:03 UTC, Márcio Martins wrote: My expectation was that given I followed the official "tutorial" closely, everything was going to just work, instead I spent about 2 hours on this and got nowhere... It took me way more than 2 hours to grasp how this build process works. It wasn't until I had read through the whole source code actually. "Use the source, Luke!"
Re: std.experimental.yesnogc
On Thursday, 14 January 2016 at 00:35:53 UTC, Andrei Alexandrescu wrote: Hey folks, I want to push things forward with artifacts dedicated to avoiding the GC, and of course my main worry is finding the right name. std.samesamebutdifferent
Re: sgue...@rejectedsoftware.com
On Sunday, 13 December 2015 at 06:57:21 UTC, Sönke Ludwig wrote: else if (args.length == 3) input = File(args[1], "rt"), output = File(args[1], "wt"); Should output not be args[2]?
Re: Interrogative: What's a good blog title?
On Monday, 27 April 2015 at 22:54:07 UTC, Andrei Alexandrescu wrote: I don't have a blog, and was thinking of starting one. E.g. the article on tracing allocations needs a home! I was wondering if you have any good ideas of what's a good blog name. I'd avoid branding my blog with my longish name, so I was thinking of something simple and easy to use in conversation (e.g. my current draft title at http://blog.erdani.com, the metareferential "You Are Reading This Blog's Title" is perhaps intriguing but difficult to talk about). Any thoughts? My only candidate right now is "Greasemonkey Philosopher". I'm shooting for a title that reflects the contrast between my low-level and high-level aspirations. Sadly enough, "greasemonkey" is a popular browser extension package, so it comes up in searches etc. Generally I'm looking for a phrase that's catchy but doesn't remind one of something else. Something contradictory, funny, etc. Please let me know of any thoughts you might have! Thanks, Andrei assumeBlog
Re: [OT] I wrote a (better?) heap memory manager, is it good for anything?
On Saturday, 9 August 2014 at 08:48:37 UTC, Mehrdad wrote: Hi all, This is barely relevant to D, but I thought I'd try posting it here because I thought the audience might be interested. Let me know if I should post it somewhere else. Long story short, I wrote my own C++ heap memory manager a while ago from scratch. First, here's a description: Cons: - Average-case performance is somewhat worse than heap managers provided by the OS or language runtimes - I'm not quite ready to open-source it yet (partly because I'm not sure if it's worth licensing commercially vs. open-sourcing, and partly because I'm not quite confident it's completely bug-free yet) Pros: - It was built from the ground-up to have dependable worst-case performance, and I think it's *pretty good* and robust under various allocation patterns - It keeps metadata entirely separate from data -- so when allocate a 4KB page of memory, it's not going to allocate an extra 4KB behind it just to put a "length" field there, which has given me problems before. (This can reduce the working set of the process considerably depending on your allocation granularity.) - It is alignment-agnostic -- so, it allocates _exactly_ as much as requested (no performance penalty for this whatsoever) - It's platform-independent (it's worked on Windows and also on Linux the few times I tried it) -- it's pretty easy to supply your own memory manager underneath, too. - It has a very simple C (and C++) interface: typedef uintptr_t ManageMemory( void *context, uintptr_t address, size_t size, bool deallocate, bool commitment); extern ManageMemory manage_system_memory; void *memory_heap_construct( void *p, ManageMemory *manager, void *context); void memory_heap_destroy(void *p); void *memory_heap_allocate( void *heap, size_t size, void *hint); void memory_heap_deallocate( void *heap, void *address, size_t size); size_t memory_heap_size(); I was basically wondering if had any particular workloads they were interested in testing this on and giving me feedback on it. For now I'd give you a .DLL or a .so (though I haven't redistributed Linux binaries before, so I'd have to figure out how to do that) and the C/C++ header so you can use it and see how it is. Maybe you'd find it potentially useful for D too, but I guess that depends on how well it performs. Let me know if you're interested. There is no realloc, move, cpy ?