Can anybody install DDT on Eclipse Neon or Mars?

2016-06-18 Thread Mark via Digitalmars-d-learn
I've spent may hours trying to do this in OSX. Everything goes fine from the marketplace window...until I restart Eclipse and find no files have been added? Any words of consolation or advice will be greatly appreciated. Desperately, Mark

Re: Is TDPL an accurate description of the D language today?

2016-09-28 Thread Mark via Digitalmars-d-learn
OK. Thanks, Steve.

Is TDPL an accurate description of the D language today?

2016-09-27 Thread Mark via Digitalmars-d-learn
I've been going through Andrei's excellent book and I noticed that the latest printing is from 2010. Since D is still a very young language I can imagine it changing quite a bit within six years. So I wonder if there are any major inconsistincies between the current state of the language and

New to D

2016-10-21 Thread Mark via Digitalmars-d-learn
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

Re: New to D

2016-10-21 Thread Mark via Digitalmars-d-learn
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: Is TDPL an accurate description of the D language today?

2016-10-28 Thread Mark via Digitalmars-d-learn
On Tuesday, 27 September 2016 at 17:53:39 UTC, Steven Schveighoffer wrote: On 9/27/16 1:38 PM, Mark wrote: I've been going through Andrei's excellent book and I noticed that the latest printing is from 2010. Since D is still a very young language I can imagine it changing quite a bit within

Need way to compare classes, and primitive types in bst Template

2017-06-08 Thread Mark via Digitalmars-d-learn
Ok. So I have a BST template, and it passes my tests. However, if you look at how I insert the data into the BST, you'll quickly notice the problem I have. https://dpaste.dzfl.pl/ff58876ce213 Keep in mind I just pasted that stack in there because I use it in my last unittest at the bottom.

Re: Trouble with SList for generic Stack class

2017-06-02 Thread Mark via Digitalmars-d-learn
Awesome. That worked. On Friday, 2 June 2017 at 22:30:28 UTC, Stefan Koch wrote: On Friday, 2 June 2017 at 22:21:07 UTC, Mark wrote: Hello, I am trying to make a class that can accept any type as an argument. [...] the stack class needs to be a template as well. This is not java ;)

Trouble with SList for generic Stack class

