Re: Best way to learn 2d games with D?

2020-03-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/15/20 4:12 PM, Jordan Wilson wrote: On Sunday, 15 March 2020 at 17:58:58 UTC, Steven Schveighoffer wrote: I want to try and learn how to write 2d games. I'd prefer to do it with D. I've found a ton of tutorials on learning 2d gaming with other languages. Is there a place to look that

Re: Best way to learn 2d games with D?

2020-03-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/15/20 3:03 PM, Ferhat Kurtulmuş wrote: On Sunday, 15 March 2020 at 19:02:11 UTC, Ferhat Kurtulmuş wrote: On Sunday, 15 March 2020 at 18:45:14 UTC, Steven Schveighoffer wrote: [...] I refer this ugly site a lot for basics of SDL. Since one could easily convert c code to d, transition is

Re: Pattern matching via switch?

2020-03-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/15/20 2:22 PM, 12345swordy wrote: On Sunday, 15 March 2020 at 17:55:59 UTC, Steven Schveighoffer wrote: On 3/14/20 3:04 PM, 12345swordy wrote: I.E. switch (object) case Type1 t1: case Type2 t2: case Type3 t3: Is this a class object and you are trying to determine at

Re: Best way to learn 2d games with D?

2020-03-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/15/20 2:14 PM, bauss wrote: On Sunday, 15 March 2020 at 17:58:58 UTC, Steven Schveighoffer wrote: I want to try and learn how to write 2d games. I'd prefer to do it with D. I've found a ton of tutorials on learning 2d gaming with other languages. Is there a place to look that uses D for

Re: Pattern matching via switch?

2020-03-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/14/20 3:04 PM, 12345swordy wrote: I.E. switch (object)     case Type1 t1:     case Type2 t2:     case Type3 t3: Is this a class object and you are trying to determine at runtime which derived type it is and perform an action based on that? Or are you trying to switch on the type of

Best way to learn 2d games with D?

2020-03-15 Thread Steven Schveighoffer via Digitalmars-d-learn
I want to try and learn how to write 2d games. I'd prefer to do it with D. I've found a ton of tutorials on learning 2d gaming with other languages. Is there a place to look that uses D for learning? Should I just start with another language and then migrate to D later? Anyone recommend any

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/13/20 5:06 PM, H. S. Teoh wrote: On Fri, Mar 13, 2020 at 04:31:16PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] I would expect that something could be written to turn a signature string into a mangling and also provide the correct type upon return. Something like

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/14/20 6:06 AM, wjoe wrote: On Friday, 13 March 2020 at 20:31:16 UTC, Steven Schveighoffer wrote: On 3/13/20 4:22 PM, wjoe wrote: I would expect that something could be written to turn a signature string into a mangling and also provide the correct type upon return. Something like: auto

Re: Is it possible to dynamically load a @safe function from a shared library ?

2020-03-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/13/20 4:22 PM, wjoe wrote: I wasn't aware that pragma(mangle, ..) can practically name any function anything. So from what I understand, because, at least on Posix, since there's only a symbol name there's nothing I can do in my loader to verify that a function is or does what it claim

Re: Associative Array potential performance pitfall?

2020-03-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/13/20 5:24 AM, H. S. Teoh wrote: Note that `arg ~ arg` may allocate, but it also may not if the current buffer for `arg` is big enough to accomodate both. That always allocates. Only appending may avoid allocation: arg ~= arg; But, I would instead use ranges if possible to avoid all

Re: How can I append PATH to environment["PATH"] in runtime?

2020-03-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/13/20 2:08 AM, Marcone wrote: environment["PATH"] ~= r";D:\folder\"; // Error Did you try the long way? environment["PATH"] = environment["PATH"] ~ r";D:\folder\"; It would be nice to have environment support opIndexOpAssign for concatenation. -Steve

Re: Aliases to mutable thread-local data not allowed

2020-03-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/10/20 7:09 AM, mark wrote: I just tried:     auto jobs = tids.length;     while (jobs) {     receive(     (Deb deb) { debForName[deb.name] = cast(Deb)deb; },     (DoneMessage m) { jobs--; }     );     }

Re: New with alias

