Re: parallel threads stalls until all thread batches are finished.

2023-08-28 Thread Ali Çehreli via Digitalmars-d-learn
On 8/28/23 15:37, j...@bloow.edu wrote: > Basically everything is hard coded to use totalCPU's parallel() is a function that dispatches to a default TaskPool object, which uses totalCPUs. It's convenient but as you say, not all problems should use it. In such cases, you would create your

Re: parallel threads stalls until all thread batches are finished.

2023-08-25 Thread Ali Çehreli via Digitalmars-d-learn
On 8/25/23 14:27, j...@bloow.edu wrote: > "A work unit is a set of consecutive elements of range to be processed > by a worker thread between communication with any other thread. The > number of elements processed per work unit is controlled by the > workUnitSize parameter. " > > So the question

Re: Bug in usage of associative array: dynamic array with string as a key

2023-07-01 Thread Ali Çehreli via Digitalmars-d-learn
On 6/30/23 17:42, Cecil Ward wrote: > https://dlang.org/spec/hash-map.html#testing_membership in the language > docs, under associative arrays - 13.3 testing membership. Would anyone > else care to try that example out as that might be quicker? I tried it by 1) Putting all the code inside a

Re: Bug in usage of associative array: dynamic array with string as a key

2023-06-30 Thread Ali Çehreli via Digitalmars-d-learn
On 6/30/23 13:16, Cecil Ward wrote: On Friday, 30 June 2023 at 19:58:39 UTC, FeepingCreature wrote: Note that you can do `uint ordinal = Decls.ordinals.get(str, -1);`. Is the second argument an ‘else’ then, my friend? Yes, .get and friends appear in this table:

Re: Bug in usage of associative array: dynamic array with string as a key

