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

Re: Address of a class object

2023-01-04 Thread Ali Çehreli via Digitalmars-d-learn
On 1/4/23 13:43, H. S. Teoh wrote: > You do realize that the compiler is free to reorder local variables on > the stack, right? ;-) Of course. :) I was trying different strategies to catch the compiler (dmd here) in a single act of 8-byte object alignment as reported by .alignof. Another

Re: Address of a class object

2023-01-04 Thread Ali Çehreli via Digitalmars-d-learn
On 1/4/23 12:02, Steven Schveighoffer wrote: > On 1/4/23 2:27 PM, Ali Çehreli wrote: >> I put the objects into a 2-length >> static array but the difference was still 0x20. (?) > > Are you putting the class *references* in a 2-length static array? I lied. As I could not put the objects in a

Re: Address of a class object

2023-01-04 Thread Ali Çehreli via Digitalmars-d-learn
On 1/4/23 11:27, Ali Çehreli wrote: > writeln("hidden 0: ", hiddenValue(addr, 0)); > writeln("hidden 1: ", hiddenValue(addr, 1)); Silly me! :) Those members have names: writeln("__vptr : ", obj.__vptr); writeln("__monitor : ", obj.__monitor);

Re: Address of a class object

2023-01-04 Thread Ali Çehreli via Digitalmars-d-learn
On 1/4/23 10:48, H. S. Teoh wrote: > Allocations are not necessarily consecutive; the GC may have its own > strategy of allocation that doesn't follow a linear sequence. That was one of my guesses. So, I put the objects into a 2-length static array but the difference was still 0x20. (?) >

Re: Address of a class object

2023-01-04 Thread Ali Çehreli via Digitalmars-d-learn
On 1/3/23 20:01, Paul wrote: > Size Alignment Type > = >17 8 MyClass > > MyClassObj1 MyClassObj2 > 27727202000 27727202020 > ``` > If my size is 17 bytes and my alignment is 8 bytes, shouldn't my > MyClassObj2 in this example be @

Re: Why does this code only work with `T` and not `typeof(T)`?

2023-01-03 Thread Ali Çehreli via Digitalmars-d-learn
On 1/3/23 20:11, thebluepandabear wrote: > if I replace the `isDrawable` template with the > following (using `typeof`), the code does not compile: It must be because T is already a type. It's the same reason why the following code fails to compile: void main() { alias T = int; alias

Re: Is there a way to enforce UFCS?

2023-01-03 Thread Ali Çehreli via Digitalmars-d-learn
On 1/3/23 19:42, thebluepandabear wrote: > @property { As your post proves, that feature is at most half-baked and is discouraged. Today, there is just one known obscure effect of using it. > void name(string name) { > _name = name; > } > d.name =

Re: Address of a class object

2023-01-01 Thread Ali Çehreli via Digitalmars-d-learn
On 1/1/23 01:01, Paul wrote: > ...on my laptop it prints... > ``` > Size Alignment Type > = > 9 4 MyClass > > 4FFB20 4FFB24 > ``` > If the size of MyClass is 9 bytes why do MyClassO1 & O2 addresses only > differ by 4 bytes? As matheus said, classes

Re: Compile time vs run time -- what is the difference?

2022-12-31 Thread Ali Çehreli via Digitalmars-d-learn
On 12/31/22 16:42, H. S. Teoh wrote: > "runtime" Going off topic, I've settled on three different spelling of that (those? :) ): - run time: As in this topic, things can happen at run time. - run-time: Adjective, as in run-time value of something. - runtime: The D runtime. Ali

Re: Address of a class object

2022-12-31 Thread Ali Çehreli via Digitalmars-d-learn
On 12/31/22 16:35, Paul wrote: > Can I acquire the address of a class object, Answering that question literally, yes, you can by casting the class variable to void*. But note: 'class object' means the instance of class in D. > not a class variable (i.e. > the instantiations of the class) D

Re: dChar Error

2022-12-30 Thread Ali Çehreli via Digitalmars-d-learn
On 12/30/22 17:22, Salih Dincer wrote: > I guess there is no other way but to overload. Since the bodies of all three overloads are the same except some types, they can easily be templatized. > This is both the safest and the fastest. I didn't think Values is fast with string copies that it

Re: dChar Error

2022-12-30 Thread Ali Çehreli via Digitalmars-d-learn
On 12/30/22 13:54, matheus wrote: > But yes I think it will generate a copy (mutable) based on this test: In this case it does copy but in the case of dchar[] to dchar[], there will be no copy. Similarly, there is no copy from immutable to immutable. > the address is different Good test. :)

Re: Compile time vs run time -- what is the difference?

2022-12-28 Thread Ali Çehreli via Digitalmars-d-learn
On 12/28/22 08:04, Ali Çehreli wrote: > I don't think any of them can run the program though because > the program can be in a state that could harm its environment > like deleting unwanted files. I was too eager there. Likely no IDE goes that far. All they need is to understand the code

Re: Compile time vs run time -- what is the difference?

2022-12-28 Thread Ali Çehreli via Digitalmars-d-learn
On 12/27/22 18:31, thebluepandabear wrote: > What I do understand is that compile time and run time are the two > processes that your code goes through to be executed natively. There is a confusion: Compile time ends when the compiler generates the executable program, one that will be executed

Re: Can you simplify nested Indexed types?

2022-12-27 Thread Ali Çehreli via Digitalmars-d-learn
On 12/27/22 07:09, Sergei Nosov wrote: > Basically, my idea is to apply `indexed` to an array several times and > have all the intermediaries saved in the same variable. There may be other ways of achieving the same goal without assigning to the same variable. > I wonder, if there's a way to

Re: Confusion about `Random`

2022-12-24 Thread Ali Çehreli via Digitalmars-d-learn
On 12/24/22 09:58, jwatson-CO-edu wrote: >> ~static this() Should be 'static ~this()'. >> ~shared static this() Should be 'shared static ~this()'. > thank you all Happy to be helpful... Ali

Re: Confusion about `Random`

2022-12-24 Thread Ali Çehreli via Digitalmars-d-learn
On 12/24/22 08:18, jwatson-CO-edu wrote: > On Friday, 23 December 2022 at 07:25:23 UTC, Salih Dincer wrote: >> You can try using static this. >> >> ```d >> import std.random; >> >> static this() { } // can try using static this() blocks: executed when a thread a starts (the program has at least