2020-03-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/10/20 2:09 AM, tcak wrote: I write a code as below: auto result = new char[4]; It allocates memory as expected. Later I define an alias and do the above step: alias Pattern = char[4]; auto result = new Pattern; But compiler says: Error: new can only create structs, dynamic arrays or

Re: An struct copy constructor that can cope with an AA?

2020-03-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/9/20 11:49 AM, mark wrote: On Monday, 9 March 2020 at 14:45:15 UTC, Steven Schveighoffer wrote: On 3/9/20 9:23 AM, mark wrote: I have this struct: [snip] I would name it dup instead of copy for consistency with D. A copy constructor is pretty heavy for a struct to do a complete

Re: Typescript with vibe.d

2020-03-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/9/20 1:23 PM, GreatSam4sure wrote: On Monday, 9 March 2020 at 15:11:48 UTC, Steven Schveighoffer wrote: On 3/9/20 5:42 AM, GreatSam4sure wrote: I want to know if it is possible to use typescript with the vibe.d since typescript is a superset of javascript. I will appreciate any example

Re: Docs 6.9.4: Implicit Conversion to bool

2020-03-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/9/20 11:35 AM, Manfred Nowak wrote: Having a function `f' overloaded for argument types `bool' and `ulong', the specs guarantee, that for `f( 1uL)' the boolean overload of `f' is called. What is this good for? You're not the first person to ask.

Re: Typescript with vibe.d

2020-03-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/9/20 5:42 AM, GreatSam4sure wrote: I want to know if it is possible to use typescript with the vibe.d since typescript is a superset of javascript. I will appreciate any example if it is possible My understanding is that Typescript needs to be compiled to javascript. You can't serve

Re: An struct copy constructor that can cope with an AA?