2023-06-30 Thread Ali Çehreli via Digitalmars-d-learn
On 6/30/23 12:05, Cecil Ward wrote: > I have code roughly like the following: > > dstring str = "name"d; Aside: One almost never needs dstring. > uint ordinal = (( str in Decls.ordinals ) !is null) ? > Decls.ordinals[ str ] : -1; > > struct Decls > { > uint[ dstring]

Re: is Dlang support Uniform initialization like c++

2023-06-30 Thread Ali Çehreli via Digitalmars-d-learn
On 6/30/23 08:18, lili wrote: How too wirte this: addPoint({4,5}, {4,6}) In this case, arrays are better but only if you don't define a constructor, which you don't need for simple types like Point below: struct Point { int x; int y; } void main() { // The type is explicit on

Re: pragma msg field name?

2023-06-26 Thread Ali Çehreli via Digitalmars-d-learn
On 6/26/23 21:25, Chris Katko wrote: > How do I get just the field name? I know .tupleof, which you can typeof() as well: class myObject{ int field1, field2, field3; static foreach(field; typeof(this).tupleof) { pragma(msg, field.stringof); } static

Re: Large statics

2023-06-25 Thread Ali Çehreli via Digitalmars-d-learn
On 6/25/23 13:41, Cecil Ward wrote: > The docs say that there is a limit on the size of large statics Customers (at least Weka) did request larger statics in the past. Since they use LDC, the limit was removed for LDC. I did not try it. :) Ali

Re: A couple of questions about arrays and slices

2023-06-24 Thread Ali Çehreli via Digitalmars-d-learn
On 6/20/23 19:09, Cecil Ward wrote: > 2.) I have a dynamic array and I wish to preinitialise its alloc cell to > be a certain large size so that I don’t need to reallocate often To be complete, 'assumeSafeAppend' must be mentioned here as well. Without it, there will be cases where the GC

Re: static if - unexpected results

2023-06-23 Thread Ali Çehreli via Digitalmars-d-learn
On 6/23/23 07:22, DLearner wrote: >`} else static if (__traits(isPOD, typeof(` ~ VarName ~ `))) {` ~ Regardless, you can also use the 'is' expression with the 'struct' keyword. If T is a struct, is (T == struct) that will produce true at compile time. Ali

Re: How does D’s ‘import’ work?

2023-06-20 Thread Ali Çehreli via Digitalmars-d-learn
On 6/20/23 08:09, Cecil Ward wrote: > I’m used to slow compilers on fast machines and compiling > gives me an excuse for more coffee and possibly fruity buns. Yes, all of us in past projects accepted C++'s slowness. We did get coffee, etc. One of my current colleagues regularly plays solitaire

Re: class Object with Dependency Injection

2023-06-18 Thread Ali Çehreli via Digitalmars-d-learn
On 6/18/23 07:37, Salih Dincer wrote: >auto truck = new Truck; >auto ship = new Ship; > >auto services = [ truck, ship ]; The problem is with the deduced type of 'services'. I don't know the mechanism behind it but the common type of 'truck' and 'ship' are deduced to be Object.

Re: Como puedo hacer funciones asincronas?

2023-06-18 Thread Ali Çehreli via Digitalmars-d-learn
On 6/17/23 20:20, Cecil Ward wrote: > On Saturday, 17 June 2023 at 22:05:37 UTC, Danico wrote: >> hola gente, quisiera saber como es que puedo hacer funciones asincronas. >> ` >> #!/usr/bin/env dmd >> import std; >> import std.stdio; >> import std.concurrency; >> //import archivo2; >> >> alias

Re: C++'s this() equivalent?

2023-06-15 Thread Ali Çehreli via Digitalmars-d-learn
On 6/15/23 08:15, zjh wrote: > I want `B` to become the following version similar to 'C++'. What should > I do? I have difficulty understanding the question. I think the nested structs, extern(C), static members, etc. confuse me. I am assuming they are not related to this question. > ```cpp

Re: Union with bits ?

2023-06-14 Thread Ali Çehreli via Digitalmars-d-learn
On 6/14/23 15:04, Paul wrote: > Question: Why do you say "may be slower than necessary"? Do you mean > compile or runtime or both? Definitely at compile time because the string that gets mixed-in first needs to be generated from your specification. For that, the bitfields() function must be

Re: Union with bits ?

2023-06-14 Thread Ali Çehreli via Digitalmars-d-learn
On 6/13/23 17:59, Paul wrote: > I would like to have labeled bits in a union with a ubyte. Something > like this: > ```d > struct MyStruct { > union { > ubyte status; > bit A, B, C…etc > } > } > ``` > Is something like this possible? > > Thanks D's string mixin syntax

Re: byte and short data types use cases

2023-06-09 Thread Ali Çehreli via Digitalmars-d-learn
On 6/9/23 08:07, Murloc wrote: > Where can I read more about this? I had written something related: http://ddili.org/ders/d.en/memory.html#ix_memory..offsetof The .offsetof appears at that point. The printObjectLayout() function example there attempts to visualize the layout of the members

Re: How does D’s ‘import’ work?

2023-06-07 Thread Ali Çehreli via Digitalmars-d-learn
On 6/7/23 21:17, Cecil Ward wrote: > I was thinking about the situation in C where I have a rule in a make > file that lists the .h files as well as the .c all as dependencies in > creating an object file. dmd's -makedeps command line switch should be helpful there. (I did not use it.) Ali

Re: How do I generate `setX` methods for all private mutable variables in a class?

2023-06-06 Thread Ali Çehreli via Digitalmars-d-learn
On 6/6/23 09:13, Basile B. wrote: > yeah I know that opDispatch is disliked because it is tried in a SFINAE > fashion, as citicized by Adam. But on the other side it's the best opover. I like how it helped in my current project: user.someShellCommand("-foo", "-bar"); opDispatch makes a

Re: Code duplication where you wish to have a routine called with either immutable or mutable arguments

2023-05-29 Thread Ali Çehreli via Digitalmars-d-learn
On 5/29/23 19:57, Cecil Ward wrote: > I wish to have one routine > that can be called with either immutable or (possibly) mutable argument > values. 'const' should take both immutable and mutable. Can you show your case with a short example? > Could I make the one routine into a template?

Re: How can I use Linker flags using DMD?

2023-05-29 Thread Ali Çehreli via Digitalmars-d-learn
On 5/29/23 17:39, Marcone wrote: > Can you help me static link dll msvcr120.dll in my x64 dlang program? Sorry, I haven't been programming on Windows for a very long time now. :/ But there are others who program on Windows here. Ali

Re: How can I use Linker flags using DMD?

2023-05-29 Thread Ali Çehreli via Digitalmars-d-learn
On 5/29/23 07:29, Marcone wrote: I want send flags to linker when using dmd.exe compiler. -L does it. Yes, -L-L can happen. :) https://dlang.org/dmd-linux.html Ali

Re: Lockstep iteration in parallel: Error: cannot have parameter of type `void`

2023-05-20 Thread Ali Çehreli via Digitalmars-d-learn
On 5/20/23 04:21, kdevel wrote: > Thanks for your explications! > > On Friday, 19 May 2023 at 21:18:28 UTC, Ali Çehreli wrote: >> [...] >> - std.range.zip can be used instead but it does not provide 'ref' >> access to its elements. > > How/why does sort [1] work with zipped arrays? I don't know

Re: Lockstep iteration in parallel: Error: cannot have parameter of type `void`

2023-05-19 Thread Ali Çehreli via Digitalmars-d-learn
On 5/19/23 02:17, kdevel wrote: Should this compile? dmd says Multiple points: - lockstep works only with foreach loops but it's not a range. - std.range.zip can be used instead but it does not provide 'ref' access to its elements. - However, since slices are already references to groups