Re: Does 'ref' turn into a pointer during compile time?

2022-12-21 Thread Ali Çehreli via Digitalmars-d-learn
On 12/21/22 16:43, thebluepandabear wrote: > Say you have the following function that takes in a `ref` parameter: > > ```D > void modify(ref int num) { > num += 5; > } > ``` > > Does the compiler turn that into the code below? > > ```D > void modify(int* num) { > num += 5; Rather:

Re: Is there such concept of a list in D?

2022-12-19 Thread Ali Çehreli via Digitalmars-d-learn
On 12/19/22 14:14, thebluepandabear wrote: > Yeah I am sure it was on this thread. One of the posts was at > https://forum.dlang.org/post/kzvnajixjdnlcupsl...@forum.dlang.org, it > now shows 'Not Found'. Then I don't know. (?) However, I realize my ThunderBird "evidence" is useless because if

Re: Is there such concept of a list in D?

2022-12-19 Thread Ali Çehreli via Digitalmars-d-learn
On 12/19/22 13:45, thebluepandabear wrote: > On Monday, 19 December 2022 at 21:41:45 UTC, thebluepandabear wrote: >> Why did my replies here to someone else get deleted? > > Myself and this other person's reply to this thread randomly got removed > for no reason, I would appreciate an explanation

Re: No need opUnary

2022-12-19 Thread Ali Çehreli via Digitalmars-d-learn
On 12/18/22 08:21, Salih Dincer wrote: > Don't you think it's interesting that it doesn't need unary operator > overloading? Yes, it is interesting. I put comments to explain it to myself: import std.stdio; struct S { int value; /* The folowing declaration allows objects of this type

Re: How is this code invalid?

2022-12-16 Thread Ali Çehreli via Digitalmars-d-learn
On 12/16/22 18:20, H. S. Teoh wrote: > scratch space for computations, called the runtime > stack. I called it "function call stack" where I gave a very simplistic view of it here: https://www.youtube.com/watch?v=NWIU5wn1F1I=236s > (2) Use @safe when possible so that the compiler will

Re: Unique!struct bug - Re: unique_ptr | Unique for autoclose handle

2022-12-15 Thread Ali Çehreli via Digitalmars-d-learn
On 12/15/22 11:31, Nick Treleaven wrote: > On Wednesday, 14 December 2022 at 17:41:07 UTC, Ali Çehreli wrote: >> I've never used Unique but I think it has a bug (or a design issue?): >> Its destructor is the following: >> >> ~this() >> { >> if (_p !is null) >> { >>

Re: unique_ptr | Unique for autoclose handle

2022-12-14 Thread Ali Çehreli via Digitalmars-d-learn
On 12/14/22 09:41, Ali Çehreli wrote: > // According to documentation, the handler must be created dynamically: > // We make a unique owner for it: Ignore that part. It's a leftover from my experiments with Unique!Handle. Ali

Re: unique_ptr | Unique for autoclose handle

2022-12-14 Thread Ali Çehreli via Digitalmars-d-learn
On 12/14/22 05:58, Vitaliy Fadeev wrote: > On Wednesday, 14 December 2022 at 11:30:07 UTC, Vitaliy Fadeev wrote: >> How to define HANDLE var ? What to return from procedure? How to call >> CloseHandle( h ) when variable destroyed? An obvious way is an RAII type where the destructor calls

Re: Is there such concept of a list in D?

2022-12-13 Thread Ali Çehreli via Digitalmars-d-learn
On 12/13/22 14:21, areYouSureAboutThat wrote: > On Saturday, 10 December 2022 at 15:59:07 UTC, Ali Çehreli wrote: >> >> ... Object orientation don't go well with collections > > On what basis do you make that assertion? You stripped my answer. > i.e. Which aspect of OOP programming 'don't

Re: Why can't rvalues be passed to a 'ref' parameter?

2022-12-11 Thread Ali Çehreli via Digitalmars-d-learn
On 12/11/22 01:25, zjh wrote: > On Sunday, 11 December 2022 at 04:36:45 UTC, thebluepandabear wrote: > >> "The main reason for this limitation is the fact that a function >> taking a ref >> parameter can hold on to that reference for later use, at a time when >> the rvalue >> would not be

Re: Function template as template parameter

2022-12-11 Thread Ali Çehreli via Digitalmars-d-learn
On 12/11/22 05:54, Salih Dincer wrote: > On Sunday, 11 December 2022 at 09:43:34 UTC, Andrey Zherikov wrote: >> Note that callback parameter must be compile-time parameter as it >> represents a member of a type during introspection done by `foo`. > > I can't quite understand the question, this

Re: Is there such concept of a list in D?

2022-12-10 Thread Ali Çehreli via Digitalmars-d-learn
On 12/9/22 22:11, thebluepandabear wrote: > I was wondering more if there is an object oriented way of creating > arrays, Every collection has its own special interface. Object orientation don't go well with collections. For example, you wouldn't want indexing operator for a linked list. >

Re: printf, writeln, writefln

2022-12-08 Thread Ali Çehreli via Digitalmars-d-learn
On 12/8/22 08:21, Salih Dincer wrote: > void stringCopy(Chars)(string source, > ref Chars target) >sample.stringCopy = cTxt; // disappeared ? char Nothing disappeared on my system. (?) Going off-topic, I find the expression above extremely confusing. I am used to

Re: gcc -E -dD; dstep; sqlite3

2022-12-08 Thread Ali Çehreli via Digitalmars-d-learn
On 12/8/22 06:28, johannes wrote: > enum __FLT128_MAX__ = 1.18973149535723176508575932662800702e+4932F128; That literal is not legal D. The "F128" characters at the end are extra. Besides, D does not have a 128-bit floating point type. Ali (Sorry for double e-mail.)

Re: printf, writeln, writefln

2022-12-07 Thread Ali Çehreli via Digitalmars-d-learn
On 12/6/22 15:07, johannes wrote: > 'write' prints out the address > of the first byte. This is odd to me because printf does the job > correctly. printf behaves as what you expect because %s means dereferencing the pointer values and printing the char contents until printf sees '\0'. > But

Re: Confused about something in the D book relating to precision

2022-12-04 Thread Ali Çehreli via Digitalmars-d-learn
On 12/4/22 18:57, thebluepandabear wrote: > I am not understanding why Ali said there is a decimal mark if precision > is nonzero? > > How can a number have zero precision? That "precision" is referring to how many digits are printed after the decimal mark in the formatted output. > "the

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Ali Çehreli via Digitalmars-d-learn
On 12/4/22 15:25, Adam D Ruppe wrote: > which would trigger the write barrier. The thread isn't > allowed to complete this operation until the GC is done. According to my limited understanding of write barriers, the thread moving to 800 could continue because order of memory operations may

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Ali Çehreli via Digitalmars-d-learn
On 12/4/22 12:17, Adam D Ruppe wrote: On Sunday, 4 December 2022 at 17:53:00 UTC, Adam D Ruppe wrote: Interesting... you know, maybe D's GC should formally expose a mutex that you can synchronize on for when it is running. .. or compile in write barriers. then it doesn't matter if the

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Ali Çehreli via Digitalmars-d-learn
On 12/4/22 06:27, Sergey wrote: > if it will be possible to write > library in D and use it from > C/++/Python/R/JVM(JNI)/Erlang(NIF)/nameYourChoice smoothly it will be a > win. Years ago we tried to call D from Java. I realized that it was very tricky to introduce the calling thread to D's

Re: Idiomatic D using GC as a library writer

2022-12-04 Thread Ali Çehreli via Digitalmars-d-learn
On 12/4/22 05:58, vushu wrote: > I was worried if my library should be GC free May I humbly recommend you question where that thinking comes from? Ali P.S. I used to be certain that the idea of GC was wrong and the creators of runtimes with GC were simpletons. In contrast, people like me,

Re: Why can't D store all UTF-8 code units in char type? (not really understanding explanation)

2022-12-02 Thread Ali Çehreli via Digitalmars-d-learn
On 12/2/22 13:18, thebluepandabear wrote: > But I don't really understand this? What does it mean that it 'must be > represented by at least 2 bytes'? The integral value of Ğ in unicode is 286. https://unicodeplus.com/U+011E Since 'char' is 8 bits, it cannot store 286. At first, that

Re: Why can't D store all UTF-8 code units in char type? (not really understanding explanation)

2022-12-02 Thread Ali Çehreli via Digitalmars-d-learn
On 12/2/22 13:44, rikki cattermole wrote: > Yeah you're right, its code unit not code point. This proves yet again how badly chosen those names are. I must look it up every time before using one or the other. So they are both "code"? One is a "unit" and the other is a "point"? Sheesh! Ali

Re: Syntax Sugar for Initializing a Fixed float Array as void*?

2022-11-30 Thread Ali Çehreli via Digitalmars-d-learn
On 11/30/22 16:48, Ali Çehreli wrote: Functions are syntax sugar. :) And I remembered std.array.staticArray. One its overloads should be useful: import std; void main() { auto v3 = staticArray!(0.1f.repeat(5)); auto v4 = staticArray!5(0.1f.repeat); writeln(v3); writeln(v4);

Re: Syntax Sugar for Initializing a Fixed float Array as void*?

2022-11-30 Thread Ali Çehreli via Digitalmars-d-learn
On 11/30/22 16:39, jwatson-CO-edu wrote: Is there a way to write a single statement that creates a void pointer that points to an initialized float array?  See below: ```d float* arr = cast(float*) new float[4]; arr[0] = 0.1; arr[1] = 0.1; arr[2] = 0.1; arr[3] = 0.1; void* value = cast(void*)

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-30 Thread Ali Çehreli via Digitalmars-d-learn
On 11/29/22 15:25, DLearner wrote: > 'dynamic array' is > not a reasonable description for a construct that behaves like > VarArr2[3] becoming 40. I agree with you: It has always bothered me to call the following a dynamic array: int[] arr; 'arr' is not a dynamic array but the slice

