Re: Invalid foreach aggregate
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?
Re: Any D IDE on Mac OSX with debugging support?
On Monday, 16 November 2015 at 08:15:36 UTC, Jacob Carlborg wrote: On 2015-11-16 08:48, Rikki Cattermole wrote: On recent versions of OSX, Apple has by default made it so that all applications must be signed by default. You can disable this behavior through system settings and security. I suspect this is what is stopping it. Alternatively use LLDB shipped with Xcode. But that won't of course have the D support that GDB has. Although I don't know if that works for OS X. Mono-D adds -i=mi parameter to debugger command line so it looks like it supports only GDB.
Re: on structs by reference
On Monday, 16 November 2015 at 07:51:53 UTC, Ali Çehreli wrote: import std.stdio; /* This is the storage to the slices that objects will share. * * (Surprisingly, creating a slice dynamically is not possible due * to syntax issues: new int[N] means "allocates N ints and make * a slice from those." However, we need a dynamic slice object * here. I've decided to put the slices in a 'slice slice' here.) */ int[][] slices; struct S { size_t idx; ref int[] arr() { return slices[idx]; } } void main() { S s; // = new S(); slices ~= [1,2,3]; s.idx = slices.length - 1; writeln(s.arr); //first S t; // = new S(); t = s; writeln(t.arr); //second s.arr ~= 4; writeln(s.arr); //third writeln(t.arr); } [1, 2, 3] [1, 2, 3] [1, 2, 3, 4] [1, 2, 3, 4] Ok, this definitely helps. Thank you! For me, the key point here is, that my struct S, which use one of the slices in the Slice of slices does not own it. This is ok. So, I have to think about who owns the Slice of slices now, because only this 'something' should be able to rearrange its data... The cool thing is, that it will be able to modify the data THROUGH the s structs, as in the line s.arr ~= 4; and is not restricted to. So, new S structs are generated by operating on the Slice of slices directly and old slices can be modified by operating on the appropriate S struct. Thanks again for helping zooming out...
Re: Epoch time + msecs
On Monday, 16 November 2015 at 14:21:02 UTC, Ola Fosheim Grøstad wrote: No, to get a period of 2^19937 you need 19937 bits or 2-3 KiB… ;) This computes out of context :) but...
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.
Re: Linker error from dub?
On Thursday, 12 November 2015 at 06:11:37 UTC, BBasile wrote: On Thursday, 12 November 2015 at 06:03:49 UTC, BBasile wrote: It worked fine because it was not used, not parsed, not linked. Maybe just the functions declarations was parsed to solve the symbols in the program, but since none was used the 'import blas.blas' was eliminated or something like that. This could be explained better by someone who knows well DMD architecture... I think that you would get an error with just the 'import blas.blas' and building the debug config. I've spotted a std.expirmental.allocators bug this summer that was revealed in by a similar scheme: extern declaration not used in release mode, but in debug mode the symbols, even if not used, were not eliminated and the compiler complained about undefined symbol this & that ! It's been a few days, but I just wanted to say thanks for the help. I was able to fix the problem by linking to cblas in my dub.json.
Re: Any D IDE on Mac OSX with debugging support?
On Monday, 16 November 2015 at 07:48:31 UTC, Rikki Cattermole wrote: On 16/11/15 7:45 PM, Vadim Lopatin wrote: Hello, Is there any IDE which allows debugging D apps on OSX? I'm trying Mono-D, but getting error "Debugger operation failed A syntax error in expression, near 'sizeof(void*)'" GDB is installed using homebrew. Probably, something is wrong with my gdb. When I'm trying to start debugging using console GDB interface - it fails with message about unsigned application. Is there any instruction how to get GDB working on OSX? Code completion and symbol lookups neither do not work on Mono-D / OSX. Does anyone managed to get it working? Best regards, Vadim On recent versions of OSX, Apple has by default made it so that all applications must be signed by default. You can disable this behavior through system settings and security. I suspect this is what is stopping it. https://answers.uchicago.edu/25481 Changing of system settings, creation of certificate and signing of GDB executable helped to get gdb debugging working when running from command line. But debugging from Mono-D still fails with the same error.
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: Epoch time + msecs
On Monday, 16 November 2015 at 10:47:36 UTC, Marc Schütz wrote: Hmmm... why is `unpredictableSeed` only a `uint`? Surely most PRNGs have more than 32 bits of internal state? Maybe it's only worth 32 random bits? There's a rangified example too: http://dlang.org/phobos/std_random.html#.MersenneTwisterEngine.seed.2
Re: Epoch time + msecs
On Monday, 16 November 2015 at 13:34:41 UTC, Kagamin wrote: On Monday, 16 November 2015 at 10:47:36 UTC, Marc Schütz wrote: Hmmm... why is `unpredictableSeed` only a `uint`? Surely most PRNGs have more than 32 bits of internal state? Maybe it's only worth 32 random bits? There's a rangified example too: http://dlang.org/phobos/std_random.html#.MersenneTwisterEngine.seed.2 No, to get a period of 2^19937 you need 19937 bits or 2-3 KiB… ;)
Re: Invalid foreach aggregate
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?
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?
writef format specifier error message
I accidentally typed an extra asterisk in the format specifier. I know that it is wrong but the error isn't clear about what and where the error is. import std.stdio; void main() { writef("%*10s", 100); } and I got the following error message(s): $ dmd -run writef.d std.format.FormatException@std/format.d(978): $ expected ??:? pure @safe bool std.exception.enforceEx!(std.format.FormatException).enforceEx!(bool).enforceEx(bool, lazy immutable(char)[], immutable(char)[], ulong) [0x437786] ??:? pure @safe void std.format.FormatSpec!(char).FormatSpec.fillUp() [0x44754b] ??:? @safe bool std.format.FormatSpec!(char).FormatSpec.writeUpToNextSpec!(std.stdio.File.LockingTextWriter).writeUpToNextSpec(std.stdio.File.LockingTextWriter) [0x438173] ??:? @safe uint std.format.formattedWrite!(std.stdio.File.LockingTextWriter, char, int).formattedWrite(std.stdio.File.LockingTextWriter, const(char[]), int) [0x436f99] ??:? @safe void std.stdio.File.writefln!(char, int).writefln(const(char[]), int) [0x436e9c] ??:? @safe void std.stdio.writefln!(immutable(char)[], int).writefln(immutable(char)[], int) [0x436deb] ??:? _Dmain [0x436d9f] ??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv [0x443cc2] ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x443c18] ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() [0x443c7e] ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x443c18] ??:? _d_run_main [0x443b75] ??:? main [0x43f8d5] ??:? __libc_start_main [0xba3cc60f]
Re: writef format specifier error message
On 11/16/2015 10:56 AM, ric maicle wrote: I accidentally typed an extra asterisk in the format specifier. I know that it is wrong but the error isn't clear about what and where the error is. import std.stdio; void main() { writef("%*10s", 100); } and I got the following error message(s): $ dmd -run writef.d std.format.FormatException@std/format.d(978): $ expected That message can be improved. Please open a bug report: https://issues.dlang.org/enter_bug.cgi Thank you, Ali
Looking for a language to hang my hat on.
I am a very new c++ programmer, having just learned the language this year. A few months ago I completed a course on Coursera that dealt with the security aspect of c (which I don't know, but it is similar enough): https://class.coursera.org/softwaresec-008 The course highlighted just how dangerous c/c++ can be. My reaction to the course has been an increased use of shared/weak pointers over standard pointers, more judicious use of "assert" and increased use of destructors, where class pointers are destroyed via the destructor so I don't need to worry about memory leaks as much (all of my non-vector arrays are created/destroyed via a class w/ template). Some of this slows programs down, but in reality it does not have much of an impact. But doubt will always linger that I caught every vulnerability. Therefore I am shopping for a language that codes like c++ but is safer. It sounds like D may fit that requirement. My platform of choice is 64-bit Fedora using Code::Blocks (yes, I use an IDE as a crutch). It seems that D supports this combo. I have been lurking on this site over the past few weeks trying to decide when (and if) to make the transition. Can anyone here who has already made that transition tell me how smoothly it went? Any major unexpected problems? Advice? thanks! Dan
Re: Looking for a language to hang my hat on.
On Monday, 16 November 2015 at 22:39:17 UTC, Dan wrote: I am a very new c++ programmer, having just learned the language this year. A few months ago I completed a course on Coursera that dealt with the security aspect of c (which I don't know, but it is similar enough): https://class.coursera.org/softwaresec-008 The course highlighted just how dangerous c/c++ can be. My reaction to the course has been an increased use of shared/weak pointers over standard pointers, more judicious use of "assert" and increased use of destructors, where class pointers are destroyed via the destructor so I don't need to worry about memory leaks as much (all of my non-vector arrays are created/destroyed via a class w/ template). Some of this slows programs down, but in reality it does not have much of an impact. But doubt will always linger that I caught every vulnerability. Therefore I am shopping for a language that codes like c++ but is safer. It sounds like D may fit that requirement. My platform of choice is 64-bit Fedora using Code::Blocks (yes, I use an IDE as a crutch). It seems that D supports this combo. I have been lurking on this site over the past few weeks trying to decide when (and if) to make the transition. Can anyone here who has already made that transition tell me how smoothly it went? Any major unexpected problems? Advice? thanks! Dan Start using D now. It's not all or nothing so you don't have to give up on C++. I have several projects that contain both C++ and D intermixed. D will make you a better C++ programmer, but especially C++ template programming. D metaprogramming is so easy to read, write and understand compared to C++ and many of the patterns still apply when you're standing knee deep in C++it. I also find the D standard library, Phobos, is a great codebase to learn from. Compared to the STL (except perhaps the original [1]) it's a great example of how performant D code can still be readable and maintainable. bye, lobo [1] http://www.stepanovpapers.com/butler.hpl.hp/stl/stl.zip
linux inotify on a std.process.ProcessPipes ?
Does anyone know if it's possible to monitor the events that happen on the output stream of a piped process ? I'm stuck on doc: - https://www.win.tue.nl/~aeb/linux/lk/lk-12.html - http://www.ibm.com/developerworks/library/l-ubuntu-inotify/ - http://linux.die.net/man/2/inotify_add_watch inotify_add_watch second argument seems to be a file name. The only thing available is a std.stdio.File with a handle. The goal is to create an asynchronous process with a least one notification that would happen when the process terminates, maybe when the output stream is written too.
Re: What does the -betterC switch in dmd do?
On Sunday, 15 November 2015 at 15:34:19 UTC, Jacob Carlborg wrote: I'm pretty sure that the only things that are excluded are module info and type info. It's still possible to use "new" and all the array features that requires support in the runtime (slicing, concatenation, appending and so on). In my experience, the only thing removed by -betterC is the ModuleInfo [1] However, there is a pending pull request to remove TypeInfo also [2] I don't think it was every fully implemented to the author's intention, and I'm not sure if it ever will be [3] Mike [1] http://forum.dlang.org/post/mailman.273.1386260316.3242.d@puremagic.com [2] https://github.com/D-Programming-Language/dmd/pull/5105 [3] http://forum.dlang.org/thread/lddug4$jgv$1...@digitalmars.com
Re: Looking for a language to hang my hat on.
On Monday, 16 November 2015 at 22:39:17 UTC, Dan wrote: I have been lurking on this site over the past few weeks trying to decide when (and if) to make the transition. Can anyone here who has already made that transition tell me how smoothly it went? Any major unexpected problems? Advice? Your largest problem in the short term is documentation quality. It's improving, but it has a long way to go. It doesn't help that the standard library has such gems as: auto joiner(RoR, Separator)(RoR r, Separator sep) if (isInputRange!RoR && isInputRange!(ElementType!RoR) && isForwardRange!Separator && is(ElementType!Separator : ElementType!(ElementType!RoR))); Your largest problem in the long run will be libraries. I'm guessing the .NET BCL is larger than everything in the D standard library plus everything available via DUB. If you're using the language in a professional capacity, you'll eventually want libraries to help you connect to commercial stuff like Google or AWS APIs -- yeah, you're writing those yourself. Whereas with C++, Java, Ruby, C#, what have you, you've already got corporate library support by default. Even Go has first-party library support for AWS. D? Not even a community version. This might change, but that's a gamble, and not one I'd take. For projects where you need specific libraries to exist already, D probably won't serve your needs. (It's definitely easier with C++ interop, but you'd still have to write bindings. htod doesn't exactly work on Linux.) Random example: I wanted an embedded document database. There are a few hanging around. Guess how many have D bindings. I ended up going with LevelDB, which is just a key/value store, and hoping that I didn't need any indices -- LevelDB already has D bindings, whereas I didn't find any real embedded document databases with D bindings. Similarly, there's a lot more choice in terms of libraries in other languages. So you know that, if the first library to do a thing doesn't quite meet your needs, the second might. I don't have that confidence in D. This is slowly getting better, and it's a lot easier with DUB than it was when I started using D.
Re: linux inotify on a std.process.ProcessPipes ?
On Mon, 16 Nov 2015 23:08:46 +, opla wrote: > Does anyone know if it's possible to monitor the events that happen on > the output stream of a piped process ? > > I'm stuck on doc: > > - https://www.win.tue.nl/~aeb/linux/lk/lk-12.html - > http://www.ibm.com/developerworks/library/l-ubuntu-inotify/ > - http://linux.die.net/man/2/inotify_add_watch > > inotify_add_watch second argument seems to be a file name. The only > thing available is a std.stdio.File with a handle. > > The goal is to create an asynchronous process with a least one > notification that would happen when the process terminates, maybe when > the output stream is written too. You can use poll on the file descriptor (which can be gotten with File.fileno). Basically something like this (untested): while (ImWaiting) { if (processPipes.stdout.eof) { // The child is done writing (has exited, generally speaking) } //TODO set up poll items pollfd pfd = { processPipes.stdout.fileno, POLLIN }; // Use 0 for timeout so that we don't wait; if you don't have anything else // to do, you can use a real timeout value if (1 == poll(, 1, 0)) { // New data is available on the child's stdout, do something with it } // Do other things, sleep, etc. }
Re: writef format specifier error message
On Tuesday, 17 November, 2015 03:49 AM, Ali Çehreli wrote: On 11/16/2015 10:56 AM, ric maicle wrote: I accidentally typed an extra asterisk in the format specifier. I know that it is wrong but the error isn't clear about what and where the error is. import std.stdio; void main() { writef("%*10s", 100); } and I got the following error message(s): $ dmd -run writef.d std.format.FormatException@std/format.d(978): $ expected That message can be improved. Please open a bug report: https://issues.dlang.org/enter_bug.cgi Thank you, Ali Filed: https://issues.dlang.org/show_bug.cgi?id=15348
Re: How to use readText to read utf16 file?
On Tuesday, 17 November 2015 at 02:42:29 UTC, Adam D. Ruppe wrote: On Tuesday, 17 November 2015 at 02:40:14 UTC, Domain wrote: How to use readText to read utf16 file? readText!wstring("filename") should do it for utf16. It will return a wstring, which is utf-16. You can do utf32 with readText!dstring. The default, of course, is string, which is utf8. It doesn't support conversions or any other encoding. Thanks! But how to remove BOM? Slice the result myself?
Re: How to use readText to read utf16 file?
On Tuesday, 17 November 2015 at 02:50:44 UTC, Domain wrote: Thanks! But how to remove BOM? Slice the result myself? Yeah. Do something like if(result.length &[0] == bom) { result = result[1..$]; } and you'll have it.
Re: How to use readText to read utf16 file?
On 11/16/15 10:00 PM, Adam D. Ruppe wrote: On Tuesday, 17 November 2015 at 02:50:44 UTC, Domain wrote: Thanks! But how to remove BOM? Slice the result myself? Yeah. Do something like if(result.length &[0] == bom) { result = result[1..$]; } and you'll have it. To be technically correct, you can do: if(!result.empty && result.front == bom) result.popFront(); This should work for all 3 types of strings. -Steve
How to use readText to read utf16 file?
How to use readText to read utf16 file? Or other encoding file.
Re: How to use readText to read utf16 file?
On Tuesday, 17 November 2015 at 02:40:14 UTC, Domain wrote: How to use readText to read utf16 file? readText!wstring("filename") should do it for utf16. It will return a wstring, which is utf-16. You can do utf32 with readText!dstring. The default, of course, is string, which is utf8. It doesn't support conversions or any other encoding.
Re: How to use readText to read utf16 file?
On Tuesday, 17 November 2015 at 03:12:47 UTC, Steven Schveighoffer wrote: On 11/16/15 10:00 PM, Adam D. Ruppe wrote: On Tuesday, 17 November 2015 at 02:50:44 UTC, Domain wrote: Thanks! But how to remove BOM? Slice the result myself? Yeah. Do something like if(result.length &[0] == bom) { result = result[1..$]; } and you'll have it. To be technically correct, you can do: if(!result.empty && result.front == bom) result.popFront(); This should work for all 3 types of strings. -Steve Thank you! Now another question: how to handle endianness?
Re: Any D IDE on Mac OSX with debugging support?
On 2015-11-16 08:48, Rikki Cattermole wrote: On recent versions of OSX, Apple has by default made it so that all applications must be signed by default. You can disable this behavior through system settings and security. I suspect this is what is stopping it. Alternatively use LLDB shipped with Xcode. But that won't of course have the D support that GDB has. Although I don't know if that works for OS X. -- /Jacob Carlborg
Re: Epoch time + msecs
On Saturday, 14 November 2015 at 12:14:42 UTC, Handyman wrote: Of course. That's why I mentioned my purpose of using Clock.currTime(), in the hope I got corrected in using the right and offical seed method which I failed to find, which brings me to another point. Don't docs provide examples on how use (and seed) a generator? http://dlang.org/phobos/std_random.html#.Mt19937
Re: Any D IDE on Mac OSX with debugging support?
On Monday, 16 November 2015 at 07:48:31 UTC, Rikki Cattermole wrote: On 16/11/15 7:45 PM, Vadim Lopatin wrote: [...] On recent versions of OSX, Apple has by default made it so that all applications must be signed by default. You can disable this behavior through system settings and security. I suspect this is what is stopping it. https://answers.uchicago.edu/25481 Thank you! Let me try that.
Re: Epoch time + msecs
On Monday, 16 November 2015 at 10:29:25 UTC, Kagamin wrote: On Saturday, 14 November 2015 at 12:14:42 UTC, Handyman wrote: Of course. That's why I mentioned my purpose of using Clock.currTime(), in the hope I got corrected in using the right and offical seed method which I failed to find, which brings me to another point. Don't docs provide examples on how use (and seed) a generator? http://dlang.org/phobos/std_random.html#.Mt19937 Hmmm... why is `unpredictableSeed` only a `uint`? Surely most PRNGs have more than 32 bits of internal state?
Re: What does the -betterC switch in dmd do?
On 2015-11-16 01:27, Meta wrote: Don't those features require type info? Hmm, now that you mention it. I expected the compiler to give an error as soon as the D runtime was referenced, but that's at least not the case. -- /Jacob Carlborg