Re: Dustmite can't handle my memory segfault
On Thursday, 20 October 2016 at 22:18:20 UTC, Vladimir Panteleev wrote: On Thursday, 20 October 2016 at 21:33:59 UTC, Nordlöw wrote: I need your help here, I'm complete stuck. Vladimir? The exit status of the `./array_ex` call (as seen from bash) is 134. How do I, in Bash, map that exit status to zero, and all other exit statuses to non-zero?
Re: Dustmite can't handle my memory segfault
Next try: dustmite --no-redirect src "dmd -main -unittest -g -debug array_ex container_traits searching_ex && { ./array_ex; } >&log; grep SIGABRT log" but that fails too as Loading src/w3c.html None => /bin/sh: 1: Syntax error: Bad fd number No object.Exception@dustmite.d(270): Initial test fails ??:? _Dmain [0x5c6be8] ??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv [0x62544e] ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x625398] ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() [0x62540a] ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x625398] ??:? _d_run_main [0x625309] ??:? main [0x61732d] ??:? __libc_start_main [0x8b69a82f] I can't get ! operator to work either.
Re: Static Length Propagation of Ranges
On Thursday, 20 October 2016 at 12:38:40 UTC, Nordlöw wrote: On Wednesday, 19 October 2016 at 19:39:46 UTC, Nordlöw wrote: On Wednesday, 19 October 2016 at 19:01:50 UTC, Meta wrote: https://goo.gl/t9m3YK I'm actually pretty impressed that this kind of code can be written in D. Thanks! Add at https://github.com/nordlow/phobos-next/blob/master/src/algorithm_ex.d#L2234 Made it even modular by factoring out arrayN at https://github.com/nordlow/phobos-next/blob/master/src/algorithm_ex.d#L2200 and used at https://github.com/nordlow/phobos-next/blob/master/src/algorithm_ex.d#L2215 Code: ElementType!R[n] arrayN(size_t n, R)(R r) { assert(r.length == n); typeof(return) dst; import std.algorithm.mutation : copy; r.copy(dst[]); return dst; } typeof(fun(E.init))[n] map(alias fun, E, size_t n)(const E[n] src) { import std.algorithm.iteration : map; return src[].map!fun.arrayN!n; } @safe pure nothrow unittest { import std.meta : AliasSeq; foreach (E; AliasSeq!(int, double)) { enum n = 42; E[n] c; const result = map!(_ => _^^2)(c); static assert(c.length == result.length); static assert(is(typeof(result) == const(E)[n])); } } Here's my variation on the theme. The main difference being that instead of eagerly evaluating the range I wrap it with additional static information. Unfortunately, (AFAIK) Phobos does not take advantage of ranges with statically known length, similarly to how it handles ranges with `enum bool empty = false`. void main() { import std.stdio; int[3] sarr = [1, 2, 3]; auto r1 = sarr.staticLengthRange; static assert (isInputRange!(typeof(r1))); static assert (r1.length == 3); writeln(r1); auto arr = [1, 2, 3, 4]; auto r2 = arr.map!(a => a * 2).staticLengthRange!4; static assert (r2.length == 4); writeln(r2); } import std.algorithm.iteration : map; import std.range.primitives : hasLength, isInputRange; // Note: this overload has questionable memory safety :( // Would be quite cool if DIP1000 could support this use case auto staticLengthRange(T, size_t n)(ref T[n] arr) { return .staticLengthRange!(n, T[])(arr[]); } auto staticLengthRange(size_t n, R)(R range) if (isInputRange!R && hasLength!R) { struct Result { enum size_t length = n; R _range; alias _range this; } assert (range.length == n); return Result(range); } auto staticLengthRange(size_t n, R)(R range) if (isInputRange!R && hasLength!R) { struct Result { enum size_t length = n; R _range; alias _range this; } assert (range.length == n); return Result(range); }
Reflection: Order of fields guaranteed?
When using reflection to obtain the fields of a class/struct, is there any guarantee that the order is the same as the order the fields are defined?
Re: Reflection: Order of fields guaranteed?
On Friday, 21 October 2016 at 01:34:44 UTC, Nick Sabalausky wrote: When using reflection to obtain the fields of a class/struct, is there any guarantee that the order is the same as the order the fields are defined? Yes they should always come in lexical order.
Re: Meta-programming detecting anonymous unions inside structs.
On 21/10/2016 8:55 PM, TheFlyingFiddle wrote: I am trying to port a serialization library I wrote in Lua some time ago. I've ran into a problem relating to types with anonymous unions inside. Given this code: enum Kind { none = 0, array, integer, floating, } struct Foo { Kind type; union { ulong integer; double floating; void[] array; } int nonUnionField; //... } How can I tell that "integer", "floating" and "array" are part the union while "nonUnionField" is not? Thanks in advance. You're gonna have to use UDA's for that.
Meta-programming detecting anonymous unions inside structs.
I am trying to port a serialization library I wrote in Lua some time ago. I've ran into a problem relating to types with anonymous unions inside. Given this code: enum Kind { none = 0, array, integer, floating, } struct Foo { Kind type; union { ulong integer; double floating; void[] array; } int nonUnionField; //... } How can I tell that "integer", "floating" and "array" are part the union while "nonUnionField" is not? Thanks in advance.
Re: Meta-programming detecting anonymous unions inside structs.
On Friday, 21 October 2016 at 07:56:27 UTC, rikki cattermole wrote: You're gonna have to use UDA's for that. Yes, to do the serialization you're right. But my usecase for this is for error reporting. Basically any struct that contains unions without serialization instructions cannot be serialized and I want to make such structures errors. So when I try to serialize the example struct Foo. It should assert with something along the lines of: "Don't know how to serialize overlapping fields: "Foo.integer", "Foo.floating" and "Foo.array".
Re: Meta-programming detecting anonymous unions inside structs.
On 21/10/2016 9:13 PM, TheFlyingFiddle wrote: On Friday, 21 October 2016 at 07:56:27 UTC, rikki cattermole wrote: You're gonna have to use UDA's for that. Yes, to do the serialization you're right. But my usecase for this is for error reporting. Basically any struct that contains unions without serialization instructions cannot be serialized and I want to make such structures errors. So when I try to serialize the example struct Foo. It should assert with something along the lines of: "Don't know how to serialize overlapping fields: "Foo.integer", "Foo.floating" and "Foo.array". I suppose you could use .offsetof to determine this.
Re: Meta-programming detecting anonymous unions inside structs.
On Friday, 21 October 2016 at 08:18:58 UTC, rikki cattermole wrote: On 21/10/2016 9:13 PM, TheFlyingFiddle wrote: On Friday, 21 October 2016 at 07:56:27 UTC, rikki cattermole wrote: You're gonna have to use UDA's for that. Yes, to do the serialization you're right. But my usecase for this is for error reporting. Basically any struct that contains unions without serialization instructions cannot be serialized and I want to make such structures errors. So when I try to serialize the example struct Foo. It should assert with something along the lines of: "Don't know how to serialize overlapping fields: "Foo.integer", "Foo.floating" and "Foo.array". I suppose you could use .offsetof to determine this. This is what I was looking for. Thanks!
DLang/Wiki/'Hello World'/Run Code/Disassembly
Code ran with expected output, but Disassembly seemed to go in a loop?
Re: DLang/Wiki/'Hello World'/Run Code/Disassembly
On Friday, 21 October 2016 at 08:58:50 UTC, DLearner wrote: Code ran with expected output, but Disassembly seemed to go in a loop? What makes you think that? It's hard to tell if you don't give any information. Let's do that! I'll use only naive flags and all and use radare2 to disassemble the main D function which is _Dmain (the entry point has to launch the runtime etc... we aren't very interested in that): $ cat >test.d <│ 0x08077e73 b9d02b0a08 mov ecx, str.Hello_World_; "Hello World!" @ 0x80a2bd0 │ 0x08077e78 b80c00 mov eax, 0xc │ 0x08077e7d 51 push ecx │ 0x08077e7e 50 push eax │ 0x08077e7f e80400 call sym._D3std5stdio16__T7writelnTAyaZ7writelnFNfAyaZv │ 0x08077e84 31c0 xor eax, eax │ 0x08077e86 5d pop ebp └ 0x08077e87 c3 ret No loop. Not even a jump. I'm in x86 so arguments are simply pushed on the stack. No brainer.
Re: Dustmite can't handle my memory segfault
On Friday, 21 October 2016 at 06:44:54 UTC, Nordlöw wrote: On Thursday, 20 October 2016 at 22:18:20 UTC, Vladimir Panteleev wrote: On Thursday, 20 October 2016 at 21:33:59 UTC, Nordlöw wrote: I need your help here, I'm complete stuck. Vladimir? The exit status of the `./array_ex` call (as seen from bash) is 134. How do I, in Bash, map that exit status to zero, and all other exit statuses to non-zero? Solution construct a Bash script named, say show-segfault: #!/usr/bin/env python3 import sys import pty stat = pty.spawn(sys.argv[1:]) if stat == 256: exit(42)# remap to 42 else: exit(stat) and wrap call to rdmd as show-segfault rdmd ...
Re: SQLite
On Wednesday, 19 October 2016 at 16:01:37 UTC, Alfred Newman wrote: Hello, I am trying to handle a SQLite3 table with D. During my researchs, I discovered the lib https://dlang.org/phobos/etc_c_sqlite3.html. However, for any reason, there is no code snippets or sample codes available there. So, I am stucked. I have the following sample structure table: sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " \ "VALUES (1, 'Paul', 32, 'California', 2.00 ); " \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) " \ "VALUES (2, 'Allen', 25, 'Texas', 15000.00 ); " \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \ "VALUES (3, 'Teddy', 23, 'Norway', 2.00 );" \ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \ "VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 );"; Can you pls provide a code snippet or some hints to the following job: - Create a table with the layout above - Iterate through the records given a basic SELECT WHERE Query Thanks in advance, AN Snippet how to do it using DDBC library https://github.com/buggins/ddbc import ddbc; string url = "sqlite:testdb.sqlite"; // creating Connection auto conn = createConnection(url); scope(exit) conn.close(); // creating Statement auto stmt = conn.createStatement(); scope(exit) stmt.close(); // execute simple queries to create and fill table stmt.executeUpdate("CREATE TABLE COMPANY (ID int, NAME varchar, AGE int,ADDRESS varchar, SALARY double)"); string[] statements = [ "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, 'Paul', 32, 'California', 2.00 )", "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (2, 'Allen', 25, 'Texas', 15000.00 )", "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (3, 'Teddy', 23, 'Norway', 2.00 )" ]; foreach(sql; statements) stmt.executeUpdate(sql);
dmd 2.072.0 beta 2 no size because of forward reference
Hey, the code bellow compiles with dmd 2.071.2, but doesn't compile with the same command with dmd 2.072.0 beta2. Maybe someone knows what's going wrong or whether it is a bug in 2.071.2/2.072.0 (it is a reduced part from memutils): app.d: import memutils.utils; struct HashMap(Key, Value) { int[] m_table; // NOTE: capacity is always POT ~this() { freeArray!(int)(m_table); } } -- module memutils.allocators; final class FreeListAlloc() { import memutils.utils : MallocAllocator; } -- module memutils.utils; import memutils.allocators; final class MallocAllocator { } final class AutoFreeListAllocator() { FreeListAlloc!()[12] m_freeLists; } alias LocklessAllocator = AutoFreeListAllocator!(); R getAllocator(R)() { return new R; } void freeArray(T)(auto ref T[] array) { auto allocator = getAllocator!(LocklessAllocator); // freeing. Avoid allocating in a dtor } The command to compile: dmd -c -Imemutils/ app.d -of/dev/null Builds with the latest stable. Fails with the beta: memutils/utils.d(9): Error: class memutils.utils.AutoFreeListAllocator!().AutoFreeListAllocator no size because of forward reference memutils/utils.d(14): Error: template instance memutils.utils.AutoFreeListAllocator!() error instantiating memutils/utils.d(11): Error: template instance memutils.allocators.FreeListAlloc!() error instantiating memutils/utils.d(14):instantiated from here: AutoFreeListAllocator!() app.d(9): Error: template instance memutils.utils.freeArray!int error instantiating app.d(13):instantiated from here: HashMap!(int, uint) Compiles with the lates beta if: dmd -c -Imemutils/ memutils/* app.d -of/dev/null
Is this a bug ?
This very simple stuff: class Item { alias children this; Item[] children; void populate() { children ~= new Item; assert(children.length == 1); } } void main() { Item root = new Item; root.populate; } leads to an assertion failure. Am I too tired to see the error or do you think it's a bug ?
Re: dmd 2.072.0 beta 2 no size because of forward reference
https://github.com/dlang/dmd/pull/5500 maybe this
Re: Is this a bug ?
On 10/21/2016 06:55 PM, Basile B. wrote: This very simple stuff: class Item { alias children this; Item[] children; void populate() { children ~= new Item; assert(children.length == 1); } } void main() { Item root = new Item; root.populate; } leads to an assertion failure. Am I too tired to see the error or do you think it's a bug ? Bug. `alias this` is tried too eagerly. What happens: The alias this of `new Item` is evaluated, leading to `children ~= [];`.
Re: DLang/Wiki/'Hello World'/Run Code/Disassembly
On Friday, 21 October 2016 at 09:07:35 UTC, cym13 wrote: On Friday, 21 October 2016 at 08:58:50 UTC, DLearner wrote: [...] What makes you think that? It's hard to tell if you don't give any information. I pressed the 'Run' button and got the 'Hello World'. I pressed the 'Disassembly' button and got...nothing.
Re: DLang/Wiki/'Hello World'/Run Code/Disassembly
Dne 21.10.2016 v 21:03 DLearner via Digitalmars-d-learn napsal(a): On Friday, 21 October 2016 at 09:07:35 UTC, cym13 wrote: On Friday, 21 October 2016 at 08:58:50 UTC, DLearner wrote: [...] What makes you think that? It's hard to tell if you don't give any information. I pressed the 'Run' button and got the 'Hello World'. I pressed the 'Disassembly' button and got...nothing. Okey so some page does not work correctly, and you think this? Wow :D you should try one of these this pages http://asm.dlang.org http://d.godbolt.org
Re: DLang/Wiki/'Hello World'/Run Code/Disassembly
On Friday, 21 October 2016 at 19:03:30 UTC, DLearner wrote: On Friday, 21 October 2016 at 09:07:35 UTC, cym13 wrote: On Friday, 21 October 2016 at 08:58:50 UTC, DLearner wrote: [...] What makes you think that? It's hard to tell if you don't give any information. I pressed the 'Run' button and got the 'Hello World'. I pressed the 'Disassembly' button and got...nothing. That's a problem about the debugger/disassembler that you use, not about D. We can't do anything else to help as you give no information. See my post: - I gave the exact source code - I gave the compiler that I used with all its flags - I explained what tool I used to analyse it, what I was analysing exactly and how - At each step I gave the exact output of the tools with potential errors This means this is reproducible. Anybody can try it at home and check for himself that it works. There is *no way* to fix a bug that we can't reproduce, and there is *no way* to reproduce it unless we have all the informations stated above.
Re: DLang/Wiki/'Hello World'/Run Code/Disassembly
On Friday, 21 October 2016 at 19:27:59 UTC, cym13 wrote: On Friday, 21 October 2016 at 19:03:30 UTC, DLearner wrote: [...] That's a problem about the debugger/disassembler that you use, not about D. We can't do anything else to help as you give no information. See my post: - I gave the exact source code - I gave the compiler that I used with all its flags - I explained what tool I used to analyse it, what I was analysing exactly and how - At each step I gave the exact output of the tools with potential errors This means this is reproducible. Anybody can try it at home and check for himself that it works. There is *no way* to fix a bug that we can't reproduce, and there is *no way* to reproduce it unless we have all the informations stated above. Apologies, I didn't understand that you put all that in the title.
Phobos lacks a particular family of range functions...
They would have for constraint `if (isInputRange!Range && isInputRange!(ElementType!Range))` In case you wouldn't see directly what would they be used for, it's for tree-like structures. Each element in a Range is also an input range. I see 3 obvious functions/templates - the most important, make an input range from a tree-like range, e.g `auto treeRange(Range, DepthMode mode)(Range range) ` - a second version for bidir ranges, e.g `reverseTreeRange` - a functional iteration algorithm: auto `deepIterate(alias Fun, DepthMode mode, Range, A...)(Range range, auto ref A a)`, which applies Fun to each element with the ability for Fun to act as a predicates to stop the iteration. Actually I have this one in my user library (this is also the reason why I post this today). Unless I'm blind I cannot see anything that handles trees with a range interface in phobos.
Re: Render SVG To Display And Update Periodically
I've tinkered with what you proposed. In the process I've worked through a variety of errors and ended up doing things I don't think are a good solution like duplication directories so that a library can be found. Let me see if I understand how to piece together a build. Some combination of three things need to be in agreement: 1 - the import statements need to point to a matching directory structure 2 - the directory structure needs to be arranged such that the imports can be found 3 - the compiler can be told directly on the command line where imports are I'm reading https://wiki.dlang.org/Compiling_and_linking_with_DMD_on_Windows which seems to be the document I need to sort through this. I'll close out with this last question and then go study up. Am I barking up the right tree?
Re: Render SVG To Display And Update Periodically
On Friday, 21 October 2016 at 23:16:55 UTC, Jason C. Wells wrote: I've tinkered with what you proposed. In the process I've worked through a variety of errors and ended up doing things I don't think are a good solution like duplication directories so that a library can be found. Let me see if I understand how to piece together a build. Some combination of three things need to be in agreement: 1 - the import statements need to point to a matching directory structure 2 - the directory structure needs to be arranged such that the imports can be found 3 - the compiler can be told directly on the command line where imports are I'm reading https://wiki.dlang.org/Compiling_and_linking_with_DMD_on_Windows which seems to be the document I need to sort through this. I'll close out with this last question and then go study up. Am I barking up the right tree? Yes. The compiler needs to know where to find the imports you use in the form of D source files or import modules (.di). Additionally, the linker needs to know which object files or libraries it needs to combine with your compiled source to create the executable, be they generated from D code or C or C++, and where to find them. By default, the compiler knows where to find the Phobos and DRuntime modules and also that it needs to pass phobos.lib (which also includes the DRuntime objects) to the linker, so you never have to specify those. Any other modules you import besides your own need to be handled in one of the following ways: * They can be passed directly to the compiler along with your own source. This will cause them to be compiled and ultimately linked into the resulting binary. * The compiler can be told where to find the source to those modules with the -I command line switch. This *does not* cause them to be compiled. The compiler will only parse them when one is imported so that it can determine which symbols are available in the module it is currently compiling. You will still need to ensure those third-party modules are compiled separately and given to the linker. Here's are a couple examples of the second approach, using the following directory structure: - libraries -- import --- arsd color.d terminal.d -- lib - myprojects -- foo --- foo.d Since Adam doesn't package the arsd stuff as a lib, you'll need to compile them yourself. cd libraries dmd -lib arsd/color.d arsd/terminal.d -odlib -ofarsd.lib The -lib switch tells the compiler to create a library after it has compiled the files. The -od switch tells it to write the library in the lib directory and -od says the file name should be arsd.lib. This will result in the file libraries/lib/arsd.lib. Alternatively, you could do this: dmd arsd/color.d arsd/terminal.d -odlib This will create lib/color.obj and lib/terminal.obj. It's easier to just create the library, which is an archive of both object files. If you intend to use the Visual Studio linker, you will need to ensure you compile the library with the same flags you will use to compile the program (-m64 or -m32mscoff). Now, assuming foo.d is the same code from my last post, cd into the myprojects/foo directory and do the following: dmd -I../../import foo.d ../../lib/arsd.lib gdi32.lib user32.lib The -I switch tells the compiler where it can find imports. It should always be the parent directory of the *package* you want to import. In this case, the package is arsd. A common mistake is to give import/arsd to the compiler. In this case, I've passed the full path to the library because that's the easiest thing to do on Windows. It's possible to tell the linker which path to look in by using DMD's -L switch (which passes options directly to the linker), but OPTLINK and the MS linker use different switches for that. It's simpler just to pass the full path. On Linux/Mac/*BSD, the extensions would be different: .obj -> .o, .lib -> .a. arsd.lib should be named libarsd.a. And the command line would look different as well: dmd -I../../import foo.d -L-L../../lib -L-larsd The -L switch is what you use to pass options to the linker. The first one, -L-L, gives the linker -L option, which on those systems tells the it append ../../lib to the library search path. The second one, -L-l (that's a lower-case 'L'), tells the linker to link with the library libarsd.a. You also need to link with any system dependencies the arsd modules have on those systems.
Re: Render SVG To Display And Update Periodically
On Saturday, 22 October 2016 at 01:31:25 UTC, Mike Parker wrote: * They can be passed directly to the compiler along with your own source. This will cause them to be compiled and ultimately linked into the resulting binary. That's what I recommend. Just dmd yourfile.d yourotherfiles.d color.d simpledisplay.d whatever_other_of_my_or_ketmars_files_you_use.d That just works consistently.
Re: Render SVG To Display And Update Periodically
First, thank you for taking the time to help me with something that should be trivial. I've done the above listing of file on the command line but I'm still stuck. I'm starting to think that I might actually be tripping over bugs, but I'm not confident enough to believe that without some confirmation. I have the following directory structure from the zipfiles found in the repositories posted by ketmar. nanovg_demo - iv (was renamed from nanovg based on dmd error messages) -- arsd (was renamed from arsd-master based on dmd error messages) To proceed, I would attempt a compile. Then I would add the file that was producing an error to the command line and try again. I got this far. Via cmd.exe: nanovg_demo>dmd example.d iv\arsd\color.d iv\arsd\simpledisplay.d iv\perf.d iv\perf.d(41): Error: module iv.nanovg.nanovg from file iv\nanovg.d must be imported with 'import iv.nanovg.nanovg;' demo.d(6): Error: module iv.nanovg.nanovg from file iv\nanovg.d must be imported with 'import iv.nanovg.nanovg;' iv/nanovg/nanovg does not exist in the source code zip files. (I was reluctant to duplicate nanonvg into iv\nanovg because somewhere I learned that copy-pasting code is a bad idea.) demo.d(7): Error: module oui is in file 'iv\nanovg\oui.d' which cannot be read oui.d does not exist anywhere. There is, however, a oui directory. As a side note, I did have some success. I am able to compile nanovg.lib quite easily (from tips provided a few messages ago). It's when I try to compile the demo that I get stuck. Regards, Jason C. Wells
New to D
Hello, Im a 3rd year Comp Sci student in Edmonton Alberta, Canada. Ive learned how to use C, and dabbled in C++ in school. Im also in a Oop course using Java. I picked up the book The D Programming Language by Alexrei Alexandrescu a few years ago. Lately Im really wanting to get into D, as It seems like a better version of C, and feels like java in a way. However; Ive run into a bit of a problem while writing some code. Im not sure if Im doing something wrong, or maybe the things Im using are depreciated?? Code Blocks does not give any messages as to what is going wrong. I haven't configured anything, and am not familiar with messing around with IDE settings. Its directly based off of the example on page 8. here is the code that does not compile: import std.stdio, std.string; void main() { ... } void dict() { uint[string] dictionary; foreach(line; stdin.byLine()) { //chunk = splitter(strip(line); ## errors because of splitter foreach(word; splitter(strip(line))) { ## errors because of splitter ?? if(word in dictionary) continue; //writeln(dictionary.length); ## gives 0 ?? auto newID = dictionary.length; dictionary[word] = newId; writeln(newID, ' ', word); } } } Im not sure what Im doing wrong here. modifying the code to just print the result of splitLines results in the entire line. and just having splitter give a sting to print also errors. Please help, thanks!
Re: New to D
On 22/10/2016 6:25 PM, Mark wrote: Hello, Im a 3rd year Comp Sci student in Edmonton Alberta, Canada. Ive learned how to use C, and dabbled in C++ in school. Im also in a Oop course using Java. I picked up the book The D Programming Language by Alexrei Alexandrescu a few years ago. Lately Im really wanting to get into D, as It seems like a better version of C, and feels like java in a way. Things have changed since TDPL was created but here is the errata which says what[0]. However; Ive run into a bit of a problem while writing some code. Im not sure if Im doing something wrong, or maybe the things Im using are depreciated?? Code Blocks does not give any messages as to what is going wrong. I haven't configured anything, and am not familiar with messing around with IDE settings. Its directly based off of the example on page 8. here is the code that does not compile: import std.stdio, std.string; void main() { ... } void dict() { uint[string] dictionary; foreach(line; stdin.byLine()) { //chunk = splitter(strip(line); ## errors because of splitter foreach(word; splitter(strip(line))) { ## errors because of splitter ?? if(word in dictionary) continue; //writeln(dictionary.length); ## gives 0 ?? auto newID = dictionary.length; dictionary[word] = newId; writeln(newID, ' ', word); } } } Im not sure what Im doing wrong here. modifying the code to just print the result of splitLines results in the entire line. and just having splitter give a sting to print also errors. Please help, thanks! Oh splitter is in std.algorithm.iteration[1]. Import it and it should work. [0] http://erdani.com/tdpl/errata/ [1] http://dlang.org/phobos/std_algorithm_iteration.html#.splitter
Re: New to D
Thanks for the fast reply. That did work. But now the error is on the line: dictionary[word] = newId; I changed the value to 10, still errors. ?? everything else is as before. thanks.
Re: New to D
On Saturday, 22 October 2016 at 05:41:34 UTC, Mark wrote: Thanks for the fast reply. That did work. But now the error is on the line: dictionary[word] = newId; I changed the value to 10, still errors. ?? everything else is as before. thanks. For simple single file experiments like this, I strongly recommend you ditch Code::Blocks (or any IDE) and just use a text editor + the command line. All you need is the compiler on the path, then you can do this: dmd foo.d Any errors will be shown right in the console. Try that out then come back and post the error messages you see. Preferably something more informative than "the error is on the line" :)
Re: Render SVG To Display And Update Periodically
On Saturday, 22 October 2016 at 03:59:16 UTC, Jason C. Wells wrote: First, thank you for taking the time to help me with something that should be trivial. I've done the above listing of file on the command line but I'm still stuck. I'm starting to think that I might actually be tripping over bugs, but I'm not confident enough to believe that without some confirmation. I think I can confidently assure you that you aren't running into any bugs here. I have the following directory structure from the zipfiles found in the repositories posted by ketmar. nanovg_demo - iv (was renamed from nanovg based on dmd error messages) -- arsd (was renamed from arsd-master based on dmd error messages) To proceed, I would attempt a compile. Then I would add the file that was producing an error to the command line and try again. I got this far. Via cmd.exe: nanovg_demo>dmd example.d iv\arsd\color.d iv\arsd\simpledisplay.d iv\perf.d iv\perf.d(41): Error: module iv.nanovg.nanovg from file iv\nanovg.d must be imported with 'import iv.nanovg.nanovg;' demo.d(6): Error: module iv.nanovg.nanovg from file iv\nanovg.d must be imported with 'import iv.nanovg.nanovg;' iv/nanovg/nanovg does not exist in the source code zip files. (I was reluctant to duplicate nanonvg into iv\nanovg because somewhere I learned that copy-pasting code is a bad idea.) looking at kemar's repository, the nanovg.d module belongs to the iv.nanovg package. I don't know what the zip directory tree looks like, but you should have this: - iv -- nanovg --- fui --- nanovg.d --- oui --- package.d --- perf.d --- svg.d As for the asrd stuff, it shouldn't bee in the iv tree at all. You should do something like this: - import -- iv -- arsd Both iv and arsd are top-level packages, so they ought to be independent of each other. demo.d(7): Error: module oui is in file 'iv\nanovg\oui.d' which cannot be read oui.d does not exist anywhere. There is, however, a oui directory. If you look at the source for demo.d, you'll see that it makes use of the oui package. That means the everything there also needs to be compiled and linked into the binary, but you haven't given those files to the compiler. As a side note, I did have some success. I am able to compile nanovg.lib quite easily (from tips provided a few messages ago). It's when I try to compile the demo that I get stuck. Which files did you add into nanovg.lib? Everything in the iv.nanovg packages and subpackages, or just the ones you use directly? It's best to compile all of them into the lib, then any that are used indirectly by each other are also available. You've dived right into a multi-module projects without a full understanding of imports and linking. I suggest you back up a bit and get familiar with the process before tackling ketmar and Adam's stuff. If they used dub, it would be a very easy process. Since they don't, and you have to manage it all manually, you need a solid understanding of how DMD handles this stuff and why you are getting the error messages you see. Try playing around with simple single-function modules, starting with something like this: io.d: ``` void print(string s) { import std.stdio : writeln; writeln(s); } ``` main.d: ``` import io; void main() { print("Hello, D!"); } ``` Compile both: dmd main.d io.d Compile separately: dmd -c io.d dmd main.d io.obj Move the io.d module into a package, mylib.io: - main.d -- mylib --- io.d Add a module statement to the top of io.d: ``` module mylib.io; ``` Change the import in main.d: ``` import mylib.io; ``` Try again compiling together, then separately. Then move the mylib directory: - main.d -- lib --- mylib io.d Then compile together and separately again. Try with and without -Ilib in both cases and see what happens. Add another single-function module into the mix. Compile mylib as a library and try again. Just keep experimenting like this until you've worked out exactly what's going on and what the error messages mean. Then you can tackle the naonvg and arsd.