Re: Is there a formula for overflow?

2022-11-30 Thread Ali Çehreli via Digitalmars-d-learn
On 11/29/22 19:07, thebluepandabear wrote: > But the book doesn't talk about why the D compiler came up with these > results The compiler doesn't do anything special. It's all about the lack of bits to store the value. If the result needs 33 bits but the type has only 32 bits, the

Re: dirEntries removes entire branches of empty directories

2022-11-26 Thread Ali Çehreli via Digitalmars-d-learn
On 11/14/22 14:41, kdevel wrote: > the ftw version gets the whole information from readdir alone. Created an enhancement request: https://issues.dlang.org/show_bug.cgi?id=23512 Ali

Re: Assigning parameter on entry to a function and assigning back on exit

2022-11-25 Thread Ali Çehreli via Digitalmars-d-learn
On 11/25/22 05:06, Victor Porton wrote: >> A function argument that is both input and output, may be passed to >> the function either as reference or do two assignments: on entry of >> the function it is assigned to the parameter, on exit it is assigned >> back. The way I understand it with C,

Re: Is defining get/set methods for every field overkill?

2022-11-21 Thread Ali Çehreli via Digitalmars-d-learn
On 11/20/22 14:37, [] () {} () wrote: > so, as I understand it, your're against the use of private, against the > use of class, and against the use of encapsulation. I never implied any of that. > .. good luck with your career as a software engineer (but please, for > all our sakes, don't work