2020-03-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/9/20 9:23 AM, mark wrote: I have this struct: struct Deb {     string name;     ...     Unit[string] tags; // set of tags     Deb copy() const {     Deb deb;     ...     foreach (key, value; tags) // XXX     deb.tags[key] = value;     return deb;     }  

Re: Trying to understand a simple piece of code: dmd barray

2020-03-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/7/20 8:06 AM, Dibyendu Majumdar wrote: On Saturday, 7 March 2020 at 12:26:32 UTC, drug wrote: I am trying to understand https://github.com/dlang/dmd/blob/master/src/dmd/backend/barray.d. Two questions: 1. What does this mean and why is it needed? line 95: alias array this; This

Re: use of struct vs class

2020-03-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/7/20 8:22 AM, mark wrote: 0x55701ef0 in _D3std9container6rbtree__T12RedBlackTreeTAyaVQea5_61203c2062Vbi0ZQBn5emptyMFNaNbNdNiNfZb (this=0x0)     at /home/mark/opt/ldc2-1.20.0-linux-x86_64/bin/../import/std/container/rbtree.d:967 967    return _end.left is null; (gdb) bt

Re: Trying to understand a simple piece of code: dmd barray

2020-03-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/7/20 7:26 AM, drug wrote: 07.03.2020 15:05, Dibyendu Majumdar пишет: Hi, I am trying to understand https://github.com/dlang/dmd/blob/master/src/dmd/backend/barray.d. Two questions: 1. What does this mean and why is it needed? line 95: alias array this; This means that `array` can

Re: use of struct vs class

2020-03-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/7/20 5:58 AM, mark wrote: change #1:     if (line.empty) {     if (deb != null && deb.valid)     debs.insert(deb);     else // report incomplete     deb = null;     continue;  

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/6/20 9:42 AM, Steven Schveighoffer wrote: alias opdispatch(T) = other_name!(name, T); And obviously, this should be opDispatch with a capital D ! -Steve

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/6/20 9:14 AM, Adam D. Ruppe wrote: On Friday, 6 March 2020 at 14:05:55 UTC, Steven Schveighoffer wrote: Adam's way doesn't work either, because the call doesn't use the alias, but just instantiates opDispatch with the new name!' oh yikes, how did I not notice that?! so yeah just kinda

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/6/20 8:55 AM, Steven Schveighoffer wrote: Instantiate!(f.opDispatch!fname, Bitmap)("path/to/wallpaper.png") I realized, this doesn't work. Because f.opDispatch is a `this` call, but is not called that way in this case. Adam's way doesn't work either, because the call doesn't use the

Re: DMD: Is it possible change compile time errors to runtime errors in Dlang?

2020-03-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/6/20 8:59 AM, Marcone wrote: On Friday, 6 March 2020 at 05:31:57 UTC, Mathias Lang wrote: On Friday, 6 March 2020 at 04:56:28 UTC, Marcone wrote: Is it possible change compile time errors to runtime errors in Dlang? If yes, how can I make it? No it's not possible, D is a statically

Re: How to dispatch a class function for an object accessed by handle?

2020-03-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/6/20 6:51 AM, wjoe wrote: On Thursday, 5 March 2020 at 18:33:41 UTC, Adam D. Ruppe wrote: On Thursday, 5 March 2020 at 14:24:33 UTC, wjoe wrote: [...] template opDispatch(string name) {     auto opDispatch(T, Args...)(Args args) {    ...     } } [...] NOTE: opDispatch suppresses

Re: How to dispatch a class function for an object accessed by handle?

2020-03-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/5/20 9:24 AM, wjoe wrote: but how can I call fn in the context of an object instance? You could do it with delegates. But it's ugly: import std.stdio; class C { void foo() { writeln("Yup");} } void main() { alias f = C.foo; auto c = new C; void delegate() dg;

Re: Safely wrapping an uncopyable struct to implement an interface

2020-03-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/4/20 9:04 AM, aliak wrote: On Wednesday, 4 March 2020 at 12:03:48 UTC, Gregor Mückl wrote: Hi! I've just created a situation in my code that is summarized by the following example. I don't know how to solve it with @safe code. A third party library provides a struct that is not

Re: in not working for arrays is silly, change my view

2020-03-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/2/20 7:32 PM, aliak wrote: On Monday, 2 March 2020 at 23:27:22 UTC, Steven Schveighoffer wrote: What I think is happening is that it determines nobody is using the result, and the function is pure, so it doesn't bother calling that function (probably not even the lambda, and then

Re: in not working for arrays is silly, change my view

2020-03-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/2/20 5:21 PM, aliak wrote: On Monday, 2 March 2020 at 21:33:37 UTC, Steven Schveighoffer wrote: On 3/2/20 3:52 PM, aliak wrote: On Monday, 2 March 2020 at 15:47:26 UTC, Steven Schveighoffer wrote: On 3/2/20 6:52 AM, Andrea Fontana wrote: On Saturday, 29 February 2020 at 20:11:24 UTC,

Re: in not working for arrays is silly, change my view

2020-03-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/2/20 3:52 PM, aliak wrote: On Monday, 2 March 2020 at 15:47:26 UTC, Steven Schveighoffer wrote: On 3/2/20 6:52 AM, Andrea Fontana wrote: On Saturday, 29 February 2020 at 20:11:24 UTC, Steven Schveighoffer wrote: 1. in is supposed to be O(lg(n)) or better. Generic code may depend on this

Re: in not working for arrays is silly, change my view

2020-03-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/2/20 6:39 AM, JN wrote: On Saturday, 29 February 2020 at 21:56:51 UTC, Ali Çehreli wrote: Because you mentioned canFind, I think you want the semantics to be "is there an element with this value." If so, it would be confusing to use the same operator for two different things: For

Re: in not working for arrays is silly, change my view

2020-03-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/2/20 6:52 AM, Andrea Fontana wrote: On Saturday, 29 February 2020 at 20:11:24 UTC, Steven Schveighoffer wrote: 1. in is supposed to be O(lg(n)) or better. Generic code may depend on this property. Searching an array is O(n). Probably it should work if we're using a "SortedRange". int[]

Re: in not working for arrays is silly, change my view

2020-02-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/29/20 2:38 PM, JN wrote: assert(1 in [1, 2, 3]); Error: incompatible types for (1) in ([1, 2, 3]): int and int[ Yes, I know about .canFind(), but this is something that trips people over and over. I think it would be better if "in" worked for both assoc arrays and normal arrays, or

Re: Should getSymbolsByUDA work with member variables?

2020-02-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/28/20 1:34 PM, cc wrote: This compiles: class Foo { int x; @(1) void y() {} this() {     static foreach (idx, field; getSymbolsByUDA!(Foo, 1)) {     } } } This does not: class Foo { @(1) int x; void y() {} this() {     static foreach

Re: library dependencies nightmare, D edition

2020-02-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/25/20 5:26 PM, Marcel wrote: I can't give you the actual error messages right now, but both libraries have packages that define modules with the same name. For example, both libraries have packages with a module called "utility.d". Unfortunately, this isn't the only thing that causes

Re: library dependencies nightmare, D edition

2020-02-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/25/20 4:31 PM, Marcel wrote: Hello! I have two libraries, where library B depends on library A, where both libraries consist of multiple packages. Say my project (I'm using VisualD) folder layout is the following: C/:    libA   A_Package1   A_Package2   A_Package3   

Re: Lambda capture by value

2020-02-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/24/20 3:32 PM, H. S. Teoh wrote: To fix this, copy the value of 'i' to a local variable inside the loop body, then the lambda will correctly capture a unique per-iteration instance of the variable. Like this: foreach (i; iota(5)) { auto _i = i; printers[i] = ()

Re: Order of static this() execution?

2020-02-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/24/20 9:25 AM, Steven Schveighoffer wrote: I'll file an issue report. https://issues.dlang.org/show_bug.cgi?id=20605 -Steve

Re: Order of static this() execution?

2020-02-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/23/20 6:55 AM, drathier wrote: On Sunday, 23 February 2020 at 11:41:25 UTC, Johan Engelen wrote: On Sunday, 23 February 2020 at 09:59:45 UTC, drathier wrote: I'm having some trouble with the order in which `static this()` runs. This is the order defined in the source file, numbered for

Re: Does scope not work on parameters?

2020-02-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/22/20 10:01 PM, Russ wrote: Is there some newer feature I should be using? scope escapes are only disallowed in @safe code. Adding @safe: to the top of this file makes it not compile with a complaint: Error: scope variable z assigned to non-scope b.foo Which I think is what you

Re: is(typeof(...)) vs __traits(compiles, ...)

2020-02-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/21/20 5:15 AM, drug wrote: Currently this code does not compiles: ``` unittest {     class MyClass     {     T opCall(T)(T p)     {     return p;     }     }     import std.container.array : Array;     Array!MyClass arr; } ``` but if you comment out `opCall`

Re: Conditional Attributes

2020-02-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/18/20 12:11 PM, Marcel wrote: Hello! Say I have a struct where every member function can either be static or not depending on a template parameter. Is there a simple way to do this? Like, for example: struct Foo(Condition) {    static if (Condition) static:    void Bar() {}    void

Re: How to get the name of an object's class at compile time?

2020-02-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/17/20 2:28 AM, Nathan S. wrote: What I want is something like this: string className(in Object obj) {     return obj is null ? "null" : typeid(obj).name; } ...except I want it to work in CTFE. What is the way to do this in D? https://issues.dlang.org/show_bug.cgi?id=7147

Re: dub / use git branch

2020-02-17 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/16/20 9:01 AM, Robert M. Münch wrote: I want to use a specific branch version if a package. I specified the branch version in a dub.selections.json file. But it seems that dub requires a ZIP file that can be downloaded from code.dlang.org, which of course fails because the branch is only

Re: AA code 50x slower

2020-02-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/16/20 7:57 AM, AlphaPurned wrote: template AA(string[] S) { auto _do() { int[string] d; foreach(s; S) d[s] = 0; return d; } enum AA = _do; evilrat is 100% correct. Each time you call that if statement, it constructs a NEW AA, checks to see if the t parameter is in there, and

Re: rt/aaA.d Line: 553

2020-02-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/15/20 10:21 AM, Ferhat Kurtulmuş wrote: On Saturday, 15 February 2020 at 14:30:20 UTC, Steven Schveighoffer wrote: On 2/15/20 6:49 AM, Ferhat Kurtulmuş wrote: On Friday, 14 February 2020 at 23:41:45 UTC, Steven I'll note that you are going to leak some memory because you are not

Re: Difference between range `save` and copy constructor

2020-02-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/15/20 9:45 AM, Jonathan M Davis wrote: On Saturday, February 15, 2020 7:34:42 AM MST Steven Schveighoffer via Digitalmars-d-learn wrote: On 2/15/20 5:53 AM, uranuz wrote: I am interested in current circumstances when we have new copy constructor feature what is the purpose of having range

Re: How the hell to split multiple delims?

2020-02-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/15/20 6:32 AM, AlphaPurned wrote: I've tried 10 different ways with split and splitter, I've used all the stuff that people have said online but nothing works. I always get a template mismatch error. Why is something so easy to do so hard in D? auto toks = std.regex.split(l,

Re: Difference between range `save` and copy constructor

2020-02-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/15/20 5:53 AM, uranuz wrote: I am interested in current circumstances when we have new copy constructor feature what is the purpose of having range `save` primitive? For me they look like doing basicaly the same thing. And when looking in some source code of `range` module the most common

Re: rt/aaA.d Line: 553

2020-02-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/15/20 6:49 AM, Ferhat Kurtulmuş wrote: On Friday, 14 February 2020 at 23:41:45 UTC, Steven Schveighoffer wrote: On 2/14/20 6:36 PM, Ferhat Kurtulmuş wrote: İf ((aa.used + 1)* GROW_DEN > aa.dim * GROW_NUM) aa.grow(ti.key); This call is expensive (it reallocates all the

Re: rt/aaA.d Line: 553

2020-02-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/14/20 6:36 PM, Ferhat Kurtulmuş wrote:     İf ((aa.used + 1)* GROW_DEN > aa.dim * GROW_NUM)     aa.grow(ti.key); This call is expensive (it reallocates all the buckets and reinserts all the existing data into the new bucket), it should be avoided if in the end we will not be

Re: rt/aaA.d Line: 553

2020-02-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/14/20 5:57 PM, Ferhat Kurtulmuş wrote: I hesitated to post this on the topic of druntime because probably I will learn something new if I am totally/stupidly wrong. There are no stupid questions, and this is the learn forum. So you are in the right place! In

Re: How to use labeled break in static foreach?

2020-02-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/14/20 1:41 AM, cc wrote: import std.meta; enum A = AliasSeq!(1, 2, 3, 4); THREELOOP: static foreach (idx, field; A) { static if (field == 3) {     pragma(msg, "Got a 3!");     break THREELOOP; } static if (idx == A.length - 1) {     static assert(0, "Got no

Re: Unpack Variadic Args?

2020-02-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/13/20 12:24 PM, Steven Schveighoffer wrote: But this means you have an additional function call (which could of course be inlined). And I might add, an additional requirement to declare some other template (one of the huge drawbacks of std.meta, IMO). Some syntax like

Re: Unpack Variadic Args?

2020-02-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/13/20 12:18 PM, Adam D. Ruppe wrote: On Thursday, 13 February 2020 at 17:13:31 UTC, Steven Schveighoffer wrote: the f(foo(args)...) syntax doesn't have a D equivalent. It would be staticMap f(staticMap!(foo, args)) No,

Re: Unpack Variadic Args?

2020-02-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/13/20 11:29 AM, Jeff wrote: On Thursday, 13 February 2020 at 08:06:52 UTC, Paul Backus wrote: Variadic template arguments unpack automatically in D, so you don't need to do anything special here:     void g(Args...)(auto ref Args args) {     import core.lifetime: forward; // like

Re: How do you find the struct types in a module? - getting Error: unknown

2020-02-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/13/20 9:47 AM, aliak wrote: Hi, I'm trying to get a typed list of structs in my current module that matches certain criteria. Something like: module mod; struct X {} struct Y {} alias allTypes = ListOfTypes!mod; But I'm having a bit of trouble. I have this so far: template

Re: writeln() in static import std

2020-02-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/13/20 2:33 AM, Adnan wrote: How can I reach stdout.writeln() using fully qualified name with static import? I have tried: std.stdio.stdout.writeln() -- fails std.writeln() -- works std.stdout.writeln -- works How does static import with std work? Hm..., this works: static import

Re: Type sequence concatenation / associative array implementation

2020-02-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/12/20 5:47 PM, Paul Backus wrote: On Wednesday, 12 February 2020 at 20:58:49 UTC, Marcel wrote: 2- How is the builtin associative array implemented? I think I read somewhere it's implemented like C++'s std::unordered_map but with BSTs instead of DLists for handling collisions: is this

Re: Some impressions/notes from a new D programmer

2020-02-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/12/20 10:52 AM, mark wrote: I also think you split into more HTML files which I prefer. FYI, dlang.org has a secondary version of the docs which splits the documents up more: https://dlang.org/library/index.html I can't find a link to it directly from the main page though... This

Re: Default value for member class

2020-02-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/10/20 1:18 PM, JN wrote: class IntValue {     int x = 5; } class Foo {     IntValue val = new IntValue(); } void main() {     Foo f1 = new Foo();     Foo f2 = new Foo();     assert(f1.val == f2.val); } Is this expected? Define "expected" ;) It's been this way for a while

Re: Getting the initial value of a class field in compile time.

2020-02-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/8/20 7:39 PM, realhet wrote: On Sunday, 9 February 2020 at 00:15:47 UTC, Drug wrote: On Saturday, 8 February 2020 at 23:37:56 UTC, realhet wrote: Hello, class A{   int i = 42; } Is there a way to get that 42? (Input is the class A and the name of the field 'i') A.i.init returns 0, so

Re: Flatten a range of static arrays

2020-02-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/8/20 1:20 PM, ag0aep6g wrote: On 08.02.20 15:57, Steven Schveighoffer wrote: This kind of stuff is so difficult to reason about and develop as a library that people will just end up removing dip1000 from their compilation. I 100% agree that DIP 1000 is hard to reason about. It's pretty

Re: Flatten a range of static arrays

2020-02-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/7/20 8:38 PM, ag0aep6g wrote: If that code were allowed, you could do this: struct Joiner {     Joiner* p; } Joiner g; void main() @safe {     scope Joiner j;     () @trusted { j.p = } (); /* pretend it's allowed */     g = *j.p; /* dereference and copy */ } Returning a

Re: Flatten a range of static arrays

2020-02-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/7/20 6:30 PM, ag0aep6g wrote: On 08.02.20 00:10, nullptr wrote: ``` import std; struct SomeRange { int[3] val; enum empty = false; auto popFront() @safe {} ref auto front() @safe { return val; } } void main() @safe {

Re: Flatten a range of static arrays

2020-02-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/7/20 6:10 PM, nullptr wrote: ``` import std; struct SomeRange {     int[3] val;     enum empty = false;     auto popFront() @safe {}     ref auto front() @safe     {     return val;     } } void main() @safe {     SomeRange().take(10).map!((return ref x) =>

Re: Flatten a range of static arrays

2020-02-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/7/20 4:17 PM, Dennis wrote: On Friday, 7 February 2020 at 20:55:14 UTC, nullptr wrote: Depending on how your range is structured, it might be possible to just mark front as returning by ref to make this work. That's a good one. I can't make front() return by ref, but I can make front a

Re: Flatten a range of static arrays

2020-02-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/7/20 3:13 PM, Dennis wrote: If I have an input range with element type `int[3]`, how do I easily turn it into a range of `int` so I can map it? If it were an int[3][] I could simply cast it to an int[] before mapping, but I don't want to eagerly turn it into an array. I thought of doing

Re: D create many thread

2020-02-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/7/20 2:34 AM, bauss wrote: On Thursday, 6 February 2020 at 22:00:26 UTC, tchaloupka wrote: On Wednesday, 5 February 2020 at 13:05:59 UTC, Eko Wahyudin wrote: Hi all, I'm create a small (hallo world) application, with DMD. But my program create 7 annoying threads when create an empty

Re: Trying to use a template class with ranges

2020-02-06 Thread Steven Schveighoffer via Digitalmars-d-learn
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: Object "A" inherited object "B". And you need to return the object link "B".

2020-02-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/6/20 10:11 AM, Steven Schveighoffer wrote b.step(); // virtual call, calls B.step I meant, calls A.step; -Steve

Re: Trying to use a template class with ranges

2020-02-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/6/20 7:16 AM, mark wrote: 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

Re: Object "A" inherited object "B". And you need to return the object link "B".

2020-02-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/6/20 8:05 AM, Mihail Lorenko wrote: On Thursday, 6 February 2020 at 12:37:01 UTC, Adam D. Ruppe wrote: On Thursday, 6 February 2020 at 12:15:17 UTC, Mihail Lorenko wrote:     B* b; A pointer to a class is a rare thing in B since they are already automatic references. Just use `B b;`

Re: module ... conflicts with package name ...

2020-02-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/5/20 6:50 PM, Steven Schveighoffer wrote: HOWEVER, I will file a bug on this. If you have two packages claiming to be the same module package, it would be helpful if it showed the previously declared filename/location. https://issues.dlang.org/show_bug.cgi?id=20563 -Steve

Re: module ... conflicts with package name ...

2020-02-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/3/20 2:18 PM, Boris Carvajal wrote: On Monday, 3 February 2020 at 16:35:06 UTC, Steven Schveighoffer wrote: I can't reproduce with a small example. Before I try and go through the process to reduce this, just wanted to see if anyone knows about this. I've made a few changes to the

Re: D create many thread

2020-02-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/5/20 8:05 AM, Eko Wahyudin wrote: Hi all, I'm create a small (hallo world) application, with DMD. But my program create 7 annoying threads when create an empty class. What is this thread for? and is it normal in D? Thank you in advance. I didn't know about this feature. I was going

Re: vibe.d no routes match path

2020-02-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/4/20 10:35 AM, seany wrote:     router.post("/archive", );     router.get("/archive", ); //also tested without this line [snip] Internal error information: No routes match path '/a' Did you go to /a? Looks like you only registered routes for /archive. -Steve

module ... conflicts with package name ...

2020-02-03 Thread Steven Schveighoffer via Digitalmars-d-learn
I have a directory structure like this (names are changed, but essentially they shouldn't matter): source/foo/package.d source/foo/bar/package.d with foo.package.d containing a public import of foo.bar, and foo.bar containing various public imports from elsewhere. I get the following

Re: Cannot take slice of scope static array in @safe code

2020-02-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/2/20 1:57 PM, ag0aep6g wrote: On 02.02.20 19:49, ag0aep6g wrote: On 02.02.20 19:18, Steven Schveighoffer wrote: I'm not sure if I got it right, but like this? int*[][] g1; int*[] g2; int* g3; void main() @safe { /* An array stored on the stack, of

Re: Cannot take slice of scope static array in @safe code

2020-02-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/2/20 1:32 PM, Dennis wrote: On Sunday, 2 February 2020 at 18:18:28 UTC, Steven Schveighoffer wrote: scope should have been a type constructor. I feel the same way, I find const/immutable much easier to reason about than scope in its current state. Do you think scope as a storage class

Re: Template Usage with Eponymous Trick

2020-02-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/2/20 12:51 PM, ShadoLight wrote: // Should this assertion pass or fail? static assert(is(a));  //PASS static assert(is(b));  //FAIL But I don't see how braces will affect this. Can you explain? First, note that: struct S(T) {} is *exactly* equivalent to (in fact, you can write it this

Re: Constant GC allocations when sending large messages to threads?

2020-02-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/2/20 12:13 PM, cc wrote: On Friday, 31 January 2020 at 15:47:26 UTC, Steven Schveighoffer wrote: You could use RefCounted to build a struct that then is sendable with the data you need. RefCounted allocates using C malloc, not the GC. Thanks for the tips.  How exactly would I go about

Re: Cannot take slice of scope static array in @safe code

2020-02-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/2/20 10:20 AM, ag0aep6g wrote: On 02.02.20 14:40, Dennis wrote: Compiling the following with -dip1000 gives an error. ``` void main() @safe { string[1] a0; scope int[1] a1; scope string[1] a2; scope string[] b0 = a0[]; // Fine scope int[] b1 = a1[]; // Fine

Re: More vibe.d : Receiving Post params

2020-02-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/1/20 7:55 PM, seany wrote: How do I intercept POST params? Thank you Look at req.form for POST parameters. They are not unified with queryString. https://vibed.org/api/vibe.http.server/HTTPServerRequest.form -Steve

Re: Unexpected issue with std.format

2020-02-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/1/20 8:39 AM, Saurabh Das wrote: I faced this issue while working with custom formatting for a struct. I have reduced the error down to this test program: import std.format, std.stdio, std.array; struct Test1 {     void toString(W, C)(ref W w, scope const ref FormatSpec!C fmt)     {   

Re: Dub - vibe.d - hunt framework ... problems

2020-02-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/1/20 6:15 AM, seany wrote: $ dub init server -t vibe.d Package recipe format (sdl/json) [json]: Name [server]: Description [A simple vibe.d server application.]: Author name [root]: License [proprietary]: Copyright string [Copyright © 2020, root]: Add dependency (leave empty to skip) []:

Re: Constant GC allocations when sending large messages to threads?

2020-01-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/31/20 2:14 AM, cc wrote: On Wednesday, 29 January 2020 at 21:10:53 UTC, Steven Schveighoffer wrote: I'm pretty sure std.concurrency uses Variant to pass message data, which boxes when it gets over a certain size. You are probably crossing that threshold. The allocations should level out

Re: Template Usage with Eponymous Trick

2020-01-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/30/20 9:10 AM, ShadoLight wrote: Why does the 'classical' template calling convention not work anymore in this case? (if the template name and function name are different it obviously still works). Note the templates were not defined in the simplified 'Eponymous Trick' style i.e.: I

Re: iopipe: Writing output to std.io File

2020-01-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/30/20 12:59 AM, Jesse Phillips wrote: On Tuesday, 28 January 2020 at 16:09:55 UTC, Steven Schveighoffer wrote: Everything is pulled with iopipe, even output, so it's just a matter of who is pulling and when. Pushing is a matter of telling the other end to pull. That statement I

Re: Constant GC allocations when sending large messages to threads?

2020-01-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/29/20 2:48 PM, cc wrote: Given the sample program at https://pastebin.com/u9sSNtj7 I'm experiencing GC allocations with every call to std.concurrency.send when sending larger messages (e.g. multiple ulongs).  These do not occur when sending uints in comparison, in the provided example.

Re: iopipe: Writing output to std.io File

2020-01-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/28/20 1:25 AM, Jesse Phillips wrote: I really feel like this is all very well thought out and clean, I don't appear to have a previous model to help visualize this output approach. Right now something like tee is coming to mind. Thank you for explaining with the answer. Thanks! Tee is

Re: Static fields with shared fields

2020-01-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/27/20 5:39 PM, Marcel wrote: Hello! If I declare a static variable inside a struct that contains a shared field, is that new variable also shared? For example, say I have a custom atomic wrapper type, like C++'s std::atomic, that contains only one shared variable: Does it remain shared

Re: Subrange type

2020-01-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/27/20 3:06 PM, Herbert wrote: How can I create a subrange type, for example ushort DiceValue {1 ... 6}? D doesn't have a "Range" type like this. But you can use ranges of different types by typing the literals. Note that D numeric ranges are always exclusive at the upper end. e.g.:

Re: Public constants and types in class

2020-01-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/27/20 3:05 PM, Herbert wrote: How can a class provide it's users with named constants, enums, types, structs and not just member functions? Just declare them inside the class. They then go inside the class namespace, but are not strictly part of the class instance itself. e.g.: class

Re: iopipe: Writing output to std.io File

2020-01-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/27/20 1:12 PM, Steven Schveighoffer wrote: void writeln(Pipe)(ref Pipe sink, string text) {    enforce(sink.ensureElems(text.size) >= text.length); // make sure there's enough buffer space to hold the text    sink[0 .. text.length] = text; // write to the buffer   

Re: iopipe: Writing output to std.io File

2020-01-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/26/20 11:59 PM, Jesse Phillips wrote: On Monday, 27 January 2020 at 01:50:00 UTC, Jesse Phillips wrote: Just as I'm hitting send the part I'm missing clicked: I needed to add the text encoding because my buffer is `char` but File writes `ubyte` ```dlang     auto output() {    

Re: Call of C function breaks memoty layout

2020-01-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/24/20 9:58 AM, drug wrote: On 1/24/20 4:37 PM, Andrey wrote: Hello, I'm trying to bind C library for Tcl/Tk in D code. There is a function called "Tcl_CreateInterp()" which I declared as extent(C). When I call this function then layout of memory become broken - one of my global wstring

Re: Call of C function breaks memoty layout

2020-01-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/24/20 8:37 AM, Andrey wrote: Hello, I'm trying to bind C library for Tcl/Tk in D code. There is a function called "Tcl_CreateInterp()" which I declared as extent(C). When I call this function then layout of memory become broken - one of my global wstring variables loses it's value. I

<    8   9   10   11   12   13   14   15   16   17   >