2017-06-02 Thread Mark via Digitalmars-d-learn
Hello, I am trying to make a class that can accept any type as an argument. Here is the class: import std.container: SList; class Stack { private SList!T list; private int _size; this(T)() { list = SList!T; _size = 0; } public void push(T)(T item) {

Re: How to Compare 2 objects of the same class

2017-06-03 Thread Mark via Digitalmars-d-learn
On Saturday, 3 June 2017 at 19:57:47 UTC, Mark wrote: Hello again. I'm designing a template version of a BST. Because of this, I want to be able to compare if two objects of the same class type are references to the same anonymous class on the heap somewhere. Example: Not sure what

Re: How to Compare 2 objects of the same class

2017-06-03 Thread Mark via Digitalmars-d-learn
On Saturday, 3 June 2017 at 22:52:42 UTC, Mark wrote: Thanks again. Nevermind, I got it.

Re: How to Compare 2 objects of the same class

2017-06-03 Thread Mark via Digitalmars-d-learn
On Saturday, 3 June 2017 at 23:32:44 UTC, Ali Çehreli wrote: ... Ali Awesome, that might be handy in the near future. Thanks.

How to Compare 2 objects of the same class

2017-06-03 Thread Mark via Digitalmars-d-learn
Hello again. I'm designing a template version of a BST. Because of this, I want to be able to compare if two objects of the same class type are references to the same anonymous class on the heap somewhere. Example:

Re: How to Compare 2 objects of the same class

2017-06-03 Thread Mark via Digitalmars-d-learn
On Saturday, 3 June 2017 at 22:38:31 UTC, Mark wrote: ... Thanks. Actually, I got another question, how Can I obtain the actual memory address of a class? I'll still need to solve the problem of taking ints/floats/reals etc., as well as structs and classes and sending them right/left in

Re: How to Compare 2 objects of the same class

2017-06-03 Thread Mark via Digitalmars-d-learn
On Saturday, 3 June 2017 at 20:24:44 UTC, ag0aep6g wrote: By default, they act the same. But you can change how `==` behaves by overriding `opEquals`. You cannot override `is`. Ok. So by using '==' it should compare the addresses of the objects? I think I didn't include the other file as

Re: Trouble with SList for generic Stack class

2017-06-02 Thread Mark via Digitalmars-d-learn
On Friday, 2 June 2017 at 23:34:14 UTC, Ali Çehreli wrote: You've probably seen H. S. Teoh's answer but still... :) ... Ali Awesome, thanks everyone!

Re: Need way to compare classes, and primitive types in bst Template

2017-06-09 Thread Mark via Digitalmars-d-learn
On Friday, 9 June 2017 at 05:53:11 UTC, ag0aep6g wrote: ... Get rid of `real val;` and just compare `payload`s. For classes, you can detect them with `static if (is(T == class))` or some such, and cast to void* when comparing. But when you cast to void*, you're ignoring an opEquals or opCmp

Re: Need way to compare classes, and primitive types in bst Template

2017-06-10 Thread Mark via Digitalmars-d-learn
On Saturday, 10 June 2017 at 14:35:48 UTC, ag0aep6g wrote: ... Just that you shouldn't take my version of addNode and rely on it without double checking that it's correct. Ah, Okay. I rechecked that everything is working. The size is correct, and the membership is correct for every

Re: Need way to compare classes, and primitive types in bst Template

2017-06-09 Thread Mark via Digitalmars-d-learn
Ok. WOW! I was way off. I adapted your code to my BST and it works perfectly. Thanks! I didn't know what static if was. I should experiment with it. For the code that I mentioned, I'd have to retype it. I wrote, tried and deleted those pieces of code several days ago because it really

Re: [OT] Converting booleans to numbers

2017-09-21 Thread Mark via Digitalmars-d-learn
On Wednesday, 20 September 2017 at 19:25:58 UTC, Timon Gehr wrote: Actually, it is useful enough to have a Wikipedia page: https://en.wikipedia.org/wiki/Iverson_bracket Example of a good use: void floodFill(dchar[][] data,dchar c,int i,int j) { void dfs(int a, int b) { if (a<0 ||

Re: "Range invalidation" ?

2017-08-31 Thread Mark via Digitalmars-d-learn
On Wednesday, 30 August 2017 at 15:06:12 UTC, Jonathan M Davis wrote: [...] Thank you for the detailed response.

"Range invalidation" ?

2017-08-30 Thread Mark via Digitalmars-d-learn
C++ has the issue of iterator invalidation, where certain operations on a container while iterating on it may invalidate the iterator, in which case it is no longer safe to use the iterator. D has ranges, but presumably the same issue can arise in D. For instance, if I have a ForwardRange

Parsing a string from stdin using formattedRead

2017-12-06 Thread Mark via Digitalmars-d-learn
std.format has the function formattedRead which can be used to parse a string, e.g. string first_name; string last_name; string info = readln(); formattedRead(info, "%s %s", first_name, last_name); This piece of code works as intended. However, since I don't need the input after it's parsed,

Re: Parsing a string from stdin using formattedRead

2017-12-06 Thread Mark via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 18:57:55 UTC, Ali Çehreli wrote: On 12/06/2017 10:47 AM, Mark wrote: > string info = readln(); > formattedRead(info, "%s %s", first_name, last_name); > > This piece of code works > formattedRead(readln(), "%s %s", first_name, last_name); > > But this raises a

Re: No modification of pointer values in safe functions?

2018-01-04 Thread Mark via Digitalmars-d-learn
On Wednesday, 3 January 2018 at 23:49:33 UTC, H. S. Teoh wrote: On Wed, Jan 03, 2018 at 03:42:07PM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: On Wednesday, January 03, 2018 22:25:16 Mark via Digitalmars-d-learn wrote: [...] > https://dlang.org/spec/function.html#safe-functi

Re: Templates for DRY code

2018-01-08 Thread Mark via Digitalmars-d-learn
On Saturday, 6 January 2018 at 23:32:42 UTC, Paul Backus wrote: On Saturday, 6 January 2018 at 03:38:35 UTC, codephantom wrote: or even.. a.append( s.to!ConvertToElementType(a) ); That's not valid code of course, but the semantics are all contained in that single chunk. This works: import

Templated Binary Search Tree treats class as const, compiler complains

2018-01-21 Thread Mark via Digitalmars-d-learn
Hello, I re wrote my old BST. This one is far more complete and clean. However, It fails my final unittest when I try to stick a class in as its type. Link: https://dpaste.dzfl.pl/95e1ae49b25b Ive done this type of thing before, but it is giving me this error: BinarySearchTree.d(30):

Re: Templated Binary Search Tree treats class as const, compiler complains

2018-01-21 Thread Mark via Digitalmars-d-learn
On Sunday, 21 January 2018 at 20:46:56 UTC, Timon Gehr wrote: On 21.01.2018 21:20, Mark wrote: Just realized that I commented out the creation of the BST new link: https://dpaste.dzfl.pl/ce620cbee919 'in' means 'const scope', but it seems you need references that are allowed to mutate the

Re: Templated Binary Search Tree treats class as const, compiler complains

2018-01-21 Thread Mark via Digitalmars-d-learn
Just realized that I commented out the creation of the BST new link: https://dpaste.dzfl.pl/ce620cbee919

vibe.d compatible with d3 or pixieJS

2018-01-28 Thread Mark via Digitalmars-d-learn
Hello! As the title suggests, I'm looking for the answer to this question. I've searched / asked it on the vibe forums, but nobody has answered. I'm not familiar enough with JS frameworks / vibe to really know how this would (not) work together. I've experimented with vibe, and I would

Re: No modification of pointer values in safe functions?

2018-01-03 Thread Mark via Digitalmars-d-learn
On Wednesday, 3 January 2018 at 22:12:01 UTC, Jonathan M Davis wrote: On Wednesday, January 03, 2018 22:02:22 Mark via Digitalmars-d-learn wrote: The documentation says the modification of pointer values is not allowed in safe functions. Yet the following compiles fine on dmd: void main

No modification of pointer values in safe functions?

2018-01-03 Thread Mark via Digitalmars-d-learn
The documentation says the modification of pointer values is not allowed in safe functions. Yet the following compiles fine on dmd: void main() @safe { int* x = new int; int* y = new int; y=x; } Is this simply a compiler bug?

Putting function pointers / delegates into associative array.

2018-01-03 Thread Mark via Digitalmars-d-learn
What I'm trying to do here is to be able to call a function based off of a key. I'm not sure how to do this, I've been messing around a bit, but the compiler doesn't like what I'm doing. Im getting: test.d(20): Error: cannot implicitly convert expression of type void delegate() to void

Re: How do you do "const nazi" in D?

2018-01-04 Thread Mark via Digitalmars-d-learn
On Wednesday, 3 January 2018 at 17:27:38 UTC, Marc wrote: for a safe programming, since C/C++ times I try to make thing const as possible. locals, parameters etc anything which isn't going to change. How do you do that in D? immutable everywhere? for example: foreach(Field field;

How to convert array of structs to JSON

2019-06-24 Thread mark via Digitalmars-d-learn
I have the following array of structs: struct Person { string name; int age; }; Person people[]; Person p; Person p1 = { "Bob", 12 }; Person p2 = { "Bob", 12 }; people ~= p1; people ~= p2; I've read through the std.json documentation, but I'm still confused as to

Re: Is there a std.zip.ZipArchive isDir or isFile method?

2020-02-11 Thread mark via Digitalmars-d-learn
On Wednesday, 12 February 2020 at 05:59:53 UTC, cc wrote: On Monday, 3 February 2020 at 13:26:38 UTC, mark wrote: I'm using std.zip.ZipArchive to read zip files, e.g.: [snip] I couldn't find one either, I had to do this: version(Windows) { enum uint FILE_ATTRIBUTE_DIRECTORY = 0x10; }

Re: GtkD on Windows: notes + question

2020-02-11 Thread mark via Digitalmars-d-learn
On Tuesday, 11 February 2020 at 20:49:40 UTC, Ron Tarrant wrote: On Sunday, 9 February 2020 at 13:28:59 UTC, mark wrote: I found a much easier way to get GtkD working on windows than that described in https://gtkdcoding.com/2019/01/11/-introduction-to-gtkDcoding.html Just FYI... I don't

How to compile with GtkD

2020-02-09 Thread mark via Digitalmars-d-learn
According to the GtkD web site https://gtkd.org/ this GUI library is cross-platform, so hopefully just what I need. The introductory blog https://gtkdcoding.com/2019/01/11/-introduction-to-gtkDcoding.html explains how to install and get started with GtkD on Windows (which I plan to use

A D implementation of the Python difflib module's sequence matcher.

2020-02-12 Thread mark via Digitalmars-d-learn
I've just completed my first D package: http://code.dlang.org/packages/ddiff It is a straight port, so it isn't at all functional-style. I'd be happy and interested if anyone could show me how to replace some/all of the for[each] loops (without reducing performance), or for any other code

Some impressions/notes from a new D programmer

2020-02-12 Thread mark via Digitalmars-d-learn
I've been learning D for a few weeks now. I'm an experienced programmer in other languages (esp. Python, but also Rust and C++). Here're some *early* impressions and notes. D Tour I found the D Tour, esp. "D's Basics" to be very helpful. Each part is short and in most cases understandable.

Dscanner: is it possible to switch off style checks case-by-case?

2020-02-13 Thread mark via Digitalmars-d-learn
I'm starting out with GtkD and have this function: void main(string[] args) { Main.init(args); auto game = new GameWindow(); Main.run(); } and this method: void quit(Widget widget) { Main.quit(); } When I run dscanner --styleCheck it reports:

Re: Some impressions/notes from a new D programmer

2020-02-12 Thread mark via Digitalmars-d-learn
On Wednesday, 12 February 2020 at 11:46:02 UTC, Dennis wrote: Thanks for your perspective. Just a few things are unclear to me: On Wednesday, 12 February 2020 at 10:39:06 UTC, mark wrote: I don't find the presentation of the member properties and methods very easy to read Can you elaborate

Re: Some impressions/notes from a new D programmer

2020-02-12 Thread mark via Digitalmars-d-learn
On Wednesday, 12 February 2020 at 14:15:40 UTC, Adam D. Ruppe wrote: On Wednesday, 12 February 2020 at 10:39:06 UTC, mark wrote: Library Reference Documentation Have you seen my fork? http://dpldocs.info/experimental-docs/std.zip.ZipArchive.html Yours is *much* clearer. However, if you

Re: Some impressions/notes from a new D programmer

2020-02-12 Thread mark via Digitalmars-d-learn
On Wednesday, 12 February 2020 at 18:20:47 UTC, Adam D. Ruppe wrote: On Wednesday, 12 February 2020 at 15:52:35 UTC, mark wrote: Yours rolls the two examples into one and doesn't show the Standards or Usage sections. Weird, that's a legit bug in there. I'll fix them. I also think you split

Re: dscanner and ref parameters

2020-02-23 Thread mark via Digitalmars-d-learn
On Sunday, 23 February 2020 at 09:35:30 UTC, Jacob Carlborg wrote: On 2020-02-23 10:03, mark wrote: Then this would not only help dscanner, but also make it clear to programmers that the argument could be modified. It's not necessary for dscanner. It should look at the signature of

A small D/GtkD example game

2020-02-24 Thread mark via Digitalmars-d-learn
I've just completed a small D/GtkD game. It might be useful for others trying to learn GtkD since it is only just over 1000 lines, yet shows how to create a dialog-style app with a modal dialog and a modeless dialog, and a custom drawn widget, as well as keyboard and mouse handling. The

SQLite 3 support?

2020-02-26 Thread mark via Digitalmars-d-learn
There seems to be some support for SQLite 3 in std. lib. etc when looking at the stable docs: https://dlang.org/phobos/etc_c_sqlite3.html But this isn't visible when looking at stable (ddox). Is this the best SQLite 3 library to use or is a third-party library best? For example

Where are the GSOC 2020 ideas?

2020-02-27 Thread mark via Digitalmars-d-learn
On https://wiki.dlang.org I can find GSOC ideas 2011-2019, but not 2020. I know the 2020 one's haven't been accepted, but I'd like to know what they are in case I feel like having a go at one as part of learning D.

Re: converting to/from char[]/string

2020-03-05 Thread mark via Digitalmars-d-learn
I changed int to size_t and used const(char[]) etc. as suggested. It ran but crashed. Each crash was a range violation, so for each one I put in a guard so instead of if ( ... m_b[m_k]) I used if (m_k < m_b.length && ... m_b[m_k) I did this kind of fix in three places. The result is that

Re: converting to/from char[]/string

2020-03-05 Thread mark via Digitalmars-d-learn
I suspect the problem is using .length rather than some other size property.

Re: converting to/from char[]/string

2020-03-05 Thread mark via Digitalmars-d-learn
On Thursday, 5 March 2020 at 11:12:24 UTC, drug wrote: On 3/5/20 2:03 PM, mark wrote: [snip] Your code and errors seem to be not related. OK, it is probably that the D stemmer is 19 years old! I've now got Martin Porter's own Java version, so I'll have a go at porting that to D myself.

Re: converting to/from char[]/string

2020-03-05 Thread mark via Digitalmars-d-learn
On Thursday, 5 March 2020 at 13:31:14 UTC, Adam D. Ruppe wrote: On Thursday, 5 March 2020 at 11:03:30 UTC, mark wrote: I want to use the Porter stemming algorithm. There's a D implementation here: https://tartarus.org/martin/PorterStemmer/d.txt I think I (or ketmar and I stole it from him)

What does assigning void mean?

2020-03-04 Thread mark via Digitalmars-d-learn
In Adam Ruppe's D Cookbook there're these lines in a ref counting example: RefCountedObject o = void; // What does this mean/do? o.data = new Implementation(); o.data.refcount = 1; I don't understand the first line; could someone explain please?

Re: What does assigning void mean?

2020-03-05 Thread mark via Digitalmars-d-learn
On Thursday, 5 March 2020 at 08:35:52 UTC, drug wrote: On 3/5/20 10:47 AM, mark wrote: In Adam Ruppe's D Cookbook there're these lines in a ref counting example: RefCountedObject o = void; // What does this mean/do? o.data = new Implementation(); o.data.refcount = 1; I don't understand the

converting to/from char[]/string

2020-03-05 Thread mark via Digitalmars-d-learn
I want to use the Porter stemming algorithm. There's a D implementation here: https://tartarus.org/martin/PorterStemmer/d.txt The main public function's signature is: char[] stem(char[] p, int i, int j) But I work entirely in terms of strings (containing individual words), so I want to add

wordladder - code improvement

2020-01-30 Thread mark via Digitalmars-d-learn
Below is a program that produces a wordladder. The algorithm is probably suboptimal, but I don't care since I've implemented the same one in Python, Rust, Go, Java, and Nim, so I find it useful for language comparison purposes. What I'd like some feedback on is how to improve the code

D Cookbook range save question

2020-01-30 Thread mark via Digitalmars-d-learn
In the D Cookbook it has as part of the FibonacciRange example: @property FibonacciRange save() { return this; } And in the description it says: "...save, which returns a new range that is a copy of the current range and can be advanced independently..." Why is this a *copy*? (For a copy

Re: D Cookbook range save question

2020-01-30 Thread mark via Digitalmars-d-learn
On Thursday, 30 January 2020 at 10:31:08 UTC, mark wrote: In the D Cookbook it has as part of the FibonacciRange example: @property FibonacciRange save() { return this; } And in the description it says: "...save, which returns a new range that is a copy of the current range and can be

Re: dub for lib & app?

2020-02-04 Thread mark via Digitalmars-d-learn
On Tuesday, 4 February 2020 at 09:21:17 UTC, Andre Pany wrote: On Tuesday, 4 February 2020 at 09:13:48 UTC, mark wrote: Is it possible to create a dub project that has one library and one or more executables (that use the library)? If so, could someone point me to the docs for this since I

Trying to use a template class with ranges

2020-02-06 Thread mark via Digitalmars-d-learn
I am starting on porting Python's difflib's sequence matcher to D. I want to have a class that will accept two ranges whose elements are of the same type and whose elements can be compared for equality. How do I make a class declaration that specifies a (forward) range type and an

Re: Trying to use a template class with ranges

2020-02-06 Thread mark via Digitalmars-d-learn
I forgot to mention: I want the class to work with: Diff(aForwardRange, bForwardRange) where T = ForwardRange, E = anything that supports == A common use case is for two sequences of strings (i.e., lines read from two files). Diff(aString, bString) where T = char[] or wchar[] or dchar[] E =

Re: Trying to use a template class with ranges

2020-02-06 Thread mark via Digitalmars-d-learn
On Thursday, 6 February 2020 at 15:21:46 UTC, Steven Schveighoffer wrote: [snip] 3. You should declare constraints signifying what types are valid. i.e.: class Diff(T) if ( isForwardRange!T // it's a forward range && is(typeof(T.init.front == T.init.front)) // elements are comparable

Re: Trying to use a template class with ranges

2020-02-06 Thread mark via Digitalmars-d-learn
On Thursday, 6 February 2020 at 16:29:57 UTC, Steven Schveighoffer wrote: On 2/6/20 11:05 AM, mark wrote: src/package.d(50,35): Error: no property opCall for type diffrange.Diff!(dchar[]), did you mean new Diff!(dchar[])? Hah, forgot that it's a class. Yes, I DID mean new Diff ;) -Steve

Re: wordladder - code improvement

2020-01-31 Thread mark via Digitalmars-d-learn
I forgot to mention: I know it isn't worth bothering with const/immutable for this tiny example. But I want to learn how to write large D programs, so I need to get into the right habits and know the right things.

Re: books for learning D

2020-01-31 Thread mark via Digitalmars-d-learn
On Wednesday, 29 January 2020 at 11:57:14 UTC, Jan Hönig wrote: On Monday, 13 January 2020 at 16:37:31 UTC, Ron Tarrant wrote: On Monday, 13 January 2020 at 10:28:48 UTC, mark wrote: I'm just starting out learning D. Andrei Alexandrescu's "The D Programming Language" is 10 years old, so is

Re: wordladder - code improvement

2020-01-31 Thread mark via Digitalmars-d-learn
Thanks for your implementation. I can't use the levenshtien distance because although it is a better solution, I want to keep the implementation as compatible with those in the other languages as possible. Your main() is much shorter than mine, but doesn't match the behaviour (and again I

How do I fix my failed PRs?

2020-02-02 Thread mark via Digitalmars-d-learn
I've done quite a few small corrections/improvements to the D-tour's English. Almost all have been accepted. However, four have not been accepted, apparently for technical reasons. But I don't understand what's wrong or what I need to do to fix them. (I'm not very knowledgeable about github.)

Re: How do I fix my failed PRs?

2020-02-02 Thread mark via Digitalmars-d-learn
On Sunday, 2 February 2020 at 12:49:31 UTC, MoonlightSentinel wrote: On Sunday, 2 February 2020 at 08:54:02 UTC, mark wrote: However, four have not been accepted, apparently for technical reasons. But I don't understand what's wrong or what I need to do to fix them. (I'm not very knowledgeable

Re: How do I fix my failed PRs?

2020-02-03 Thread mark via Digitalmars-d-learn
Thanks Petar... I'm in no hurry, just glad that they're in process:-)

Is there a std.zip.ZipArchive isDir or isFile method?

2020-02-03 Thread mark via Digitalmars-d-learn
I'm using std.zip.ZipArchive to read zip files, e.g.: auto zip = new ZipArchive(read(filename)); // ... foreach (name, member; zip.directory) { if (name.endsWith('/')) // skip dirs continue; mkdirRecurse(dirName(name)); zip.expand(member);

Re: Empty string vs null

2020-02-04 Thread mark via Digitalmars-d-learn
Thanks for that thorough and careful explanation. Since I'm trying to learn to write D in good style and want my code to be reliable and maintainable, I've now switched to using "" rather than null.

Empty string vs null

2020-02-03 Thread mark via Digitalmars-d-learn
I have just discovered that D seems to treat empty and null strings as the same thing: // test.d import std.stdio; import std.string; void main() { string x = null; writeln("x = \"", x, "\""); writeln("null = ", x == null); writeln("\"\"= ", x == ""); writeln("empty

Re: Empty string vs null

2020-02-03 Thread mark via Digitalmars-d-learn
Just found this post by Mark Parker that explains: https://forum.dlang.org/post/gvveit$10i5$1...@digitalmars.com // test.d import std.stdio; import std.string; void main() { report(null, "null"); report(""); report("x"); } void report(const string x, const string name=null) {

dub for lib & app?

2020-02-04 Thread mark via Digitalmars-d-learn
Is it possible to create a dub project that has one library and one or more executables (that use the library)? If so, could someone point me to the docs for this since I couldn't find this in the dub docs? Aside: I'm learning D to give me something approaching the convenience of Python with

Does D have an equvalent of: if (auto = expr; expr)

2020-02-07 Thread mark via Digitalmars-d-learn
Some languages support this kind of thing: if ((var x = expression) > 50) print(x, " is > 50") Is there anything similar in D?

How to use sets in D?

2020-02-07 Thread mark via Digitalmars-d-learn
I am porting code from other languages to D as part of learning D, and I find I've used sets quite a lot. AFAIK D doesn't have a built-in set type or one in the std. lib. However, I've been perfectly successfully using int[E] where E is my ElementType, and adding with set[element] = 0. I

Re: Does D have an equvalent of: if (auto = expr; expr)

2020-02-07 Thread mark via Digitalmars-d-learn
Thanks for the excellent replies.

Re: How to use sets in D?

2020-02-07 Thread mark via Digitalmars-d-learn
On Friday, 7 February 2020 at 22:03:00 UTC, H. S. Teoh wrote: On Fri, Feb 07, 2020 at 07:37:08PM +, mark via Digitalmars-d-learn wrote: [snip] bool[E] works just fine. [snip] Or you can wrap void[0][E] in a nice user-defined type that gives nice set-like syntax. But IMO, this is all

compiler error when trying to get random key from AA

2020-01-25 Thread mark via Digitalmars-d-learn
I have this code: import std.random; import std.stdio; void main() { auto aa = ["one": 1, "two": 2, "three": 3]; writeln(aa); auto rnd = rndGen; auto word = aa.byKey.choice(rnd); writeln(word); } And in the D playground it gives this error: onlineapp.d(8): Error: template

Re: compiler error when trying to get random key from AA

2020-01-25 Thread mark via Digitalmars-d-learn
On Saturday, 25 January 2020 at 08:59:23 UTC, Basile B. wrote: On Saturday, 25 January 2020 at 08:35:18 UTC, mark wrote: I have this code: import std.random; import std.stdio; void main() { auto aa = ["one": 1, "two": 2, "three": 3]; writeln(aa); auto rnd = rndGen; auto word =

Re: compiler error when trying to get random key from AA

2020-01-25 Thread mark via Digitalmars-d-learn
In the end I used this line since I'm not fussy about the rnd for this: auto word = compatibles.byKey.array.choice; Thank you!

GtkD crash

2020-02-21 Thread mark via Digitalmars-d-learn
I'm porting a simple game to GtkD to learn the library and more about D. Unfortunately, I've hit a show-stopping crash. I have a subclass of ApplicationWindow which has this method: private void onChangeState(int score, Board.State state) { import std.format: format;

Re: GtkD crash

2020-02-21 Thread mark via Digitalmars-d-learn
Thanks for your question, it led me to focus on the Label and now I've solved the problem. I thought that onChangeState was never called before the Label was constructed, but it turns out it is called before. So now I use: if (statusLabel !is null)

Re: How to compile with GtkD

2020-02-09 Thread mark via Digitalmars-d-learn
On Sunday, 9 February 2020 at 12:03:23 UTC, Ron Tarrant wrote: On Sunday, 9 February 2020 at 11:52:19 UTC, mark wrote: right now I want to start on Linux and I'm stuck. Maybe this will help... https://gtkdcoding.com/2019/03/31/x0002-gtkd-in-a-linux-environment.html Unfortunately it didn't

Re: How to compile with GtkD [solved]

2020-02-09 Thread mark via Digitalmars-d-learn
Turns out I didn't need to add lines to dub.sdl at all. So my dub.sdl is now just: name "gtktest" description "Gtk Test" authors "Mark" targetType "executable" dependency "gtk-d:gtkd" version=">=3.9.0" The solution was to do this: $ dub add-path ~/opt/GtkD3/ After that it does static builds,

GtkD on Windows: notes + question

2020-02-09 Thread mark via Digitalmars-d-learn
I found a much easier way to get GtkD working on windows than that described in https://gtkdcoding.com/2019/01/11/-introduction-to-gtkDcoding.html 1. I downloaded and installed the Gtk3 runtime (the link is on https://gtkdcoding.com/2019/01/11/-introduction-to-gtkDcoding.html) 2. I

Re: GtkD on Windows: notes + question

2020-02-10 Thread mark via Digitalmars-d-learn
On Sunday, 9 February 2020 at 14:08:02 UTC, Daniel Kozak wrote: "lflags-windows": ["/SUBSYSTEM:WINDOWS", "/ENTRY:mainCRTStartup"], [snip] Is there a way to avoid the console Window, at least for release builds? Thank you! Your solution I guess is for dub.json. For those using dub.sdl the

Re: GtkD on Windows: notes + question

2020-02-10 Thread mark via Digitalmars-d-learn
On Sunday, 9 February 2020 at 14:08:02 UTC, Daniel Kozak wrote: "lflags-windows": ["/SUBSYSTEM:WINDOWS", "/ENTRY:mainCRTStartup"], [snip] Is there a way to avoid the console Window, at least for release builds? Thank you! Your solution I guess is for dub.json. For those using dub.sdl the

dscanner and ref parameters

2020-02-23 Thread mark via Digitalmars-d-learn
I use dscanner to lint my code and find it helpful. However, in GtkD there are several functions which take ref args, and these confuse dscanner. For example: uint kv; event.getKeyval(kv); // ref arg is updated here dscanner incorrectly (but understandably) reports:

Re: Dscanner: is it possible to switch off style checks case-by-case?

2020-02-15 Thread mark via Digitalmars-d-learn
On Saturday, 15 February 2020 at 07:23:02 UTC, Basile B. wrote: On Thursday, 13 February 2020 at 17:15:50 UTC, mark wrote: I'm starting out with GtkD and have this function: [snip] Otherwise here is an example of how you can tune the different checks:

Tour: unneeded import

2020-01-13 Thread mark via Digitalmars-d-learn
In the D tour example shown here https://tour.dlang.org/tour/en/basics/ranges there is the following import: import std.range : drop, generate, take; But generate is not used so I think it ought to be deleted to avoid confusion.

books for learning D

2020-01-13 Thread mark via Digitalmars-d-learn
I'm just starting out learning D. Andrei Alexandrescu's "The D Programming Language" is 10 years old, so is it still worth getting? (I don't know how much D has changed in 10 years.)

Re: books for learning D

2020-01-13 Thread mark via Digitalmars-d-learn
On Monday, 13 January 2020 at 11:13:32 UTC, Ferhat Kurtulmuş wrote: On Monday, 13 January 2020 at 11:08:45 UTC, Ferhat Kurtulmuş wrote: On Monday, 13 January 2020 at 10:28:48 UTC, mark wrote: I'm just starting out learning D. Andrei Alexandrescu's "The D Programming Language" is 10 years

Re: books for learning D

2020-01-13 Thread mark via Digitalmars-d-learn
On Monday, 13 January 2020 at 11:35:51 UTC, bachmeier wrote: On Monday, 13 January 2020 at 11:20:31 UTC, mark wrote: On Monday, 13 January 2020 at 11:13:32 UTC, Ferhat Kurtulmuş wrote: On Monday, 13 January 2020 at 11:08:45 UTC, Ferhat Kurtulmuş wrote: On Monday, 13 January 2020 at 10:28:48

Re: Reading a file of words line by line

2020-01-15 Thread mark via Digitalmars-d-learn
Thanks for the ideas, I've now reduced the size of the getWords() function (even allowing for moving the imports to the top of the file) to this: WordSet getWords(string filename, int wordsize) { string bareWord(string line) { auto rx = ctRegex!(r"^([a-z]+)", "i"); auto

Some comments on learning D using the tour

2020-01-15 Thread mark via Digitalmars-d-learn
I am learning D for the first time. While I wait for Mike Parker's "Learning D" book to arrive, I have started using the tour. I really like the tour, especially the fact that you can run and tweak the code as well as read the explanations. However, what I really miss is a contents page so

Re: Reading a file of words line by line

2020-01-15 Thread mark via Digitalmars-d-learn
I really do need a set for the next part of the program, but taking your code and ideas I have now reduced the function to this: WordSet getWords(string filename, int wordsize) { WordSet words; File(filename).byLine .map!(line => line.until!(not!isAlpha)) .filter!(word

Re: Some comments on learning D using the tour

2020-01-16 Thread mark via Digitalmars-d-learn
On Thursday, 16 January 2020 at 01:02:46 UTC, Mike Parker wrote: On Wednesday, 15 January 2020 at 20:06:01 UTC, mark wrote: However, what I really miss is a contents page so that I can look at each topic and jump back when I want to recap something. Please submit an enhancement request:

Re: Some comments on learning D using the tour

2020-01-16 Thread mark via Digitalmars-d-learn
On Thursday, 16 January 2020 at 02:32:07 UTC, Adam D. Ruppe wrote: On Wednesday, 15 January 2020 at 20:06:01 UTC, mark wrote: For example, I haven't found one definitive place in the docs that document D's strings. My unofficial docs are built from the same source, so not perfect, but at

confused about string and lambda args

2020-01-16 Thread mark via Digitalmars-d-learn
I'm looking at https://tour.dlang.org/tour/en/gems/range-algorithms (IMO the example code is far too long and complicated.) But here's the thing: auto wordCharCounts = words // I added this and it works fine .map!"a.length"; writeln(wordCharCounts); auto wordCharCounts2 =

  1   2   >