Re: Is defining get/set methods for every field overkill?

2022-11-21 Thread Ali Çehreli via Digitalmars-d-learn
On 11/20/22 23:01, [] () {} () wrote: > On that basis, I might be tempted to agree with you're point of view -> > never, ever, ever, ever, use classes in D. That's not my point of view. Ali

Re: Is defining get/set methods for every field overkill?

2022-11-20 Thread Ali Çehreli via Digitalmars-d-learn
On 11/20/22 00:31, [] () {} () wrote: > Quoted from that video (the one that you agree with): > > "I don't ever think that private .. private is like just .. shouldn't > even be used." > > "so I don't even use classes I just use struct so that everything is > always public .. and that in my

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Ali Çehreli via Digitalmars-d-learn
On 11/19/22 01:43, [] () {} () wrote: > do it your way for the next 10 years, and > I bet you will eventually come to a different point of view ;-) Hm... I am responding without reading the rest of the thread so I don't know whether you've mentioned the 10 years more but here it goes: I hope

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Ali Çehreli via Digitalmars-d-learn
On 11/19/22 01:05, [] () {} () wrote: > All this because some programmer wanted to save a few key strokes, or > did not anticipate change, or did not anticipate the need to ensure data > is valid before assigning it, or returning it. > > So no. It's not overkill. It's called software

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Ali Çehreli via Digitalmars-d-learn
On 11/18/22 20:13, [] () {} () wrote: > after 10 years of doing all that, you may well come to the conclusion > that public member variables are not such a great idea afterall ;-) It depends. Majority of my structs are pure data. When there is no invariant to protect, then there is no reason

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Ali Çehreli via Digitalmars-d-learn
On 11/18/22 19:35, [] () {} () wrote: > I like to see an example, of a 'class type' with 'public' member > variables, somehow magically converted into both getter and setter using > UFCS, without breaking client code. UFCS was mentioned before in the same context but I think what is meant was