Re: Proper way to handle "alias this" deprecation for classes

2023-05-07 Thread Ali Çehreli via Digitalmars-d-learn
On 5/7/23 13:44, Chris Piker wrote: > to fix the problem I > just delete the alias this line from dpq2, see what unit tests and app > code it breaks, then fix each of those. Yes but I neglected the lvalue/rvalue issue. In some cases the code won't compile if the return type of the newly

Re: Proper way to handle "alias this" deprecation for classes

2023-05-07 Thread Ali Çehreli via Digitalmars-d-learn
On 5/7/23 10:55, Chris Piker wrote: > According to dmd 2.103, alias this is > deprecated for classes, so I'd like to correct the problem. alias this is for implicit type conversions, which can be achieved explicitly as well. Given the following old code: class C { int* result; alias

Re: A Programmer's Dilema: juggling with C, BetterC, D, Macros and Cross Compiling, etc.

2023-05-02 Thread Ali Çehreli via Digitalmars-d-learn
On 5/1/23 03:23, Mike Parker wrote: > If you're referring to `rt_init` and `rt_term` are the `extern(C)` > functions in `core.runtime`. It's not necessary to call those from C. A > D library with a C interface can provide an `extern(C)` initialization > function that internally calls

Re: Cannot get this C++ example migrated to D

