Re: Threading challenge: calculate fib(45) while spinning

2021-10-15 Thread Ali Çehreli via Digitalmars-d-learn
On 10/14/21 8:54 PM, Ali Çehreli wrote: >writefln!"\rFibonacci(%d) = %d"(n, fibN); That '\r' bothered me because the actual work needs to know what the spinner is doing to clear its remaining character. >receiveTimeout(delay, > (OwnerTerminated msg) { And

Re: Threading challenge: calculate fib(45) while spinning

2021-10-14 Thread Ali Çehreli via Digitalmars-d-learn
On 10/14/21 9:17 PM, jfondren wrote: On Friday, 15 October 2021 at 03:54:17 UTC, Ali Çehreli wrote: On 10/14/21 8:35 PM, jfondren wrote: The book, "The Go Programming Language" has this simple goroutine example: Here is one that uses receiveTimeout and OwnerTerminated: Very nice,

Re: Threading challenge: calculate fib(45) while spinning

2021-10-14 Thread Ali Çehreli via Digitalmars-d-learn
On 10/14/21 8:35 PM, jfondren wrote: The book, "The Go Programming Language" has this simple goroutine example: Here is one that uses receiveTimeout and OwnerTerminated: import std.stdio; import std.concurrency; import core.thread; void main() { spawnLinked(, 100.msecs); enum n = 45;

Re: Structured binding declaration (like in C++)

2021-10-14 Thread Ali Çehreli via Digitalmars-d-learn
On 10/13/21 1:02 PM, Vindex wrote: Is there a decomposition for tuples and other data structures? For example, ``` auto t = tuple(1, "2"); auto (x, y) = t; // or auto (x, y) = t.expand; ``` No, D does not have this (yet?). I thought there was a special case for tuples with foreach but I

Re: Create array from range

2021-10-09 Thread Ali Çehreli via Digitalmars-d-learn
On 10/9/21 4:58 PM, Greg Strong wrote: How do I filter some elements of an array into a new array? This doesn't answer your specific question but std.algorithm.remove may be usable in some cases: https://dlang.org/phobos/std_algorithm_mutation.html#remove If it matters, the following

Re: Python's list equivalent with std.variant?

2021-10-03 Thread Ali Çehreli via Digitalmars-d-learn
On 10/3/21 3:22 PM, rjkilpatrick wrote: > I am trying to emulate Python's list in D, to store some derived classes I notice your code comment about SuperClass[]. It is still the most obvious solution here. You just need to check the reuslt of a cast(DerivedClass): import std.stdio :

Re: Modules ... "import" vs. "compilation" ... what is the real process here?

2021-09-27 Thread Ali Çehreli via Digitalmars-d-learn
On 9/27/21 10:38 AM, james.p.leblanc wrote: > I have trouble understanding "module imports" vs. "module compilations". In addition to what Mike Parker said, templates do complicate matters here: Templates are instantiated (i.e. compiled for a specific set of template arguments) by modules

Re: abstract classes and interfaces

2021-09-27 Thread Ali Çehreli via Digitalmars-d-learn
On 9/27/21 9:30 AM, kyle wrote: That'd be great. Long live Beefconf. I miss it way too often. Gotta have some beet ready for the next BeetConf. :p Ali

Re: Mixin programming foreach

2021-09-27 Thread Ali Çehreli via Digitalmars-d-learn
On 9/27/21 10:26 AM, Tejas wrote: > On Monday, 27 September 2021 at 17:14:11 UTC, Ali Çehreli wrote: >> On 9/27/21 9:23 AM, eXodiquas wrote: >> >> > [...] >> >> Same here. :) >> >> > [...] >> >> Often repeated but there are no stupid questions. >> >> [...] > > Sometimes I wonder if I should

Re: Mixin programming foreach

2021-09-27 Thread Ali Çehreli via Digitalmars-d-learn
On 9/27/21 9:23 AM, eXodiquas wrote: > I found this forum very helpful Same here. :) > for my (maybe) stupid questions Often repeated but there are no stupid questions. > First of all, I'm not exactly sure what this code here, from the > documentation at

Re: write struct as raw data to file

2021-09-26 Thread Ali Çehreli via Digitalmars-d-learn
Correcting my sloppy code. :) On 9/26/21 8:53 AM, Ali Çehreli wrote: >// We need an array Ses (length of 1 in this case) >auto ses = new S[1]; Allocating a dynamic array there is egregious pessimization. The following works the same but this time the static array of a single S will be

Re: write struct as raw data to file