Re: Is defining get/set methods for every field overkill?

2022-11-16 Thread Ali Çehreli via Digitalmars-d-learn
On 11/16/22 20:39, thebluepandabear wrote: > I am debating whether or not I should add getter methods to these > properties. If you are debating, then the answer is easy: you should not. :) Less code written means less bugs, more cohesion, easier refactoring, cleaner code, all good stuff...

Re: Actual lifetime of static array slices?

2022-11-15 Thread Ali Çehreli via Digitalmars-d-learn
On 11/15/22 06:05, Siarhei Siamashka wrote: > Ali commented that "the > compiler cannot do anything about it in all cases and we wouldn't want > it to spend infinite amount of time to try to determine everything". Yes, that's my understanding. > This sounds like he justifies the compiler's

Re: Actual lifetime of static array slices?

2022-11-14 Thread Ali Çehreli via Digitalmars-d-learn
On 11/14/22 19:05, Elfstone wrote: > @safe > int[] foo() > { > int[1024] static_array; > // return static_array[]; // Error: returning `static_array[]` > escapes a reference to local variable `static_array` That is trivial for the compiler to catch. >

Re: dirEntries removes entire branches of empty directories

2022-11-11 Thread Ali Çehreli via Digitalmars-d-learn
On 11/11/22 08:00, Ali Çehreli wrote: > It may have to do something with the performance of the hard disk. I meant "the reason you got a much better improvement" may have to do something with the performance differences of your hard disk and mine. Ali

Re: dirEntries removes entire branches of empty directories

2022-11-11 Thread Ali Çehreli via Digitalmars-d-learn
On 11/11/22 05:13, kdevel wrote: > dmd -O compiled patched (see below!) version applied to /usr/bin on my > desktop > yields: > > ftw : 363 ms, 750 ÎŒs, and 5 [*] > dirEntries: 18 secs, 831 ms, 738 ÎŒs, and 3 [*] Great. I did not use -O with my test. It may have to do something with the

Re: dirEntries removes entire branches of empty directories

2022-11-10 Thread Ali Çehreli via Digitalmars-d-learn
On 11/9/22 12:06, Ali Çehreli wrote: > I am using its sibling 'ftw' Now that we know that dirEntries works properly, I decided not to use ftw. However, ftw performs about twice as fast as dirEntries (despite some common code in the implementation below). I am leaving it here in case somebody

Re: dirEntries removes entire branches of empty directories

2022-11-10 Thread Ali Çehreli via Digitalmars-d-learn
On 11/9/22 11:30, Vladimir Panteleev wrote: > On Wednesday, 9 November 2022 at 19:05:58 UTC, Ali Çehreli wrote: >> Running the program shows no output; 'a' is not visited as a directory >> entry. > > That's not what happens for me: Does not happen for me today either. (?) I must have confused

Re: dirEntries removes entire branches of empty directories

2022-11-09 Thread Ali Çehreli via Digitalmars-d-learn
On 11/9/22 11:05, Ali Çehreli wrote: > Can you think of a workaround to achieve that? Me, me, me! :) I've learned about the Posix function 'nftw' (but I am using its sibling 'ftw'). It was pretty easy to use but there is a quality issue there: They failed to support a 'void*' context for