2023-04-16 Thread Ali Çehreli via Digitalmars-d-learn
On 4/16/23 00:46, Skippy wrote: > I wish D had value type classes as well. That cannot work due to the slicing problem. C++ cannot have value type classes either for the same reason. The difference there is that the enforcement is by guidelines (e.g. "never pass class objects by value to

Re: class variable initialization

2023-04-15 Thread Ali Çehreli via Digitalmars-d-learn
On 4/15/23 09:06, NonNull wrote: >> struct Wrapper >> { >>Object x = new Object(); >>alias x this; >> } > Amazing, was this always so? At least for a long time. However, every Wrapper object will have a pointer to that single shared object. If you think that cost is unnecessary, you

Re: Memory leak issue between extern (c) and D function

2023-04-15 Thread Ali Çehreli via Digitalmars-d-learn
On 4/13/23 20:50, backtrack wrote: > mystruct* getmystruct() > { > mystruct* mystruct = cast(mystruct*)malloc(mystruct.sizeof); > return mystruct; > > } There must be a corresponding function to do the cleaning: void freemystruct(mystruct* ptr) { free ptr;

Re: Assocative array lookup for object

2023-04-12 Thread Ali Çehreli via Digitalmars-d-learn
On 4/12/23 04:35, Salih Dincer wrote: > I made a little mistake and I'll fix it before someone rub nose in it :) You asked for it! :) >auto opIndex(string key) { > if(auto ret = key in data) > { >return *ret; > } > return null; >} Not every type is

Re: How come a count of a range becomes 0 before a foreach?

2023-04-09 Thread Ali Çehreli via Digitalmars-d-learn
On 4/8/23 21:38, ikelaiah wrote: > I will modify the code to construct it twice. Multiple iterations of dirEntries can produce different results, which may or may not be what your program will be happy with. Sticking an .array at the end will iterate a single time and maintain the list

Re: DlangUI Layout Justification

2023-04-07 Thread Ali Çehreli via Digitalmars-d-learn
On 3/9/23 07:09, Ron Tarrant wrote: Many thanks, ryuukk. I'll check it out. I don't know how relevant it is but there is also Hipreme Engine that supports Android: https://forum.dlang.org/thread/fecijdotstuclyzzc...@forum.dlang.org Ali

Re: Code organization, dub, etc.

2023-04-07 Thread Ali Çehreli via Digitalmars-d-learn
On 3/13/23 07:30, Joe wrote: > whether DLang (the Foundation and/or the > community) would consider working with the CMake and clang-format > communities to get them to support D in their products That would be great. I hope it will eventually happen. I've used CMake on existing projects only

Re: member func is best choice for pointers?

2023-04-07 Thread Ali Çehreli via Digitalmars-d-learn
On 4/6/23 07:26, a11e99z wrote: > ```d > import std, core.lifetime; > > struct Node { > Node* pNext; > void func() { "Node::func %s".writeln( pNext); } That's a member function, which works with the obj.func() syntax. However, there is another feature of D that is in play here:

Re: regex matching but not capturing

2023-04-06 Thread Ali Çehreli via Digitalmars-d-learn
On 4/6/23 11:08, Paul wrote: ways to access those repetitive ", cc" s on the end.  I don't think my regex is capturing them. Some internets think you are in parser territory: https://stackoverflow.com/questions/1407435/how-do-i-regex-match-with-grouping-with-unknown-number-of-groups Ali

Re: Virtual method call from constructor

2023-04-04 Thread Ali Çehreli via Digitalmars-d-learn
On 4/4/23 00:08, Chris Katko wrote: > dscanner reports this as a warning: > > ```D > struct foo{ > this() >{ >/* some initial setup */ >refresh(); >} > void refresh() { /* setup some more stuff */} > // [warn] a virtual call inside a constructor may lead to unexpected > results in

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-04 Thread Ali Çehreli via Digitalmars-d-learn
On 4/4/23 02:24, Salih Dincer wrote: > I don't understand what `foreach()` does :) Hm. I forgot whether 'parallel' works only with 'foreach'. But there are various other algorithms in std.parallelism that may be more useful with range algorithm chains:

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-01 Thread Ali Çehreli via Digitalmars-d-learn
On 4/1/23 15:30, Paul wrote: > Is there a way to verify that it split up the work in to tasks/threads > ...? It is hard to see the difference unless there is actual work in the loop that takes time. You can add a Thread.sleep call. (Commented-out in the following program.) Another option is

Re: Why are globals set to tls by default? and why is fast code ugly by default?

2023-04-01 Thread Ali Çehreli via Digitalmars-d-learn
On 3/26/23 13:41, ryuukk_ wrote: > C, C++, Rust, Zig, Go doesn't do TLS by default for example C doesn't do because there was no such concept when it was conceived. C++ doesn't do because they built on top of C. (D does because it has always been innovative.) Go doesn't do because it had no

Re: The Phobos Put

2023-03-29 Thread Ali Çehreli via Digitalmars-d-learn
On 3/29/23 12:21, ag0aep6g wrote: > As far as I understand, you're saying that we cannot overload on `ref`. > But we can. Salih's code demonstrates just that. > > void f(ref int x) {} > void f(int x) {} > void main() { int x; f(x); f(42); } /* no errors */ I thought Salih was proposing two more

Re: The Phobos Put

2023-03-29 Thread Ali Çehreli via Digitalmars-d-learn
On 3/29/23 09:27, Salih Dincer wrote: > In this way, > it could also be used directly with slices. For example: > auto put(R)(R[] range, R[] source) >=> putImpl(range, source); That's for rvalues. > auto put(R)(ref R[] range, R[] source) >=> putImpl(range, source); That's for

Re: The Phobos Put

2023-03-29 Thread Ali Çehreli via Digitalmars-d-learn
On 3/29/23 04:48, Dennis wrote: > On Wednesday, 29 March 2023 at 11:10:42 UTC, Salih Dincer wrote: >> Why does my `put` work but the Phobos `put` doesn't work with a slice? > > Your `put` doesn't take `range` by `ref`, so it allows you to pass an > rvalue. Consequently, it doesn't advance the

Re: Calling assumeSorted on const(std.container.Array)

2023-03-25 Thread Ali Çehreli via Digitalmars-d-learn
On 3/25/23 09:31, Olivier Prat wrote: On Saturday, 25 March 2023 at 13:45:36 UTC, Olivier Prat wrote: I'm trying to call assumeSorted on a const(Array) using this code snippet: [...] In a similar fashion, a number of methods in SortedRange do not compile if called on a const(SortedRange)

Re: Segfault with std.variant

2023-03-25 Thread Ali Çehreli via Digitalmars-d-learn
On 3/24/23 23:07, Mitchell wrote: >variant["four"] = Variant(4); // Segfault Today I learned that VariantN forwards to associative array operations. Cool I guess. :) > with a segfault. I'm using LDC2: Same with dmd. It fails in the destructor of VariantN. static if

Re: Implicit type conversion depending on assignment

2023-03-23 Thread Ali Çehreli via Digitalmars-d-learn
On 3/23/23 07:36, Alexander Zhirov wrote: > @property auto toString(T)() The name is misleading because you want types other than string as well. > alias toString this; That should have been a compilation error because 'toString' does not have a known type (because it depends on a

Re: Implicit type conversion depending on assignment

2023-03-23 Thread Ali Çehreli via Digitalmars-d-learn
On 3/23/23 06:38, Alexander Zhirov wrote: > Is it possible to convert such records inside the structure to the > assigned type? D does not embrace implicit conversions. There is some support like 'alias this' as you mentioned but what you are looking for is not possible. Ali

Re: Threads

2023-03-22 Thread Ali Çehreli via Digitalmars-d-learn
On 3/21/23 22:30, Tim wrote: > to make a simple multi-threading application. Unless there is a reason not to, I recommend std.concurrency and std.parallelism modules. They are different but much more simpler compared to the low-level core.thread. > args_copy = args; //Why program name

Re: alias Error: need 'this'

2023-03-19 Thread Ali Çehreli via Digitalmars-d-learn
On 3/19/23 06:49, bomat wrote: > I can live with the `static` > solution, I guess. If you could, you would define it 'static' anyway. :) Because you highly likely needed a distinct 'variableWithALongName' member for each MyStruct object, that wouldn't work. > Shouldn't it be the exact same

Re: const in functions

2023-03-17 Thread Ali Çehreli via Digitalmars-d-learn
On 3/12/23 16:14, FozzieBear wrote: > On Sunday, 12 March 2023 at 15:09:45 UTC, Salih Dincer wrote: >> >> ... > > So I don't agree with part of this comment (made elsewhere in this thread): > > "You can live without 'const' until your code interacts with other > people's code." My comment was

Re: const in functions

2023-03-13 Thread Ali Çehreli via Digitalmars-d-learn
On 3/13/23 08:17, Salih Dincer wrote: > In this case, using `ref` will increase performance while reducing the > number of copies. I am not sure about that. Unless there is an expensive copy construction, most objects are simple data copies. To use 'ref' or not should be guided through

Re: 'auto' keyword

2023-03-12 Thread Ali Çehreli via Digitalmars-d-learn
On 3/12/23 06:07, DLearner wrote: > 1. As a shorthand to make the type of the variable being declared the > same as the type on the right hand side of an initial assignment. As Adam explained, D already has type inference without a special keyword. However, some places where 'auto' (or

Re: const in functions

2023-03-12 Thread Ali Çehreli via Digitalmars-d-learn
On 3/12/23 08:09, Salih Dincer wrote: > As someone who has used const very little in my life You can live without 'const' until your code interacts with other people's code. For example, the following program works just fine: struct S { int * p; void foo() {} } void bar(S s) {}

Re: How to expand wildchar under dos ?

2023-03-10 Thread Ali Çehreli via Digitalmars-d-learn
On 3/9/23 19:24, John Xu wrote: > Under dos, how to get wildchar matched file names? Have you tried dirEntries? It supports glob patterns: https://dlang.org/library/std/file/dir_entries.html Ali

Re: Passing and returning arguments by ref

2023-03-03 Thread Ali Çehreli via Digitalmars-d-learn
On 3/3/23 12:45, Joe wrote: > I had tried changing B.x1() to: > >`ref X x1() { return [0]; }` > > but the compiler didn't accept it. Yeah, that wouldn't work because the return expression is an X*. Even though 'ref' is implemented as a pointer behind the scenes, that syntax is not legal.

Re: Passing and returning arguments by ref

2023-03-03 Thread Ali Çehreli via Digitalmars-d-learn
On 3/3/23 06:03, Joe wrote: > My understanding was that since A, B and X[] are all reference types, > this ought to work, but obviously something is missing. Think may be due to D not having reference variables. Sometimes one needs to use pointers. I find the following a simpler (and

Re: Bug in DMD?

2023-03-02 Thread Ali Çehreli via Digitalmars-d-learn
On 3/2/23 15:34, ryuukk_ wrote: > the problem is not that it can run in the background, the problem is > figuring out > > 1. how to install > 2. how to setup > 3. how to run I haven't used it myself but dustmite seems to be integrated into dub. 'dub dustmite <...>' Ali

Re: Deciding one member of iteration chain at runtime

2023-02-17 Thread Ali Çehreli via Digitalmars-d-learn
On 2/17/23 09:30, Chris Piker wrote: > operatorG needs > to be of one of two different types at runtime std.range.choose may be useful but I think it requires creating two variables like g1 and g2 below: import std.range; import std.algorithm; void main(string[] args) { const condition

Re: Gneric linkedList range adaptor

2023-02-10 Thread Ali Çehreli via Digitalmars-d-learn
On 2/10/23 14:10, Ben Jones wrote: > Any idea how to fix the helper method? I came up with the following solution: > struct LinkedListAdaptor(alias nextField, T){ In this case nextField will be a callable (a lambda below). > void popFront() { > current = __traits(child,

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-09 Thread Ali Çehreli via Digitalmars-d-learn
On 2/9/23 15:59, ProtectAndHide wrote: > some 'key D > people' (wink wink) [...] > So I hand that over to you .. wink wink. You're trolling[1] again. Ali [1] https://www.merriam-webster.com/dictionary/troll#h3

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-09 Thread Ali Çehreli via Digitalmars-d-learn
On 2/9/23 15:58, thebluepandabear wrote: >> In contrast, I use D every day and love its relaxed attitude towards >> private. > > the fact that private stuff is accessible from other classes in the same > module is really really bad, and it's pretty detrimental to the language. Not everybody

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-09 Thread Ali Çehreli via Digitalmars-d-learn
On 2/9/23 14:34, ProtectAndHide wrote: > You mentioned previously that D implements various things in > unprincipled ways. I think you will continue misunderstanding that term. What it means is, D does not insist on certain programming paradigms over others. For example, you can code in

Re: staticMap but with two arguments

2023-02-09 Thread Ali Çehreli via Digitalmars-d-learn
On 2/9/23 12:45, John Chapman wrote: > On Thursday, 9 February 2023 at 19:17:55 UTC, Ali Çehreli wrote: >> I could not figure out eliminating the hard-coded 4. Can we introspect >> the parameter list of a template like 'fun' in the example? If we >> could, then we could get 4 that way. > > Thank

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-09 Thread Ali Çehreli via Digitalmars-d-learn
On 2/8/23 04:07, zjh wrote: > Last time, someone proposed to add `private` like `C++'s`, We've discussed the 'private' topic very many times already. C++'s private necessitate the 'friend' keyword, which comes with it's own problems. Besides, D has zero problems with its private

Re: Sort Associative Array by Key

2023-02-09 Thread Ali Çehreli via Digitalmars-d-learn
On 2/8/23 23:19, Alexander Zhirov wrote: >> foo.byPair >> .array >> .sort!((a, b) => a.key < b.key) >> .map!(a => a.value); > > Is it possible to specify in `map` to return the result `[a.key] = > a.value`? To make the result look like `[key:[val], key:[val]]` map can return a tuple and

Re: How to debug/set breakpoint a dynamic library.so ?

2023-02-09 Thread Ali Çehreli via Digitalmars-d-learn
On 2/9/23 06:00, mw wrote: The dynamic library.so is built from D (with pyd), and invoked from Python. I'm just wondering How to debug/set breakpoint a dynamic library.so ? Can someone give an example? Thanks. I may be totally off on this but I think it is as simple as the following: gdb

Re: staticMap but with two arguments

2023-02-09 Thread Ali Çehreli via Digitalmars-d-learn
On 2/8/23 12:04, John Chapman wrote: > rather than write it manually for each N? import std.meta : AliasSeq; template pickArgs(size_t totalElements, size_t argsPerElement, size_t whichElement, args...) { alias pickArgs = AliasSeq!();

Re: Comparison of multidimensional associative arrays

2023-02-08 Thread Ali Çehreli via Digitalmars-d-learn
On 2/8/23 11:04, Alexander Zhirov wrote: > That is, the result is arrays of table B that are missing OR not equal > to arrays in table A. This should do it: alias MyType = string[string][int]; // 'a' is subtracted from 'b' MyType difference(MyType b, MyType a) { MyType result;

Re: Comparison of multidimensional associative arrays

2023-02-08 Thread Ali Çehreli via Digitalmars-d-learn
On 2/8/23 09:55, Alexander Zhirov wrote: > the differences Is it considered a difference if a key exists but the value is different? Or is that an error case if you encounter that? > return them when comparing: The representation seems difficult as well. When given this: > 6:["id":"6",

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-07 Thread Ali Çehreli via Digitalmars-d-learn
On 2/6/23 23:33, ProtectAndHide wrote: > On Monday, 6 February 2023 at 21:46:29 UTC, Ali Çehreli wrote: >> And as 'static class' and 'static struct' are already usable in D, a >> newcomer would definitely be confused with your "terrible" conclusion. > You being a little agressive don't you

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-07 Thread Ali Çehreli via Digitalmars-d-learn
On 2/6/23 23:45, ProtectAndHide wrote: > Well I don't agree that D should boast about things that's its > implemented in an unprincipled way. Here, "unprincipled"[1] is just a descriptive word meaning that D does not insist on certain software engineering methodologies e.g. unlike Java where

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-06 Thread Ali Çehreli via Digitalmars-d-learn
On 2/6/23 12:56, ProtectAndHide wrote: > I'm not going to 'go write a > DIP'. Nobody will write a DIP about it because very few people ever mentioned this issue over the years. And as 'static class' and 'static struct' are already usable in D, a newcomer would definitely be confused with

Re: staticMap but with two arguments

2023-02-06 Thread Ali Çehreli via Digitalmars-d-learn
On 2/5/23 17:20, John Chapman wrote: > staticMap's "fun" can only be > instantiated with a single argument, while I need it to work with two. I adapted staticMap's implementation to two sets of arguments: import std.meta : AliasSeq; // The first half of 'args' is the "first arguments" and //

Re: ImportC "no include path set"

2023-02-06 Thread Ali Çehreli via Digitalmars-d-learn
On 2/5/23 22:55, Elfstone wrote: > So how am I supposed to set the include path? I am not familiar with D in Windows but my first guess would be the -I compiler switch: dmd -I=/my/c/headers ... Ali

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-06 Thread Ali Çehreli via Digitalmars-d-learn
On 2/5/23 18:15, ProtectAndHide wrote: > I do not agree, that a compiler that allows a programmer to misuse a > type Types normally have objects. If a programmer found a way to use objects of a memberless type why stop them? > should be seen as 'a feature'. I am not saying I already see

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-06 Thread Ali Çehreli via Digitalmars-d-learn
On 2/5/23 17:50, thebluepandabear wrote: > I don't see why you'd want I am not saying it would be wanted or needed. > to expose a static class/namespace as a > variable, or any of such similar things. That would give no benefits to > the programmer? Perhaps. As I responded to ProtectAndHide,

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-05 Thread Ali Çehreli via Digitalmars-d-learn
On 2/5/23 14:40, ProtectAndHide wrote: > On Sunday, 5 February 2023 at 10:51:51 UTC, thebluepandabear wrote: >> >> It's not a terrible workaround to be honest. >> > > The 'terrible' part is this: > > - the compiler will allow you to declare a variable of type Algo > - the compiler will

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-02-05 Thread Ali Çehreli via Digitalmars-d-learn
On 2/5/23 02:57, thebluepandabear wrote: > When dealing with contexts, or for when you want a clear context in your > codebase, namespaces can be a life saver Can you give an example of a D problem that namespaces could solve? I have been with D for 14 years and haven't missed namespaces from

Re: Are there some helpers in Phobos equivalent to std::set_difference of ugly c++

2023-02-03 Thread Ali Çehreli via Digitalmars-d-learn
On 2/3/23 09:11, Ali Çehreli wrote: 'fold' is Ha ha! :) Make that 'reduce' of course. Ali

Re: Are there some helpers in Phobos equivalent to std::set_difference of ugly c++

2023-02-03 Thread Ali Çehreli via Digitalmars-d-learn
On 2/3/23 08:01, Richard (Rikki) Andrew Cattermole wrote: All good, I'm glad it'll work for you :) I used the word difference to search the phobos docs with. 'fold' is doing much better in that department because it mentions other names: "Implements the homonym function (also known as

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-30 Thread Ali Çehreli via Digitalmars-d-learn
On 1/29/23 22:09, RTM wrote: > On Saturday, 28 January 2023 at 23:19:35 UTC, ProtectAndHide wrote: > >> That is, you can do OOP without classes > > How so? OOP is about putting objects (data) and behavior (functions) together. > Every OOP definition includes classes OOP is possible in C, which

Re: How to get the body of a function/asm statement in hexadecimal

2023-01-29 Thread Ali Çehreli via Digitalmars-d-learn
On 1/29/23 14:19, max haughton wrote: > it is not trivial to find where the *end* of a > function is I suspected as much and did run ... > objdump ... to fool myself into thinking that 0xc3 was . Well, arguments e.g. pointer values can have 0xc3 bytes in them. So, yes, I am fooled! :) Ali

Re: How to get the body of a function/asm statement in hexadecimal

2023-01-29 Thread Ali Çehreli via Digitalmars-d-learn
On 1/29/23 13:45, Ruby the Roobster wrote: > Of course, function pointers cannot be dereferenced. Since you want to see the bytes, just cast it to ubyte*. The following function dumps its own bytes: import std; void main() { enum end = 0xc3; for (auto p = cast(ubyte*)&_Dmain; true;

Re: std.logger issue

2023-01-26 Thread Ali Çehreli via Digitalmars-d-learn
On 1/26/23 12:08, Krzysztof Jajeśnica wrote: > On Thursday, 26 January 2023 at 17:17:28 UTC, o3o wrote: >> how can I enable `trace` level? > > Set `sharedLog.logLevel` instead of `globalLogLevel`. Good catch. I had tried the following without success: stdThreadLocalLog.logLevel =

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-22 Thread Ali Çehreli via Digitalmars-d-learn
On 1/22/23 16:21, thebluepandabear wrote: > Again, stuffing it into a module is not the same thing as a namespace. That is correct but it is also one answer of D's to namespaces. There are others. For example, structs and classes provide namespacing as well. > The user can just bypass this

Re: Function which returns a sorted array without duplicates

2023-01-22 Thread Ali Çehreli via Digitalmars-d-learn
On 1/21/23 23:33, evilrat wrote: > And IIRC you probably don't need `dup` Unfortunately, no. Skipping .dup is only possible if we are allowed to sort the original array. > as sort produces a lazy range. sort() returns a SortedRange but it can't be lazy. Even if it were, the first call to

Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-20 Thread Ali Çehreli via Digitalmars-d-learn
On 1/20/23 07:01, torhu wrote: > But why not have drawLine just be a free function? Exactly. If I'm not mistaken, and please teach me if I am wrong, they are practically free functions in Java as well. That Java class is working as a namespace. So, the function above is the same as the

Re: What is the 'Result' type even for?

2023-01-19 Thread Ali Çehreli via Digitalmars-d-learn
On 1/19/23 19:11, Ruby The Roobster wrote: > typeof(c).stringof.writeln; > The program prints: > > ["a", "b", "c", "d", "e"] > Result > > What is the purpose of this 'Result' type? Just to make sure, 'Result' is what the programmer of a Phobos algorithm chose to name a struct type. It

Re: Problem with ImportC example?

2023-01-18 Thread Ali Çehreli via Digitalmars-d-learn
On 1/18/23 08:04, DLearner wrote: > Unfortunately, neither works: > ``` > C:\Users\SoftDev>cl.exe > 'cl.exe' is not recognized as an internal or external command, > operable program or batch file. That supports the theory that you don't have a C compiler installed that dmd can use for

Re: Problem with ImportC example?

2023-01-17 Thread Ali Çehreli via Digitalmars-d-learn
On 1/17/23 12:02, DLearner wrote: C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c failed launching cl.exe /P /Zc:preprocessor [...] I don't use Windows for development but that error message makes me think cl.exe is not found to be executed. dmd relies on system compiler

Re: Mixin helper help

2023-01-16 Thread Ali Çehreli via Digitalmars-d-learn
On 1/13/23 18:51, bauss wrote: That's a good one! It looks like you liked it four years ago as well. :) I found where I remembered it from: https://forum.dlang.org/post/pvdoq2$1e7t$3...@digitalmars.com Ali

Re: Mixin helper help

2023-01-13 Thread Ali Çehreli via Digitalmars-d-learn
On 1/13/23 00:48, bauss wrote: > 1. Change your mixin template to something like this: There was a technique as a workaround for this template mixin limitation but I can't find it right now. > 2. Change the place where you instantiate to this: I think the workaround I am trying to remember

Re: Creating a pointer/slice to a specific-size buffer? (Handing out a page/frame from a memory manager)

2023-01-13 Thread Ali Çehreli via Digitalmars-d-learn
On 1/13/23 07:22, Gavin Ray wrote: > Maybe it would be better to wrap the slice in a new class with an > invariant? Possibly but please check before using because I think 'invariant' requires presence of member functions: https://dlang.org/spec/struct.html#Invariant > Because what I want

Re: Creating a pointer/slice to a specific-size buffer? (Handing out a page/frame from a memory manager)

2023-01-13 Thread Ali Çehreli via Digitalmars-d-learn
On 1/13/23 07:07, Gavin Ray wrote: > This is "valid" D I hope? Yes because static arrays are just elements side-by-side in memory. You can cast any piece of memory to a static array provided the length and alignment are correct. However, such a cast is not allowed in @safe code. Ali

Re: Creating a pointer/slice to a specific-size buffer? (Handing out a page/frame from a memory manager)

2023-01-13 Thread Ali Çehreli via Digitalmars-d-learn
On 1/13/23 06:49, Gavin Ray wrote: > I am curious if you can return something like `ubyte[PAGE_SIZE]*` or > `ref ubyte[PAGE_SIZE]`? A simple cast seems to work: enum PAGE_SIZE = 4096; enum BUF_POOL_NUM_PAGES = 1024; alias frame_idx_t = size_t; ubyte[10_000] data; ubyte[PAGE_SIZE]*

Re: enum functions

2023-01-11 Thread Ali Çehreli via Digitalmars-d-learn
TLDR Eponymous templates that define a function pointer does not transfer the function call parameter to the enclosing template for type deduction. (Note: The term "deduction" is used with template parameters, not "inference".) Also note that I am replacing 'enum'

Re: Coding Challenges - Dlang or Generic

2023-01-09 Thread Ali Çehreli via Digitalmars-d-learn
On 1/9/23 16:17, Paul wrote: > coding challenges Perhaps the following two? https://rosettacode.org/ https://adventofcode.com/ Ali

Re: Bug or feature? iota has different semantics for integer and float arguments

2023-01-06 Thread Ali Çehreli via Digitalmars-d-learn
On 1/6/23 17:50, Arredondo wrote: > Would anyone volunteer to file a bug report? Me! Me! :) https://issues.dlang.org/show_bug.cgi?id=23604 Ali

Re: Bug or feature? iota has different semantics for integer and float arguments

2023-01-06 Thread Ali Çehreli via Digitalmars-d-learn
On 1/6/23 15:23, Arredondo wrote: > then you get an exception (incorrect startup parameters). Although that difference is a bug, iota does have a special floating point implementation to prevent the accumulation of floating point errors. I mention it as item 4 here:

Re: Address of a class object

2023-01-04 Thread Ali Çehreli via Digitalmars-d-learn
On 1/4/23 20:04, Paul wrote: >> (Again, there is no problem here; we are just learning.) >> Ali > > Do I have this much right? > ..with this output? Looks good to me. While we're here, you can force the class objects to be on the stack as well: scope MyClassVar1 = new MyClass(); I

  1   2   3   4   5   6   7   8   9   10   >