2021-09-26 Thread Ali Çehreli via Digitalmars-d-learn
rawRead and rawWrite work with slices (arrays) of things. You need to use an array of your struct even if there is a single item. Here is an example: import std.stdio; import std.file; struct S { int i; double d; } void readFrom(string name) { // We need an array Ses (length of 1 in

Re: associative array with element type struct ?

2021-09-23 Thread Ali Çehreli via Digitalmars-d-learn
On 9/23/21 3:06 PM, Paul wrote: > Can I have an associative array with the element type being a struct? Of course! And it's very common. :) > ...this > 26 // simple dual tone key struct > 27 struct keytones { ushort rowFreq; ushort colFreq; } > 28 > 29 // keypad associative array > 30

Re: Why dtor are not executed when removing a struct from associative arrays?

2021-09-20 Thread Ali Çehreli via Digitalmars-d-learn
On 9/20/21 5:23 AM, Learner wrote: I was expecting S instance dtor called S is being destructed If you are sure the element can be destroyed, you can call destroy(): import std.stdio; enum someSpecialInitValue = 777; struct S { int i = someSpecialInitValue; this(int i) { this.i

Re: What is the meaning of @future ?

2021-09-18 Thread Ali Çehreli via Digitalmars-d-learn
On 9/18/21 1:27 AM, evilrat wrote: > IIRC they went out of business for inability to compete Yes, but not Sociomantic but Dunhumby[1], who had acquired Sociomantic, shut down that business because of changes in the ad market. Ali

Re: Merge 2 structs together (into a single struct)?

2021-09-16 Thread Ali Çehreli via Digitalmars-d-learn
On 9/16/21 1:12 PM, james.p.leblanc wrote: > I really thought that this would be a simple enough > small project in meta programming/reflection. It should be doable. One question is how to resolve conflicting members of the two structs, which can be defaulted to one of the policies "cause

Re: Program crash: GC destroys an object unexpectedly

2021-09-14 Thread Ali Çehreli via Digitalmars-d-learn
On 9/14/21 9:56 AM, eugene wrote: > On Tuesday, 14 September 2021 at 16:43:50 UTC, jfondren wrote: >> The misaligned pointer and the >> reference-containing struct that vanishes on the return of your >> corresponding function are both problems for this. > > where did you find 'misaligned

Re: Building several dynamic libraries with one shared GC

2021-09-12 Thread Ali Çehreli via Digitalmars-d-learn
On 9/12/21 1:25 PM, NonNull wrote: On Sunday, 12 September 2021 at 18:56:50 UTC, Ali Çehreli wrote: All initialization functions of the plugins were called automatically in my D test environment and all plugins were usable. The trouble started when the main library was being used in a foreign

Re: Building several dynamic libraries with one shared GC

2021-09-12 Thread Ali Çehreli via Digitalmars-d-learn
On 9/12/21 7:31 AM, NonNull wrote: > I am making a plug-in development system for a high performance Linux > application that already exists and is written in C and will not be > modified for this purpose. I've done something similar but in my case the main application is in D and the plugins

Re: Ali's Book - Programming in D

2021-09-10 Thread Ali Çehreli via Digitalmars-d-learn
On 9/10/21 11:05 AM, Ron Tarrant wrote: On Friday, 10 September 2021 at 14:21:12 UTC, Ali Çehreli wrote: tldr; Yes, it's print-on-demand and 2019 is correct for the current print edition. I would download the PDF version from ddili.org. D version: 2.094.2 Book revision: 2021-02-26 Off the

Re: Ali's Book - Programming in D

2021-09-10 Thread Ali Çehreli via Digitalmars-d-learn
On 9/10/21 4:48 AM, Ron Tarrant wrote: > On Friday, 10 September 2021 at 10:59:10 UTC, bauss wrote: > >> Publisher ‏ : ‎ CreateSpace Independent Publishing Platform; 1st >> edition (Aug. 19 2015) > > Yeah, I saw that, too. And if you do a "Look inside," the copyright date > is 2019... thus my

Re: Documentation generator is not working

2021-09-05 Thread Ali Çehreli via Digitalmars-d-learn
On 9/5/21 3:22 PM, Vinod K Chandran wrote: On Friday, 3 September 2021 at 20:21:43 UTC, Ali Çehreli wrote: So, change your program to respond to -D and generate the documentation potentially by spawning a dmd instance. :o) I am not sure i get the point correctly. You mean, starting dmd as

Re: Forum posting question ... how post a thread question with color syntax highlighting ??

2021-09-05 Thread Ali Çehreli via Digitalmars-d-learn
On 9/5/21 4:24 PM, someone wrote: > > For example; IIRC Ali's posts are always no-markdown. > That's because I've been using Thunderbird for mail and news for a long time now and unfortunately it is impossible to convince Thunderbird to add the necessary header field. (Vladimir has a

Re: "+=" (overloads) with custom array slices on both lhs, and rhs ??

2021-09-05 Thread Ali Çehreli via Digitalmars-d-learn
On 9/5/21 12:43 PM, james.p.leblanc wrote: > I have constructed a custom array type that works, but is missing > correct functioning on some operator overloads. With its old, new, and newest styles; and support for multi-dimensional use cases; operator overloading can be difficult to get

Re: Documentation generator is not working

2021-09-03 Thread Ali Çehreli via Digitalmars-d-learn
On 9/2/21 10:38 AM, Vinod K Chandran wrote: On Thursday, 2 September 2021 at 17:34:59 UTC, Adam D Ruppe wrote: Anything after -run goes to your program not the compiler. Args to the compiler must be before -run. Thanks for the reply. Got the point now. :) So, change your program to

Re: Run-time setting of immutable variable?

2021-09-02 Thread Ali Çehreli via Digitalmars-d-learn
On 9/2/21 9:01 AM, DLearner wrote: Suppose there is a variable that is set once per run, and is (supposed) never to be altered again. An accessor function can be a solution, which supports your other comment about data potentially mutating by other means: // Assume these are in a module //

Re: Labelled @nogc Working With Inner Scopes

2021-08-30 Thread Ali Çehreli via Digitalmars-d-learn
I don't have a strong opinion on the question but I tend to agree with the current behavior because it's easy to add the attributes anyway. Going off topic, I want to mention that the 'in' and 'out' contracts have a simpler syntax now and that the 'do' (or 'body') keyword is optional in that

Re: pipeProcess, interactions with stderr ... I am missing something here

2021-08-30 Thread Ali Çehreli via Digitalmars-d-learn
On 8/30/21 9:35 AM, james.p.leblanc wrote: > D-ers, > > I am attempting to use pipeProcess for interacting with an external > process. > My simplified routine can work somewhat. But, trying to print any messages > that process writes to stderr yields the message: > > (master) gnuplot >

Re: template parameters

2021-08-29 Thread Ali Çehreli via Digitalmars-d-learn
On 8/29/21 3:31 PM, Charles Hixson wrote: > Thanks. I going to have to study: > > enum supportsCall = isIntegral!(typeof(T.init.%s())); > > > for awhile to make any sense of that, but it looks like just what I was > looking for. Trying to explain with comments: // This is an eponymous template

Re: template parameters

2021-08-29 Thread Ali Çehreli via Digitalmars-d-learn
On 8/29/21 11:32 AM, Charles H. wrote: I've set up a class template (so far untested) thus:     class    AARL (T, ndx = "ndx")     if (isIntegral(T.init.ndx) )     If I'm correct, this should work for ndx an integer variable of T, but I'd really like T to be able to be anything

Re: byte + byte = int: why?

2021-08-29 Thread Ali Çehreli via Digitalmars-d-learn
On 1/18/19 9:09 AM, Mek101 wrote: > source/hash.d(11,25): Error: cannot implicitly convert expression > `cast(int)temp[fowardI] + cast(int)temp[backwardI]` of type `int` to `byte` Others suggested casting as a solution which works but it will hide potential errors. Depending on the

Re: byte + byte = int: why?

2021-08-29 Thread Ali Çehreli via Digitalmars-d-learn
On 8/29/21 3:57 AM, Rekel wrote: On Friday, 18 January 2019 at 18:49:23 UTC, Steven Schveighoffer wrote: As others have said, those are the rules D has for historical reasons, you just have to deal with them. Is that to ensure compatibility with C? Yes. It's mentioned multiple times in

Re: A little help with Ranges

2021-08-26 Thread Ali Çehreli via Digitalmars-d-learn
On 8/26/21 7:17 PM, Merlin Diavova wrote: What I meant about the handling an empty filter is, what if I want to take an alternative route if the filter returns empty? Then the operations downstream will not produce any results. For example, the array will be empty below: import std.stdio;

Re: Scope of Mixins

2021-08-26 Thread Ali Çehreli via Digitalmars-d-learn
On 8/26/21 10:45 AM, Adam D Ruppe wrote: On Thursday, 26 August 2021 at 17:39:16 UTC, Ali Çehreli wrote: String mixins are appealing because they can inject code like C macros do. It's not trivially possible to do the same with template mixins. Template mixins are great, but obviously totally

Re: Scope of Mixins

2021-08-26 Thread Ali Çehreli via Digitalmars-d-learn
On 8/26/21 10:06 AM, Adam D Ruppe wrote: On Thursday, 26 August 2021 at 17:01:06 UTC, DLearner wrote: The object was to take a variable, and do alternative things with it depending on (say) whether it was an 'int' or an 'int*'. That's *very* easy to do with the alias. You can just check

Re: foreach() behavior on ranges

2021-08-24 Thread Ali Çehreli via Digitalmars-d-learn
On 8/24/21 1:44 PM, Ferhat Kurtulmuş wrote: > Just out of curiosity, if a range implementation uses malloc in save, is > it only possible to free the memory with the dtor? Yes but It depends on the specific case. For example, if the type has a clear() function that does clean up, then one

Re: Possible to overload assignment of struct field ??

2021-08-23 Thread Ali Çehreli via Digitalmars-d-learn
On 8/23/21 10:25 PM, james.p.leblanc wrote: So, you need a "property". Easy... :) 1) Rename the member e.g. as a_. 2) Write setter and getter functions named 'a'. struct Foo{ int a_; int a() const { return a_; } void a(int value) { a_ = value; } } void main(){ auto x =

Re: Potential strategy for avoiding problems with copy of a struct (maybe??)

2021-08-22 Thread Ali Çehreli via Digitalmars-d-learn
On 8/22/21 6:03 AM, james.p.leblanc wrote: > struct Foo { > int a, b, c; > Foo* myadd; > > this(int a, int b, int c) { > this.a = a; > this.b = b; > this.c = c; > this.myadd = As Matthias Lang mentioned,

Re: modules and mains

2021-08-21 Thread Ali Çehreli via Digitalmars-d-learn
On 8/21/21 8:46 PM, Brian Tiffin wrote: > prompt$ cat B.d > module B; > version = boss; A cannot know about 'version' condition inside B. The solution is to provide version on the command line. This is how I do it with dmd: $ dmd -version=boss [...] (So, remove 'version = boss;' line in

Re: Unqualified class name

2021-08-21 Thread Ali Çehreli via Digitalmars-d-learn
On 8/21/21 2:48 PM, jfondren wrote: On Saturday, 21 August 2021 at 21:13:58 UTC, Jeremy T. Gibson wrote: On Saturday, 21 August 2021 at 18:27:34 UTC, Ali Çehreli wrote:     return __traits(identifier, typeof(this)); That works perfectly!  Thanks. =) This is exactly the solution you linked

Re: Unqualified class name

2021-08-21 Thread Ali Çehreli via Digitalmars-d-learn
On 8/21/21 10:33 AM, Jeremy T. Gibson wrote: `typeid(class).name` always yields the full classname, including its module information (i.e., "modulename.classname"), where I only want "classname" on its own. I've been reminded of __traits(identifier) on this forum just yesterday: import

Re: Lexicographical object comparison by selected members of a struct

2021-08-21 Thread Ali Çehreli via Digitalmars-d-learn
On 8/21/21 1:31 AM, Tejas wrote: > I was more impressed that you found that hack in the first place I can't take credit. :) 'static foreach' had that difference since its inception. The spec says "If a new scope is desired for each expansion, use another set of braces:"

Re: Lexicographical object comparison by selected members of a struct

2021-08-21 Thread Ali Çehreli via Digitalmars-d-learn
On 8/20/21 11:19 PM, Tejas wrote: On Saturday, 21 August 2021 at 06:03:33 UTC, Ali Çehreli wrote: On 8/20/21 10:37 PM, Alexandru Ermicioi wrote: [...] Cool! Much better. :) I could not do [...] Did you use that double curly bracket in `static foreach` so that you don't get error for

Re: Lexicographical object comparison by selected members of a struct

2021-08-21 Thread Ali Çehreli via Digitalmars-d-learn
On 8/20/21 10:37 PM, Alexandru Ermicioi wrote: On Saturday, 21 August 2021 at 05:34:59 UTC, Alexandru Ermicioi wrote: ... Also there is no need for mixing string code here. You can get the field using __traits(getMember, this, member). Cool! Much better. :) I could not do static

Lexicographical object comparison by selected members of a struct

2021-08-20 Thread Ali Çehreli via Digitalmars-d-learn
Sometimes I need comparison operators that should consider only some members of a struct: struct S { int year; // Primary member int month;// Secondary member string[] values; // Irrelevant } I've been using the laziest tuple+tupleof solution in some of my structs:

Re: Non-consistent implicit function template specializations

2021-08-18 Thread Ali Çehreli via Digitalmars-d-learn
On 8/18/21 4:10 AM, Rekel wrote: >> isArray!T && (isArray!(ElementType!T)) > > I tried looking into how isArray is defined. Like, does being able to > index mean it's an array, or are these only static &/or dynamic arrays? The definitions are in phobos/std/traits.d enum bool isArray(T) =

Re: Concurrency message passing

2021-08-17 Thread Ali Çehreli via Digitalmars-d-learn
On 8/17/21 11:36 AM, JG wrote: >>> Maybe message parsing isn't the >>> correct solution? I use message passing in many of my programs. > After being populated it should be passed to > the other thread and no references are kept. Then you simply cast to-and-from 'shared' and be happy with it.

Re: Non-consistent implicit function template specializations

2021-08-17 Thread Ali Çehreli via Digitalmars-d-learn
On 8/17/21 2:59 AM, Rekel wrote: > template TFoo(T){ void foo(){writeln("1");} } // #1 > template TFoo(T : T[]) { void foo(){writeln("2");} } // #2 I don't have such problems because I am not smart enough to understand that syntax so I don't use it. :) I use template constraints

Re: simple (I think) eponymous template question ... what is proper idimatic way ?

2021-08-17 Thread Ali Çehreli via Digitalmars-d-learn
On 8/17/21 11:11 AM, james.p.leblanc wrote: > auto foo(T)(T a, T b) { ... } > > Now, suppose I need to restrict "T" only certain subsets of variable types. There are template constraints: import std.traits; auto foo(T)(T a, T b) if (isArray!T) { // ... } auto foo(T)(T a, T b) if

Re: Drawbacks of exceptions being globally allocated

2021-08-15 Thread Ali Çehreli via Digitalmars-d-learn
On 8/15/21 2:10 AM, Alexandru Ermicioi wrote: >> This may be useful in some cases but in general, these colatteral >> exceptions don't carry much information and I don't think anybody >> looks at them. Usually, the first one is the one that explains the >> error case. > That is just an

Re: What exactly are the String literrals in D and how they work?

2021-08-15 Thread Ali Çehreli via Digitalmars-d-learn
Lot's of great information and pointers already. I will try from another angle. :) On 8/14/21 11:10 PM, rempas wrote: > So when I'm doing something like the following: `string name = "John";` > Then what's the actual type of the literal `"John"`? As you say and as the code shows, there are

Re: Drawbacks of exceptions being globally allocated

2021-08-14 Thread Ali Çehreli via Digitalmars-d-learn
On 8/14/21 4:41 AM, Tejas wrote: > What is the drawback of the following "simple" ```@nogc``` exception > creation technique? > > ```d > import std; > void main()@nogc > { > try{ > __gshared a = new Exception("help"); > scope b = a; > throw b; > } >

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread Ali Çehreli via Digitalmars-d-learn
On 8/13/21 4:23 PM, Marcone wrote: > string x = "Hello World!"; > writeln(x[x.indexOf("e")..x.indexOf("r")]); I don't see the usefulness and there are the following problems with it: - Not an algorithmic complexity issue but it sounds to me like a pessimization to go through the elements in

Re: How to extend the string class to return this inside the square bracket?

2021-08-13 Thread Ali Çehreli via Digitalmars-d-learn
On 8/13/21 4:08 PM, jfondren wrote: On Friday, 13 August 2021 at 22:09:59 UTC, Marcone wrote: Isn't there some unario operator template that I can use with lambda to handle a string literal? So, something other than an exact "lit"[0..this.xx(..)] syntax is fine? What didn't you like about

Re: Anyway to achieve the following

2021-08-13 Thread Ali Çehreli via Digitalmars-d-learn
On 8/13/21 1:25 AM, JG wrote: > Suppose one has a pointer p of type T*. > Can on declare variable a of type T which is stored in the location > pointed to by p? You may be looking for core.lifetime.emplace. (core.lifetime is not on dlang.org at the moment for me but it is under

Re: I do not understand copy constructors

2021-08-12 Thread Ali Çehreli via Digitalmars-d-learn
On 8/12/21 4:32 AM, Paul Backus wrote: > Qualifying the ctor as `inout` works fine I can see how a DConf Online presention is shaping up in your head. ;) http://dconf.org/2021/online/index.html We need a collective understanding of effective use of such fundamental concepts. Ali

Re: D has the same memory model as C++

2021-08-11 Thread Ali Çehreli via Digitalmars-d-learn
On 8/11/21 12:19 PM, Tejas wrote: Atleast leave some pointers on where to start :( I DuckDuckGo'ed it for you. :) https://en.cppreference.com/w/cpp/language/memory_model Then looked it up at Wikipedia too: https://en.wikipedia.org/wiki/Memory_model_(programming) Ali

Re: D has the same memory model as C++

2021-08-11 Thread Ali Çehreli via Digitalmars-d-learn
This is an interesting thread but "memory model" does not cover or mean all of the points discussed here. I can't define it precisely, so I'm leaving it to interested parties to search for themselves. :) Ali

Re: writef, compile-checked format, pointer

2021-08-10 Thread Ali Çehreli via Digitalmars-d-learn
On 8/9/21 10:03 PM, nov wrote: > i dreamed that programming will be less-error with compile checking format. I still think so because many errors that can be caught at compile time are moved to run time in non-statically-typed languages. > but reality disappoint :( > message for every

Re: writef, compile-checked format, pointer

2021-08-09 Thread Ali Çehreli via Digitalmars-d-learn
On 8/9/21 3:46 PM, Adam D Ruppe wrote: > The compile time checker [...] implementation is really really > slow and pretty bloated in codegen too. > > My personal policy is to never use it. My personal policy is to kindly ask you to fix it! :p Ali

Re: writef, compile-checked format, pointer

2021-08-09 Thread Ali Çehreli via Digitalmars-d-learn
On 8/9/21 3:01 PM, Patrick Schluter wrote: > On Monday, 9 August 2021 at 19:38:28 UTC, novice2 wrote: >> format!"fmt"() and writef!"fmt"() templates >> with compile-time checked format string >> not accept %X for pointers, >> >> but format() and writef() accept it >> >>

Re: Proper way to protect (lock) a struct field after initialization ??

2021-08-08 Thread Ali Çehreli via Digitalmars-d-learn
On 8/8/21 3:11 AM, james.p.leblanc wrote: Hello All. Is there a standard way to protect a field of a struct after the struct has been initialized? Is this possible with a struct? If not, I suppose a class (object) would be needed?  If so, are there any simple pointers to an example of this?

Re: best/proper way to declare constants ?

2021-08-05 Thread Ali Çehreli via Digitalmars-d-learn
On 8/5/21 5:11 PM, someone wrote: > Although I have very little experience with D, I second this: > refactoring, even huge refactors, proved to be far more straightforward > than I expected. May I humbly suggest names like Location instead of structureLocation to make refactoring even more

Re: __traits() to get parameter details only ? ... hasMember looks up everything within

2021-08-05 Thread Ali Çehreli via Digitalmars-d-learn
On 8/4/21 7:21 PM, someone wrote: > somewhere I read > Ali saying there's nothing wrong implementing properties the old-way via > functions because @property has nothing special about it but I can't > state where I read what I am stating so take it with a grain of salt. As I understand it,

Re: __FILE__

2021-08-04 Thread Ali Çehreli via Digitalmars-d-learn
On 8/4/21 7:17 PM, Steven Schveighoffer wrote: >> The compiler has to evaluate the default argument as constant >> expression in order to use it as default value.. > > This is not true, you can use runtime calls as default values. What??? I just checked and it works! :) string bar() {

Re: module search paths

2021-08-03 Thread Ali Çehreli via Digitalmars-d-learn
On 8/3/21 9:51 PM, Brian Tiffin wrote: > I added an `import std.json;`. That did not include the > JSONType enum. It works for me: import std.json; int main() { return JSONType.null_; } > Is there a go to quick and easy way of tracking down > module members? Searching for it at dlang.org

Re: Find struct not passed by reference

2021-08-03 Thread Ali Çehreli via Digitalmars-d-learn
On 8/3/21 12:22 PM, frame wrote: On Tuesday, 3 August 2021 at 19:19:27 UTC, jfondren wrote: On Tuesday, 3 August 2021 at 19:11:16 UTC, frame wrote: On Tuesday, 3 August 2021 at 16:35:04 UTC, Ali Çehreli wrote: Why foreach() does not accept a pointer? pointers don't come with a length?

Re: align dynamic array (for avx friendliness) hints? / possible??

2021-08-03 Thread Ali Çehreli via Digitalmars-d-learn
On 8/3/21 10:50 AM, james.p.leblanc wrote: > **Is there some highly visible place this is already documented? For what it's worth, it appears as "slice from pointer" in my index: http://ddili.org/ders/d.en/pointers.html#ix_pointers.slice%20from%20pointer Admittedly, one needs to know the

Re: Name Mangling & its representation of D types

2021-08-03 Thread Ali Çehreli via Digitalmars-d-learn
On 8/3/21 9:43 AM, NonNull wrote: I'd like to understand how any D type is represented as a string by the name mangling done by the compilers. Related article that mentions .mangleof, a property of all symbols: https://dlang.org/blog/2017/12/20/ds-newfangled-name-mangling/ Ali

Re: Find struct not passed by reference

2021-08-03 Thread Ali Çehreli via Digitalmars-d-learn
On 8/2/21 4:06 PM, frame wrote: Is there a way to find a struct which should be passed by reference but accidentally isn't? Maybe with copy constructors? If I understand it correctly, your current value-type needs to be a reference type. Would the following be workable solutions? a) Classes

Re: Is returning void functions inside void functions a feature or an artifact?

2021-08-02 Thread Ali Çehreli via Digitalmars-d-learn
On 8/2/21 9:42 AM, Rekel wrote: > when would one use an alias instead of a > function/delegate? I haven't used aliases before. alias will match both functions and delegates... and... any symbol at all. So, if you don't have a reason to constain the user, callable template parameters are most

Re: Exit before second main with -funittest

2021-07-31 Thread Ali Çehreli via Digitalmars-d-learn
On 7/30/21 7:48 PM, Brian TIffin wrote: > Found, find, C++ too hot for most to handle, so why? I rubbed shoulders with C++ people who would argue to the effect of "C++ was not meant to be for everyone." > And a deeper thanks, Ali, for the book. You're welcome. I am very happy when it is

Re: Exit before second main with -funittest

2021-07-30 Thread Ali Çehreli via Digitalmars-d-learn
On 7/30/21 3:08 PM, Brian Tiffin wrote: > Don't take to C++, never have, even while watching > cfront and Walter having the first** brain to craft a native compiler. [...] > ** I'm not sure Walter was first first, or close first, or... He wrote the first C++ compiler. (cfront was a C++-to-C

Re: Exit before second main with -funittest

2021-07-30 Thread Ali Çehreli via Digitalmars-d-learn
On 7/29/21 9:22 PM, Mathias LANG wrote: > On Friday, 30 July 2021 at 03:45:21 UTC, Ali Çehreli wrote: >> Almost all of my programs are in the following pattern: >> >> ```D >> import std.stdio; >> >> void main(string[] args) { >> version (unittest) { >> // Don't execute the main program

Re: Exit before second main with -funittest

2021-07-29 Thread Ali Çehreli via Digitalmars-d-learn
Almost all of my programs are in the following pattern: import std.stdio; void main(string[] args) { version (unittest) { // Don't execute the main program when unit testing return; } try { // Dispatch to the actual "main" function doIt(args); } catch (Exception exc) {

Re: Performance issue with fiber

2021-07-28 Thread Ali Çehreli via Digitalmars-d-learn
On 7/28/21 1:15 AM, hanabi1224 wrote: > On Wednesday, 28 July 2021 at 01:12:16 UTC, Denis Feklushkin wrote: >> Spawning fiber is expensive > > Sorry but I cannot agree with the logic behind this statement, the whole > point of using fiber is that, spwaning system thread is expensive, thus > ppl

Re: Why does Unconst exist?

2021-07-27 Thread Ali Çehreli via Digitalmars-d-learn
On 7/27/21 10:38 PM, Tejas wrote: When I initially saw it, I was hopeful that it would allow me to bypass some of the restrictions of ```const``` , but it literally just takes a type and strips the ```const``` from it, you can't pass a variable to it in order to get rid of ```const``` . What

Re: POST request with std.net.curl

2021-07-23 Thread Ali Çehreli via Digitalmars-d-learn
On 7/23/21 11:11 AM, bachmeier wrote: I'm writing a D program that interacts with the Todoist API using std.net.curl. It's not a problem to do get requests to query tasks, but I cannot find a way to get post to work to create a new task. This is a working bash script, where APIKEY is defined

Re: How to Fix Weird Build Failure with "-release" but OK with "-debug"?

2021-07-23 Thread Ali Çehreli via Digitalmars-d-learn
On 7/23/21 12:30 PM, apz28 wrote: > The -debug build with passing unit-tests so no problem there. > The -release build is having problem. After make change to accommodate > it, it takes forever to build. I started it yesterday 11AM and it is > still compiling now (more than a day already.) It

Re: enum true, or 1

2021-07-23 Thread Ali Çehreli via Digitalmars-d-learn
On 7/22/21 1:44 PM, Brian Tiffin wrote: > So would there be any cringes Not from me. :) > seeing a skeleton D source file that > always ended with > > ~~~d > /++ > Disclaimer > > This software is distributed in the hope that it will be useful, but > WITHOUT ANY WARRANTY; direct

Re: Initializing a complex dynamic array (with real part from one array, and imaginary from other array)?

2021-07-22 Thread Ali Çehreli via Digitalmars-d-learn
On 7/21/21 2:17 AM, drug wrote: > auto z = zip(x, y) // concatenate two ranges > .map!(a=>Complex!double(a[0],a[1])) // take the current first > element of the first range as the real part and the current first > element of the second range as the imaginary

Re: associative array with Parallel

2021-07-22 Thread Ali Çehreli via Digitalmars-d-learn
On 7/21/21 11:01 PM, frame wrote: > This is another parallel foreach body conversion question. > Isn't the compiler clever enough to put a synchronized block here? parallel is a *function* (not a D feature). So, the compiler might have to analyze the entire code to suspect race conditions. No,

Re: enum true, or 1

2021-07-21 Thread Ali Çehreli via Digitalmars-d-learn
On 7/21/21 8:44 PM, Brian Tiffin wrote: > What is the preferred syntax for simple on/off states? I use std.typecons.Flag. It feels very repetitive but that's what we have: import std.typecons; void foo(Flag!"doFilter" doFilter) { if (doFilter) { // ... } } bool someCondition; void

Re: Not allowed to globally overload operators?

2021-07-20 Thread Ali Çehreli via Digitalmars-d-learn
On 7/20/21 11:49 AM, H. S. Teoh wrote: > On Tue, Jul 20, 2021 at 11:32:26AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: >> On 7/19/21 11:20 PM, Tejas wrote: >> >>> trying to create the spaceship operator of C++ >> >> Just to make sure, D's opCmp r

Re: Not allowed to globally overload operators?

2021-07-20 Thread Ali Çehreli via Digitalmars-d-learn
On 7/19/21 11:20 PM, Tejas wrote: > trying to create the spaceship operator of C++ Just to make sure, D's opCmp returns an int. That new C++ operator was added to provide the same semantics. Ali

Re: Yet another parallel foreach + continue question

2021-07-20 Thread Ali Çehreli via Digitalmars-d-learn
On 7/19/21 5:07 PM, seany wrote: > Consider : > > for (int i = 0; i < max_value_of_i; i++) { > foreach ( j, dummyVar; myTaskPool.parallel(array_to_get_j_from, > my_workunitSize) { > > if ( boolean_function(i,j) ) continue; > double d =

Re: Including a file

2021-07-18 Thread Ali Çehreli via Digitalmars-d-learn
On 7/18/21 10:28 AM, Vindex wrote: > ``` > ldc2 source/main.d -ofmyprogram -L-l:libmylib.so.0 > Error: file "thing.json" cannot be found or not in a path specified with -J > ``` > > Is the actual inclusion of the file on import deferred until the link step? I wonder whether it's an ldc

Re: function parameters: is it possible to pass byref ... while being optional at the same time ?

2021-07-17 Thread Ali Çehreli via Digitalmars-d-learn
On 7/17/21 8:52 PM, someone wrote: > I am a self-taught programmer Same here. > well before college Not here because I had access to a Sinclair Spectrum only in 1985. :/ > I have a degree in electronics engineering Same here. > one of the things that I felt in love with when I was first

Re: function parameters: is it possible to pass byref ... while being optional at the same time ?

2021-07-17 Thread Ali Çehreli via Digitalmars-d-learn
On 7/17/21 6:49 PM, Brian Tiffin wrote: > *Practice makes perfect? No, practice makes permanent.* One reference for that quote is "Classical Guitar Pedagogy" by Anthony Glise, Chapter Nine--Practicing. ;) Ali

Re: Creating immutable arrays in @safe code

2021-07-16 Thread Ali Çehreli via Digitalmars-d-learn
On 7/16/21 3:21 PM, Dennis wrote: > But `pure` is no silver bullet: Agreed. I occasionally struggle with these issues as well. Here is a related one: import std; void foo(const int[] a) { auto b = a.array; b.front = 42; // Error: cannot modify `const` expression `front(b)` } I think

Re: Creating immutable arrays in @safe code

2021-07-16 Thread Ali Çehreli via Digitalmars-d-learn
On 7/16/21 1:19 PM, Dennis wrote: > I like passing around immutable data I think the D community needs to talk more about guidelines around 'immutable'. We don't... And I lack a complete understanding myself. :) To me, 'immutable' is a demand of the user from the provider that the data will

Re: How to create friends of a class at compile time?

2021-07-15 Thread Ali Çehreli via Digitalmars-d-learn
On 7/15/21 5:46 PM, Ali Çehreli wrote: > On 7/15/21 11:24 AM, Tejas wrote: > > package(qualifiedIdentifier) > Just don't do it Ok, I said all that before realizing what you needed with transpiling C++ to D and the solution of package(qualifiedIdentifier). (And package(qualifiedIdentifier)

Re: How to create friends of a class at compile time?

2021-07-15 Thread Ali Çehreli via Digitalmars-d-learn
On 7/15/21 11:24 AM, Tejas wrote: > it seems like seperating chunks of C++ code into seperate modules > and using the > ```d > package(qualifiedIdentifier) > ``` > access specifier seems to be the way to go. That would be necessary if one agreed with C++'s 'private' to begin with. In other

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Ali Çehreli via Digitalmars-d-learn
On 7/14/21 11:27 AM, Tejas wrote: > the compiler error should have been a dead giveaway > that opIndex was returning a _constant_ value I know you mean "rvalue" but if I may be unnecessarily pedantic, an rvalue can indeed be mutated: struct A { int i; void mutate() { i = 42;

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Ali Çehreli via Digitalmars-d-learn
On 7/14/21 9:13 AM, Tejas wrote: > ref/*notice this ref*/ int opIndex(int index)return/*NOTICE THE > RETURN*/ { Indeed... I cover that 'ref' here: http://ddili.org/ders/d.en/operator_overloading.html#ix_operator_overloading.return%20type,%20operator Two quotes from that section: 1) "it

Re: Error with implicit cast of ^^=

2021-07-14 Thread Ali Çehreli via Digitalmars-d-learn
On 7/14/21 2:44 AM, wjoe wrote: >> x = (x ^^ y).to!(typeof(x)); >> } >> >> For example, run-time error if y == 7. > I was planning on adding support for over-/underflow bits but this is > much better. Thanks! If so, then there is also std.experimental.checkedint:

Re: Error with implicit cast of ^^=

2021-07-13 Thread Ali Çehreli via Digitalmars-d-learn
On 7/13/21 4:12 AM, wjoe wrote: > ```D > byte x = some_val; > long y = some_val; > > x ^^= y; // Error: cannot implicitly convert expression > pow(cast(long)cast(int)x, y) of type long to byte [...] > I rewrote it to something like > ```D > mixin("x = cast(typeof(x))(x" ~ op[0..$-1] ~ " y);");

Re: mixin template's alias parameter ... ignored ?

2021-07-12 Thread Ali Çehreli via Digitalmars-d-learn
On 7/12/21 5:42 PM, someone wrote: > On Monday, 12 July 2021 at 23:25:13 UTC, Ali Çehreli wrote: >> On 7/12/21 3:35 PM, someone wrote: >> >> >>> private size_t pintSequenceCurrent = cast(size_t) 0; >> > >> >> Style: There's no need for the casts (throughout). >> > >> > [...] besides, it won't

Re: mixin template's alias parameter ... ignored ?

2021-07-12 Thread Ali Çehreli via Digitalmars-d-learn
On 7/12/21 3:35 PM, someone wrote: >>> private size_t pintSequenceCurrent = cast(size_t) 0; > >> Style: There's no need for the casts (throughout). > > [...] besides, it won't hurt, and it helps me in many ways. I think you are doing it only for literal values but in general, casts can be very

Re: mixin template's alias parameter ... ignored ?

2021-07-10 Thread Ali Çehreli via Digitalmars-d-learn
On 7/10/21 10:20 PM, someone wrote: > mixin template templateUGC ( > typeStringUTF, > alias lstrStructureID > ) { > > public struct lstrStructureID { The only way that I know is to take a string parameter and use it with a string mixin: mixin template templateUGC (

  1   2   3   4   5   6   7   8   9   10   >