Re: dirEntries removes entire branches of empty directories

2022-11-09 Thread Ali Çehreli via Digitalmars-d-learn
On 11/9/22 11:48, Imperatorn wrote: > That's not the behaviour I get in Windows. Windows users deserve it! :p (At least it is better in this case. :) ) > When I create the subdirectory, I see it even if it's empty struct DirIteratorImpl has different implementations for Windows, etc. Ali

dirEntries removes entire branches of empty directories

2022-11-09 Thread Ali Çehreli via Digitalmars-d-learn
In case it matters, the file system is ext4. 1) Create a directory: mkdir deleteme and then run the following program: import std; void main() { foreach (e; dirEntries(absolutePath("./deleteme"), SpanMode.breadth)) { writeln(e.name); } } Understandably, the top level

Re: Passing a string by reference

2022-11-08 Thread Ali Çehreli via Digitalmars-d-learn
On 11/8/22 04:53, Alexander Zhirov wrote: > On Tuesday, 8 November 2022 at 12:43:47 UTC, Adam D Ruppe wrote: >> Just use plain `string`. > > So it's always working with thick pointers? Yes, D's arrays are fat pointers. strings are arrays of immutable(char). >> nope, an object isn't created

Re: What's the correct way of creating an instance of class in D?

2022-11-03 Thread Ali Çehreli via Digitalmars-d-learn
On 11/3/22 08:40, H. S. Teoh wrote: > D does not have the equivalent of C++'s allocating a class instance on > the stack. Not by default but we have two different ways, either may be discouraged: import std.typecons : scoped; import std.stdio; class C { int i; } void main() { //

Re: Unit testing a function returning void

2022-11-03 Thread Ali Çehreli via Digitalmars-d-learn
On 11/3/22 03:00, Bruno Pagis wrote: >void print() { > writeln("array = ", this.array); >} Similar to Paul Backus's program but I would try to avoid the file system for unit tests when possible. In this case, you can print into a sink, which can be useful in other ways as well:

Re: save() feature for iota

2022-11-03 Thread Ali Çehreli via Digitalmars-d-learn
On 11/3/22 04:58, Paul Backus wrote: > https://issues.dlang.org/show_bug.cgi?id=23453 Even though iterating over UTF value ranges don't make sense in general, they would work for some values including the ASCII range. Ali

Re: druntime thread (from foreach parallel?) cleanup bug

2022-11-01 Thread Ali Çehreli via Digitalmars-d-learn
On 11/1/22 10:27, H. S. Teoh wrote: > Maybe try running Digger to reduce the code for you? Did you mean dustmite, which is accessible as 'dub dustmite ' but I haven't used it. My guess for the segmentation fault is that the OP is executing destructor code that assumes some members are

Re: CTFE in betterC needs the GC

2022-10-29 Thread Ali Çehreli via Digitalmars-d-learn
On 10/29/22 20:41, arandomonlooker wrote: > string exampleCTFE(string a, string b) { > return a ~ b; > } Although you need that function only at compile time, it is an ordinary function that could be called at run time as well. The function needs GC for that concatenation in the general

Re: ubyte + ubyte = int

2022-10-26 Thread Ali Çehreli via Digitalmars-d-learn
On 10/26/22 14:19, Ali Çehreli wrote: >https://dlang.org/spec/type.html#integer-promotions Reading "Value Range Propagation" further down that link, I learned that e.g. masking 'decimal' with 0xf makes the code compile: return ((decimal & 0xf) + ubyte('0')); return

Re: ubyte + ubyte = int

2022-10-26 Thread Ali Çehreli via Digitalmars-d-learn
On 10/26/22 14:10, 0xEAB wrote: > I guess, this fancy behavior is inherited from C. Yes. It is called integer promotions: https://dlang.org/spec/type.html#integer-promotions (The next section is related as well.) > I know this is advanced stuff, but the compiler *could* even prove that >

Re: Replacing tango.text.Ascii.isearch

2022-10-26 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 22:49, Siarhei Siamashka wrote: > Unicode is significantly simpler than a set of various > incompatible 8-bit encodings Strongly agreed. > I'm surely > able to ignore the peculiarities of modern Turkish Unicode The problem with Unicode is its main aim of allowing characters of

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 19:25, Salih Dincer wrote: > with static in main(): If 'static' makes a difference on your side as well, it is your turn to create a bug report. :) (Last time you discovered a bug, I was too quick to report it. :/) Ali

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 17:16, Salih Dincer wrote: > Excuse me, but they still write in purple prose about dynamic > array literature here! I've heard positive things about D's arrays from people who use D in production. Especially slices... > I've known D for more than 10 years, but the topic we're

Re: auto scope question?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 15:07, WhatMeWorry wrote: > auto screen = executeShell(cmdLine); > auto s; That can't work because there is no information to infer the type of 's'. Judging from the return type of getPath, perhaps it's string[]: string[] s; This is the question we should answer first: What

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 13:36, matheus wrote: > On Tuesday, 25 October 2022 at 20:12:25 UTC, Paul Backus wrote: >> Static arrays are value types. What that means is, when we say float[3], there are just 3 floats without any overhead. >> Dynamic arrays are reference types. That phrase can be confusing

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 13:12, Paul Backus wrote: > In order to create a copy of a static array Although .dup works for static arrays as well, you meant "dynamic array" and everyones knows it. :) > with its own block of > memory, separate from the original, you have to use the built-in `.dup` > method:

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 11:23, Steven Schveighoffer wrote: >> Why do I say incorrect things like that? :) > You were right actually. As always! Now I'm confused. :o) Ali

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 11:01, Ali Çehreli wrote: > static arrays don't have .ptr to point > to any member. Why do I say incorrect things like that? :) Of course static arrays have .ptr as well but that always point to their own body of N elements. They own their elements... I move away from the keyboard

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 10:54, Salih Dincer wrote: > So I don't understand why it causes problems with > dynamic arrays! So why is there nothing wrong with the static array in > the example below? The same rules as other uses of dynamic arrays... > //A[] a = [A.init];/* In that case, there is a

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 08:50, Andrey Zherikov wrote: > I'd like to tune default ctor but structs can't have custom one. > Adding a ctor with parameter seems a hack to me There is static opCall, which may be seen as a hack as well. :) The following all print the same thing now: import std.stdio; struct

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/22 07:53, Adam D Ruppe wrote: > On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov wrote: >> A[] a = [A.init]; > > This is a problem - this is referring to a static array instance, shared > across all copies of B. You almost certainly don't want this. Agreed. It should be

Re: Supporting foreach (k, v; T.init) for a user-defined (container) type

2022-10-24 Thread Ali Çehreli via Digitalmars-d-learn
On 10/24/22 14:26, Per Nordlöw wrote: What property of a container (type) `T` enables iteration as ```d foreach (k, v; T.init) {     ... } ``` ? I thought it sufficed to define `T.byKeyValue` but its presence seem to have no effect. Another option is to use range functions where front()

Re: Find in assoc array then iterate

2022-10-22 Thread Ali Çehreli via Digitalmars-d-learn
On 10/22/22 08:21, Kevin Bailey wrote: > his claim that there was no value. I think he was questioning the need for iterating from a point forward inside an unordered container. When the container is unordered, the elements that are accessed after a found element could be anything. I think

Re: Real simple question... for good programmers

2022-10-22 Thread Ali Çehreli via Digitalmars-d-learn
On 10/22/22 14:53, WhatMeWorry wrote: > > > string[] tokens = userSID.output.split!isWhite; > writeln("tokens = ", tokens); Could you please show minimal compilable code that demonstrates the issue. I spent some time with some guesses but failed (to get my code to compile with

Re: Find in assoc array then iterate

2022-10-21 Thread Ali Çehreli via Digitalmars-d-learn
On 10/21/22 15:03, Kevin Bailey wrote: I'm trying to do this equivalent C++:     unordered_map map;     for (auto i = map.find(something); i != map.end(); ++i)     ...do something with i... in D, but obviously with an associative array. It seems that it's quite easy to iterate through

Re: Catching C errors

2022-10-19 Thread Ali Çehreli via Digitalmars-d-learn
On 10/19/22 09:47, data pulverizer wrote: > It's okay, I've found a work around. Do you simply check the return value? Ali

Re: Catching C errors

2022-10-19 Thread Ali Çehreli via Digitalmars-d-learn
On 10/19/22 07:05, data pulverizer wrote: > I am calling code from a C API, and would like to know how to catch exit > errors If you are talking about the exit() Posix function, you can't do anything about that because its purpose is to cause "normal process termination". Ali

Re: warning LNK4255 - How to solve this warning

2022-10-18 Thread Ali Çehreli via Digitalmars-d-learn
On 10/18/22 12:26, Hipreme wrote: > Is there any way to know which files produced this error or at least the > symbol names that are clashing? I'm totally helpless about this error. There is 'nm' on Posix systems that lists symbols in object files (including libraries and programs). Ali

Re: parallel is slower than serial

2022-10-18 Thread Ali Çehreli via Digitalmars-d-learn
On 10/18/22 06:24, Guillaume Piolat wrote: > To win something with OS threads, you must think of tasks that takes on > the order of milliseconds rather than less than 0.1ms. > Else you will just pay extra in synchronization costs. In other words, the OP can adjust work unit size. It is on the

Re: Reading and wiping notes also adding more notes

2022-10-17 Thread Ali Çehreli via Digitalmars-d-learn
On 10/17/22 22:40, Joel wrote: > I have two text fields. The one on the left has the whole text, new > stuff being added to the bottom. The one on the right has text I've been > wiping as I'm reading. I think this can be modelled as a string array and an index showing where the active part

Re: probably a trivial question...

2022-10-13 Thread Ali Çehreli via Digitalmars-d-learn
Changing the order of lines... On 10/13/22 16:43, WhatMeWorry wrote: > return s.split(';'); // single quotes That one is a single character and very lightweigth because it's just an integral value. You can't put more than one character within single quotes: ';x' // ERROR > return

Re: D Community Conversations: Walter Bright on the Origins of D Part 2

2022-10-12 Thread Ali Çehreli via Digitalmars-d-announce
On 10/12/22 17:52, ItIsEncapsulatedOrItisNot wrote: > On Thursday, 13 October 2022 at 00:46:09 UTC, ItIsEncapsulatedOrItisNot > wrote: Creative new name. However, although access rights are related to encapsulation, they don't provide it. Encapsulation is encapsulation. > My programs are now

Re: Ali introduced D at Northeastern University

2022-10-11 Thread Ali Çehreli via Digitalmars-d-announce
On 10/8/22 16:11, Walter Bright wrote: Just posted it in the "New" section of HackerNews On the front page at the moment. Ali

Re: Replacing tango.text.Ascii.isearch

2022-10-05 Thread Ali Çehreli via Digitalmars-d-learn
On 10/5/22 13:40, torhu wrote: auto sw = StopWatch(); Either this: auto sw = StopWatch(AutoStart.yes); or this: auto sw = StopWatch(); sw.start(); Ali

<    1   2   3   4   5   6   7   8   9   10   >