Re: Coding Challenges - Dlang or Generic

2023-01-09 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 10, 2023 at 03:18:54AM +, matheus via Digitalmars-d-learn wrote: > On Tuesday, 10 January 2023 at 01:22:33 UTC, H. S. Teoh wrote: > > ... > > > > Here's a challenge. Given an input year, for example, "2023", > > write a program that outputs (for the corresponding year): > > ... >

Re: Coding Challenges - Dlang or Generic

2023-01-09 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jan 10, 2023 at 12:17:18AM +, Paul via Digitalmars-d-learn wrote: > Greetings Dlang-ers > I was wondering if anyone knew of any coding challenges available > where the input and output are specified and its left to the > programmer to find a solution? Here's a challenge. Given an

Re: How to avoid variable capturing in `foreach` loop with lambdas?

2023-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 05, 2023 at 10:46:07PM +, thebluepandabear via Digitalmars-d-learn wrote: > On Thursday, 5 January 2023 at 17:36:55 UTC, H. S. Teoh wrote: [...] > > ```D > > foreach (BoardSize boardSize; arr) { > > Button button = new Button(); > > button.text = format("%sx%s",

Re: GC interaction with malloc/free

2023-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 05, 2023 at 08:18:42PM +, DLearner via Digitalmars-d-learn wrote: > On Thursday, 5 January 2023 at 19:54:01 UTC, H. S. Teoh wrote: [...] > > core.stdc.stdlib.{malloc,free} *is* the exact same malloc/free that > > C uses, it has nothing to do with the GC. The allocated memory is >

Re: GC interaction with malloc/free

2023-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 05, 2023 at 07:49:38PM +, DLearner via Digitalmars-d-learn wrote: > Suppose there is a D main program (not marked anywhere with @nogc), > that _both_ > > A: Calls one or more C functions that themselves call malloc/free; and > also > B: Calls one or more D functions that

Re: Is there a way to enforce UFCS?

2023-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 05, 2023 at 02:32:17PM +, Dom DiSc via Digitalmars-d-learn wrote: [...] > I think this is really another usecase for @property: we should forbid the > function call syntax for them (so one needs to use them like a variable). [...] > Properties are not functions. If you want a

Re: How to avoid variable capturing in `foreach` loop with lambdas?

2023-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 05, 2023 at 11:55:33AM +, thebluepandabear via Digitalmars-d-learn wrote: [...] > ```D > foreach (BoardSize boardSize; arr) { > Button button = new Button(); > button.text = format("%sx%s", boardSize[0], boardSize[1]); > button.onButtonClick = { >

Re: Address of a class object

2023-01-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jan 05, 2023 at 06:32:47AM +, areYouSureAboutThat via Digitalmars-d-learn wrote: [...] > Second, to be sure your getting the correct results, it would be nice > if there was a 'category of type' in std.traits for: > > isAllocatedOnStack > isAllocatedOnHeap > > As it is, your just

Re: Address of a class object

2023-01-04 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 04, 2023 at 01:20:12PM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > 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

Re: Address of a class object

2023-01-04 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 04, 2023 at 09:51:05AM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > On 1/3/23 20:01, Paul wrote: > > > Size Alignment Type > > = > >17 8 MyClass > > > > MyClassObj1 MyClassObj2 > > 27727202000 27727202020 > > ``` > > If my

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

2022-12-31 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jan 01, 2023 at 02:18:23AM +, Salih Dincer via Digitalmars-d-learn wrote: > On Sunday, 1 January 2023 at 01:20:02 UTC, Ali Çehreli wrote: > > On 12/31/22 16:42, H. S. Teoh wrote: > > > > - runtime: The D runtime. > > Sometimes I see runtime facilities used as compile time and I'm

Re: Address of a class object

2022-12-31 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jan 01, 2023 at 12:35:40AM +, Paul via Digitalmars-d-learn wrote: > Hello. Thanks for any assistance. > > Can I acquire the address of a class object, not a class variable > (i.e. the instantiations of the class) but the object definition > itself? > > ```d > class MyClass {char c}

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

2022-12-31 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 28, 2022 at 02:31:45AM +, thebluepandabear via Digitalmars-d-learn wrote: > I am reading through the free book on learning D by Ali Çehreli and I > am having difficulties understanding the difference between compile > time execution and run time execution in D language. It's very

Re: Confusion about `Random`

2022-12-23 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 23, 2022 at 03:21:24PM +, jwatson-CO-edu via Digitalmars-d-learn wrote: > On Friday, 23 December 2022 at 00:00:06 UTC, H. S. Teoh wrote: [...] > > My personal guess is that you forgot a `ref` somewhere when you pass > > the RNG to a function. Given that due to historical accident

Re: Confusion about `Random`

2022-12-22 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Dec 22, 2022 at 08:17:56PM +, jwatson-CO-edu via Digitalmars-d-learn wrote: > On Thursday, 22 December 2022 at 17:33:48 UTC, Paul Backus wrote: > > So, as far as I can tell, there is nothing wrong with your code, and > > the random number generator is working as intended. > > > >

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

2022-12-21 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Dec 22, 2022 at 12:43:28AM +, thebluepandabear via Digitalmars-d-learn 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

Re: How is this code invalid?

2022-12-17 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Dec 17, 2022 at 02:36:10AM +, thebluepandabear via Digitalmars-d-learn wrote: [...] > Thanks, I've tried to mark it with `@safe` and it did give me a > warning. > > I was also wondering, why is this code valid? > > ```D > int[] numbersForLaterUse; > > @safe void foo(int[] numbers)

Re: How is this code invalid?

2022-12-16 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 16, 2022 at 05:39:08PM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] > If you really want to see what could possibly have gone wrong, try > this version of the code: [...] > The results will likely differ depending on your OS and specific > environment; but

Re: How is this code invalid?

2022-12-16 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Dec 17, 2022 at 12:23:32AM +, thebluepandabear via Digitalmars-d-learn wrote: [...] > ```D > int[] numbersForLaterUse; > > void foo(int[] numbers...) { >numbersForLaterUse = numbers; > } > > struct S { > string[] namesForLaterUse; > > void foo(string[] names...) { >

Re: Gotcha with photos' documentation

2022-12-09 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 09, 2022 at 12:51:27PM +0100, Christian Köstlin via Digitalmars-d-learn wrote: > On 09.12.22 02:27, H. S. Teoh wrote: [...] > > https://github.com/dlang/phobos/pull/8646 [...] > Thanks a lot ... > that was fast. It only took a minute to fix. :-D > Is there also an implementation

Re: Gotcha with photos' documentation

2022-12-08 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Dec 08, 2022 at 05:21:52PM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] > I'll see if I can reword this to be more explicit. [...] https://github.com/dlang/phobos/pull/8646 T -- Don't modify spaghetti code unless you can eat the consequences.

Re: Gotcha with photos' documentation

2022-12-08 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Dec 08, 2022 at 09:15:45PM +0100, Christian Köstlin via Digitalmars-d-learn wrote: > Recently I stumbled upon a small issue in dlang's docs. > I wanted to look up uniq in std.algorithm. Started from > https://dlang.org/phobos/std_algorithm.html and clicked uniq, no > problem, all good.

Re: printf, writeln, writefln

2022-12-06 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 06, 2022 at 11:07:32PM +, johannes via Digitalmars-d-learn wrote: > //-- the result should be f.i. "the sun is shining" > //-- sqlite3_column_text returns a constant char* a \0 delimited c-string > printf("%s\n",sqlite3_column_text(res, i)); > writeln(sqlite3_column_text(res, i));

Re: How ptr arithmitic works??? It doesn't make any sense....

2022-12-04 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Dec 04, 2022 at 04:33:35PM +, rempas via Digitalmars-d-learn wrote: > First a little bit of theory. A pointer just points to a memory > address which is a number. So when I add "10" to this pointer, it will > point ten bytes after the place it was pointing to, right? This is true only

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

2022-12-02 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 02, 2022 at 11:47:30PM +, thebluepandabear via Digitalmars-d-learn wrote: > On Friday, 2 December 2022 at 23:44:28 UTC, thebluepandabear wrote: > > > :-D > > > > > > (Exercise for the reader: what's the Hausdorff dimension of the > > > set of strings over Unicode space? :-P) > >

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

2022-12-02 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 02, 2022 at 02:32:47PM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > 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

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

2022-12-02 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 02, 2022 at 09:18:44PM +, thebluepandabear via Digitalmars-d-learn wrote: > Hello (noob question), > > I am reading a book about D by Ali, and he talks about the different > char types: char, wchar, and dchar. He says that char stores a UTF-8 > code unit, wchar stores a UTF-16

Re: Is there a formula for overflow?

2022-11-30 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 30, 2022 at 03:07:44AM +, thebluepandabear via Digitalmars-d-learn wrote: > I am reading through Ali's book about D, and he gives the following > examples for an overflow: [...] > The result overflows and is 1705032704. > > Also for the second example, it overflows and comes up

Re: How often I should be using const? Is it useless/overrated?

2022-11-18 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 18, 2022 at 11:51:42AM +, thebluepandabear via Digitalmars-d-learn wrote: A question I have been thinking about whilst using D is how often I should be using const. You should use it as often as you need to use it, and no more. If you don't need to use it, don't use it.

Re: Need Advice: Union or Variant?

2022-11-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 17, 2022 at 10:16:04PM +, jwatson-CO-edu via Digitalmars-d-learn wrote: > On Thursday, 17 November 2022 at 21:05:43 UTC, H. S. Teoh wrote: [...] > > struct Atom { > > F_Type kind; > > union { // anonymous union > > Atom*

Re: Need Advice: Union or Variant?

2022-11-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 17, 2022 at 08:54:46PM +, jwatson-CO-edu via Digitalmars-d-learn wrote: [...] > ```d > enum F_Type{ > CONS, // Cons pair > STRN, // String/Symbol > NMBR, // Number > EROR, // Error object > BOOL, // Boolean value > FUNC, // Function > } > > struct Atom{ >

Re: Can we ease WASM in D ?

2022-11-16 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 16, 2022 at 10:51:31PM +, bioinfornatics via Digitalmars-d-learn wrote: > Dear community, > > I look some day ago to the D wasm page: > -> https://wiki.dlang.org/Generating_WebAssembly_with_LDC > > And since then I ask myself can we at compile time convert a D code > to an

Re: Removing an element from an array

2022-11-10 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 10, 2022 at 11:26:45PM +, Alexander Zhirov via Digitalmars-d-learn wrote: > I have an array of self-written class `A`. I'm sorry for my tactlessness, > but I'm confused about the modules. How do I correctly find a specific > object `fragment` inside the array and delete it? I

Re: dirEntries removes entire branches of empty directories

2022-11-10 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 10, 2022 at 07:07:33PM +, Imperatorn via Digitalmars-d-learn wrote: > On Thursday, 10 November 2022 at 16:34:53 UTC, Ali Çehreli wrote: > > On 11/9/22 11:30, Vladimir Panteleev wrote: > > > On Wednesday, 9 November 2022 at 19:05:58 UTC, Ali Çehreli > > > wrote: > > >> Running the

Re: Make IN Dlang

2022-11-04 Thread H. S. Teoh via Digitalmars-d-learn
Happened to stumble across this today, which I thought is a relevant, if sadly humorous, take on build systems: https://pozorvlak.dreamwidth.org/174323.html T -- ASCII stupid question, getty stupid ANSI.

Re: Makefiles and dub

2022-11-04 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 04, 2022 at 11:19:17PM +, Anonymouse via Digitalmars-d-learn wrote: > [#20699](https://issues.dlang.org/show_bug.cgi?id=20699) must be > non-trivial to fix, so I'm exploring makefiles. If possible I'd like > to keep dub for dependency management though, just not for actual >

Re: Hipreme's #4 Tip of the day - Don't use package.d

2022-11-04 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 04, 2022 at 07:34:58PM +, jmh530 via Digitalmars-d-learn wrote: > On Friday, 4 November 2022 at 19:17:04 UTC, Adam D Ruppe wrote: > > On Friday, 4 November 2022 at 19:10:33 UTC, jmh530 wrote: > > > If you don't plan to use private(package_name), then I don't know > > > what the

Re: Make IN Dlang

2022-11-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 02, 2022 at 09:16:22PM +0100, Christian Köstlin via Digitalmars-d-learn wrote: > On 02.11.22 20:16, H. S. Teoh wrote: [...] > > IMO, the ideal situation is a hybrid situation: the underlying build > > mechanism should be purely declarative, because otherwise the > > complexity just

Re: Unit testing a function returning void

2022-11-03 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 03, 2022 at 08:51:52AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > 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

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

2022-11-03 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 03, 2022 at 04:41:14AM +, Siarhei Siamashka via Digitalmars-d-learn wrote: [...] > ```D > @safe: > import std.stdio; > class A { > void foo() { writeln("foo"); } > } > void main() { > auto a1 = new A; > a1.foo(); // prints "foo" > A a2; > a2.foo(); // Segmentation fault

Re: Make IN Dlang

2022-11-02 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 02, 2022 at 03:08:36PM +, JN via Digitalmars-d-learn wrote: > On Tuesday, 1 November 2022 at 23:40:22 UTC, Christian Köstlin wrote: > > sh("touch %s".format(t.name)); > > One of the problems of many Make-like tools is that they offer lots of > freedom, especially

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

2022-11-01 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Nov 01, 2022 at 10:37:57AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > 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. Oh yes, sorry, I

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

2022-11-01 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Nov 01, 2022 at 05:19:56PM +, mw via Digitalmars-d-learn wrote: > My program received signal SIGSEGV, Segmentation fault. > > Its simplified structure looks like this: > > ``` > void foo() { > ... > writeln("done"); // saw this got printed! > } > > int main() { > foo(); >

Re: how to benchmark pure functions?

2022-10-27 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Oct 27, 2022 at 06:20:10PM +, Imperatorn via Digitalmars-d-learn wrote: > On Thursday, 27 October 2022 at 17:17:01 UTC, ab wrote: > > Hi, > > > > when trying to compare different implementations of the optimized > > builds of a pure function using benchmark from > >

Re: Importing modules under DUB on Windows

2022-10-26 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 26, 2022 at 04:20:01PM +, DLearner via Digitalmars-d-learn wrote: > Hi > > Never used DUB before. > Wanted to use a function stored in a module outside the main source. > > Main source has `import ;` > > Put a line into the JSON: `"importPaths": "C:\\Users\\..."` pointing > to

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

2022-10-25 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 26, 2022 at 12:16:55AM +, Salih Dincer via Digitalmars-d-learn wrote: [...] > I've known D for more than 10 years, but the topic we're talking about > still seems strange to me. The explanations given are not enough for > me, I'm sorry. > > Can anyone tell me what happens when I

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

2022-10-24 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Oct 24, 2022 at 09:26:14PM +, Per Nordlöw via Digitalmars-d-learn 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

Re: Design question regarding saving changes in the original array and/or returning a new set

2022-10-23 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Oct 23, 2022 at 01:32:44PM +, matheus via Digitalmars-d-learn wrote: > Hi, > > I have a design question and I'd like to hear some advice. Let's say > that I want to create a method to sort an array: > > arr.sort(asc); > > I think usually this would usually return a new set of

Re: [Help Needed] - Debugging compilation time

2022-10-21 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Oct 21, 2022 at 04:32:17PM +, Hipreme via Digitalmars-d-learn wrote: > Hey guys, I have been complaining a lot of time right now from D > compilation speed at least for my project. > > I have: > - Underused CTFE > - Underused Templates > - Avoided importing standard libraries > -

Re: Can someone tell me what the compiler thought I was trying to do?

2022-10-18 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 19, 2022 at 01:15:37AM +, Adam D Ruppe via Digitalmars-d-learn wrote: > On Wednesday, 19 October 2022 at 00:57:31 UTC, H. S. Teoh wrote: > > Has it really been implemented? I tested the latest git master, the > > following code doesn't compile: > > it only applies to types, not

Re: Can someone tell me what the compiler thought I was trying to do?

2022-10-18 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Oct 15, 2022 at 12:47:02AM +, Mike Parker via Digitalmars-d-learn wrote: > On Friday, 14 October 2022 at 22:17:52 UTC, H. S. Teoh wrote: > > > Given that this particular trap crops up regularly, perhaps some > > sort of warning ought to be added. Once the @nodiscard DIP is > >

Re: Can someone tell me what the compiler thought I was trying to do?

2022-10-14 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Oct 14, 2022 at 09:51:54PM +, WhatMeWorry via Digitalmars-d-learn wrote: > > I lost about a half an hour troubleshooting some code of mine which as it > turned out to be resolved with just one line. > > > // paths.remove(i); // compiles fine but does nothing > > paths =

Re: Convert int to dchar

2022-10-05 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 05, 2022 at 04:57:57PM +, Paul via Digitalmars-d-learn wrote: >I'm sure I'm making this more difficult than it needs to be. I'm > trying to convert an integer to a dchar. The solution below works but > seems like overkill. > > dstring dstrValue = to!dstring(5); >

Re: rotate left an array

2022-10-03 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Oct 03, 2022 at 05:38:25PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: [...] > Good catch but I think what we want is a copy of the front element, at > least for InputRanges (.save does not work for File.byLine :/). One of the things we need to settle in Phobos v2 is what to do

Re: How is it possible that countUntil() generates a jump-table when the hayStack is a compile time array?

2022-10-01 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Oct 01, 2022 at 01:20:08PM +, realhet via Digitalmars-d-learn wrote: > Hello, > > I just wanted to optimize a byte -> index lookup, by using a 256 > element table instead of using [1, 2, 3].countUntil(x) and I was > amazed what I've found. > My solution lookup[x] was not faster at

Re: How to workaround on this (bug?)

2022-09-16 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Sep 17, 2022 at 12:19:16AM +, frame via Digitalmars-d-learn wrote: > On Friday, 16 September 2022 at 23:06:35 UTC, H. S. Teoh wrote: > > > Basically, if you pass something to .fun by value, then that value > > must be destroyed by .fun once it's ready to return. So if the > > value

Re: How to workaround on this (bug?)

2022-09-16 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 16, 2022 at 10:43:43PM +, frame via Digitalmars-d-learn wrote: > ```d > import std.variant; > > // error: destructor `std.variant.VariantN!32LU.VariantN.~this` is not > `nothrow` > void fun(Variant v) nothrow > { > > } > > void main() > { >fun(Variant()); > } > ``` > > A

Re: Function attribute best practices

2022-09-12 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 12, 2022 at 02:29:58PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > If your intent is to *enforce* pure functions only, then that's what > you do. If your intent instead is to ensure that given proper > parameters, the function will be pure, then the answer is

Re: Function attribute best practices

2022-09-12 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 12, 2022 at 10:08:29AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: [...] > What I meant was > > - if I put 'pure' etc. on my templatized code, > > - and then tested with a 'pure' unittest, > > I wouldn't know that the gratuitous use of my 'pure' on the member > function was

Re: Function attribute best practices

2022-09-12 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Sep 12, 2022 at 09:14:42AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: [...] > struct Foo(R) { > R r; > int i; > > bool empty() @nogc nothrow pure @safe scope { > return r.empty; > } > > auto front() @nogc nothrow pure @safe scope { > return

Re: import `Class` is used as a type

2022-09-10 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Sep 10, 2022 at 04:59:50PM +, Injeckt via Digitalmars-d-learn wrote: > I'm trying use classes in my project, but when i'm try inherit class, > I get error: > > Error: import `Server.Console` is used as a type [...] Don't name the module the same thing as the class. Rename it

Re: How include header file?

2022-09-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Sep 07, 2022 at 06:11:14PM +, Injeckt via Digitalmars-d-learn wrote: > I need to include this Ws2tcpip.h header file to my project. How can I > do this? It's all because I need inet_ntop function from this header > file. If that's the only function you need, you can just copy the

Re: How to use exceptions

2022-08-11 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 12, 2022 at 12:12:13AM +, Adam D Ruppe via Digitalmars-d-learn wrote: > On Thursday, 11 August 2022 at 23:50:58 UTC, H. S. Teoh wrote: > > I think the OP's idea is somewhat different: adding contextual > > information to a propagating exception that the throwing code may > > not

Re: How to use exceptions

2022-08-11 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 11, 2022 at 11:06:45PM +, Adam D Ruppe via Digitalmars-d-learn wrote: > You might find my recent blog post interesting too: > > http://dpldocs.info/this-week-in-d/Blog.Posted_2022_08_01.html#exception-template-concept > > and a draft of some more concepts: >

Re: Ranges

2022-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Aug 06, 2022 at 03:37:32PM +, pascal111 via Digitalmars-d-learn wrote: > On Friday, 5 August 2022 at 04:05:08 UTC, Salih Dincer wrote: > > On Thursday, 4 August 2022 at 22:54:42 UTC, pascal111 wrote: > > > > > > I didn't notice that all what we needs to pop a range forward is > > >

Re: Ranges

2022-08-05 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 05, 2022 at 08:06:00AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > [...] I realized that the following fails with a RangeError: > > void main() { > auto arr = [1, 2, 3]; > arr[0..$-1] = arr[1..$];// <-- Runtime error > } > > I suspect the length of the array is

Re: Obscure Isssue #1

2022-08-05 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 05, 2022 at 02:23:15PM +, Ruby The Roobster via Digitalmars-d-learn wrote: > On Friday, 5 August 2022 at 14:11:09 UTC, H. S. Teoh wrote: > > On Fri, Aug 05, 2022 at 01:56:40PM +, Ruby The Roobster via > > Digitalmars-d-learn wrote: [...] > > > public import dutils.math.core; >

Re: Obscure Isssue #1

2022-08-05 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 05, 2022 at 01:56:40PM +, Ruby The Roobster via Digitalmars-d-learn wrote: [...] > public import dutils.math.core; Is the imported module available anywhere? I'm trying to run your code sample to determine what's going on, but it's not compiling because you didn't post the code

Re: curses/ncurses liberary in D

2022-08-04 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 04, 2022 at 11:52:48PM +, pascal111 via Digitalmars-d-learn wrote: > On Thursday, 4 August 2022 at 21:35:37 UTC, Adam D Ruppe wrote: > > On Thursday, 4 August 2022 at 21:15:39 UTC, pascal111 wrote: > > > > https://github.com/adamdruppe/arsd/blob/master/terminal.d > > > > > > How

Re: How to find all modules in a package?

2022-08-04 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 04, 2022 at 07:22:04AM +, Domain via Digitalmars-d-learn wrote: > On Wednesday, 3 August 2022 at 12:27:32 UTC, frame wrote: > > On Wednesday, 3 August 2022 at 03:36:55 UTC, Domain wrote: > > > I want to find out all public functions in all modules in a package. > > > Can I do that

Re: BigInt.toString

2022-08-03 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 04, 2022 at 12:45:44AM +, Ruby The Roobster via Digitalmars-d-learn wrote: > How exactly can one store the string representation of a BigInt? The > seemingly obvious > > ```d > //... > dchar[] ret; //dchar[] is necessary for my project > //Assume that val is a BigInt with a

Re: MMFile usage

2022-08-03 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 04, 2022 at 12:35:55AM +, Alex Burton via Digitalmars-d-learn wrote: > Hi, > I want to use MmFile to manage memory mapped files. I want multiple > processes to be able to read in many files using the virtual memory > system to page them in and reuse the memory. > > If I read the

Re: Request assistance resolving linker error: Undefined symbol(s) for architecture x86_64

2022-08-02 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Aug 03, 2022 at 04:28:57AM +, anonymouse via Digitalmars-d-learn wrote: > How do I go about tracking down what's causing the following error: > > ``` > Undefined symbols for architecture x86_64: > "__D3std8internal6memory12__ModuleInfoZ", referenced from: >

Re: Write binary data as a file

2022-08-02 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Aug 02, 2022 at 11:10:27AM +, Alexander Zhirov via Digitalmars-d-learn wrote: [...] > ```d > auto result = db.query("select tcxs.settings_file as dbfile from > amts.t_client_xrdp_settings tcxs where tcxs.pid_client = ?", id); > ubyte[] bytes = cast(ubyte[])result.front()["dbfile"]; >

Re: A converting problem in using "among" with arrays

2022-07-29 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 29, 2022 at 10:32:11PM +, pascal111 via Digitalmars-d-learn wrote: [...] > I want searching for value 54 in array y "54.among(y).writeln;", but > it seems compiler complaints because the data type is "int[]", so I > tried to convert "y" to "uint[]". You're using the wrong

Re: Is this a violation of const?

2022-07-29 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 29, 2022 at 09:56:20PM +, Andrey Zherikov via Digitalmars-d-learn wrote: > In the example below `func` changes its `const*` argument. Does this > violates D's constness? > > ```d > import std; > > struct S > { > string s; > > void delegate(string s) update; > } > >

Re: "strtok" D equivalent

2022-07-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 28, 2022 at 09:03:55PM +, pascal111 via Digitalmars-d-learn wrote: > On Thursday, 28 July 2022 at 19:37:31 UTC, rikki cattermole wrote: [...] > > foreach(value; input.splitWhen!((a, b) => delimiters.canFind(b))) { > > writeln(value); > > } > > } > > ``` > > From

Re: Some user-made C functions and their D equivalents

2022-07-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 28, 2022 at 04:45:55PM +, pascal111 via Digitalmars-d-learn wrote: > On Thursday, 28 July 2022 at 16:37:35 UTC, frame wrote: > > On Thursday, 28 July 2022 at 16:17:16 UTC, pascal111 wrote: > > > > > My friend, there is a wide deep secret world for hackers. We have > > > no any

Re: BASIC "sgn" function equivalent

2022-07-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 28, 2022 at 03:10:19PM +, pascal111 via Digitalmars-d-learn wrote: > On Thursday, 28 July 2022 at 15:03:34 UTC, H. S. Teoh wrote: > > On Thu, Jul 28, 2022 at 02:30:38PM +, pascal111 via > > Digitalmars-d-learn wrote: [...] > > > Of-course D has a built in "sgn" function, but I

Re: BASIC "sgn" function equivalent

2022-07-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 28, 2022 at 02:30:38PM +, pascal111 via Digitalmars-d-learn wrote: [...] > Of-course D has a built in "sgn" function, but I like to do it with my > hands to be sure of code, I'm some doubtful and don't trust alien > works. Just use the source, Luke! Phobos is open source for a

Re: char* pointers between C and D

2022-07-25 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 25, 2022 at 05:30:14PM +, pascal111 via Digitalmars-d-learn wrote: [...] > int main(string[] args) > { > > > const(char)[] ch1 = "Hello World!"; > char[] ch2="Hello World!".dup; > > const(char) *p1; > char *p2; > > ch2~="\0"; > >

Re: OK to do bit-packing with GC pointers?

2022-07-22 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 22, 2022 at 04:50:44PM +, Ben Jones via Digitalmars-d-learn wrote: > I'm looking to store a pointer to one of 2 unrelated (no inheritance > relationship) classes and use the LSb to track which type I have. Is > this going to cause any problems with the GC? For one of the classes

Re: null == "" is true?

2022-07-12 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 12, 2022 at 07:55:46PM +, ag0aep6g via Digitalmars-d-learn wrote: > On Tuesday, 12 July 2022 at 19:02:01 UTC, user1234 wrote: > > On Tuesday, 12 July 2022 at 16:40:38 UTC, H. S. Teoh wrote: > [...] > > > Do not rely on this, however; > > > > Absolutely. I'd like to add:

Re: null == "" is true?

2022-07-12 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 12, 2022 at 04:27:44PM +, Antonio via Digitalmars-d-learn wrote: > It works > > ```d > void main() > { >assert(null==""); > } > ``` > > why? Because an empty string is, by default, represented by an empty slice of the null pointer. Do not rely on this, however; it's

Re: How can I match every instance of a template type (struct)?

2022-07-12 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jul 12, 2022 at 01:56:11PM +, rempas via Digitalmars-d-learn wrote: > On Tuesday, 12 July 2022 at 13:37:49 UTC, ag0aep6g wrote: > > > > static if (is(typeof(obj) == Test!T, T)) { printf("YES!!!\n"); } > > Haah? Ok, what does this work anyway? I thought you needed >

Re: destroy and @safe

2022-06-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 21, 2022 at 06:28:14PM +, Paul Backus via Digitalmars-d-learn wrote: > On Tuesday, 21 June 2022 at 17:33:46 UTC, H. S. Teoh wrote: > > > > Does the language allow you to declare a @system delegate inside > > @safe code? > > Yes. This compiles: > > void main() @safe > {

Re: destroy and @safe

2022-06-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 21, 2022 at 01:29:47PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 6/21/22 1:17 PM, H. S. Teoh wrote: [...] > > This is why I've proposed in the past that @safe functions should be > > allowed to call @system delegates that they receive as arguments. The > >

Re: destroy and @safe

2022-06-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 21, 2022 at 04:47:44PM +, Antonio via Digitalmars-d-learn wrote: > On Tuesday, 21 June 2022 at 16:20:32 UTC, Antonio wrote: > > > My code starts to be a @safe/@trusted mess (because external > > libraries). The only solution I have is to "wrap" them or to trust > > all code by

Re: a struct as an multidimensional array index

2022-06-10 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 10, 2022 at 08:08:45AM +, Chris Katko via Digitalmars-d-learn wrote: > Is it somehow possible to use a struct as a [multidimensional] array index: > > D > > struct indexedPair > { > size_t x, y; > } > > bool isMapPassable[100][100]; > auto p = indexedPair(50, 50); > >

Re: want to confirm: gc will not free a non-gc-allocated field of a gc-allocated object?

2022-06-06 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jun 06, 2022 at 10:18:08PM +, mw via Digitalmars-d-learn wrote: > Hi, > > Suppose I have this code: > > ``` > class GCAllocated { > float[] data; > > this() { > // non-gc-allocated field > this.data = cast(float[])(core.stdc.stdlib.malloc(nBytes)[0 .. nBytes]); > } > }

Re: Unexplainable behaviour with direct struct assignment.

2022-05-18 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 18, 2022 at 08:05:05PM +, HuskyNator via Digitalmars-d-learn wrote: [...] > ```d > module app; > import std.stdio; > > struct A { > float[1] vec; > this(float[1] n) { > this.vec = n; > } > } > > void main(string[] args) { > A c = A([50.0f]);

Re: class destructors must be @disabled?

2022-05-18 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 18, 2022 at 02:35:00PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > No. Class destructors are for cleaning up non-GC resources. As long as > you stick to those, you can safely run them. > > Structs that get put into classes have to run their destructors >

Re: class destructors must be @disabled?

2022-05-18 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 18, 2022 at 11:02:01AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: [...] > HORROR: > > Now, a big one that I've just realized. > > - The two guidelines above (the "don't touch class members" one and > the "don't allocate" one) miss an important fact that they apply >

Re: Why are structs and classes so different?

2022-05-16 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, May 16, 2022 at 05:02:57PM +, IGotD- via Digitalmars-d-learn wrote: > On Sunday, 15 May 2022 at 16:08:01 UTC, Mike Parker wrote: > > > > `scope` in a class variable declaration will cause it to the class > > to be allocated on the stack. > > > > Common practice is that a class has

Re: What are (were) the most difficult parts of D?

2022-05-16 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, May 16, 2022 at 04:00:12AM +, cc via Digitalmars-d-learn wrote: > On Wednesday, 11 May 2022 at 05:41:35 UTC, Ali Çehreli wrote: > > What are you stuck at? What was the most difficult features to > > understand? etc. > > > > To make it more meaningful, what is your experience with

Re: Why are structs and classes so different?

2022-05-15 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, May 15, 2022 at 08:05:05PM +, Kevin Bailey via Digitalmars-d-learn wrote: [...] > But I asked a different question: Why can't I put a class object on > the stack? What's the danger? [...] You can. Use core.lifetime.emplace. Though even there, there's the theoretical problem of stack

Re: What are (were) the most difficult parts of D?

2022-05-14 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, May 14, 2022 at 04:39:33AM +, zjh via Digitalmars-d-learn wrote: > On Saturday, 14 May 2022 at 04:31:48 UTC, zjh wrote: > > > Likewise, each post could add something like `votes` , > > Or something like all kinds of `tags` such as > `range/fiber/commandline/auto ref/in/...`. > >

Re: What are (were) the most difficult parts of D?

2022-05-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 13, 2022 at 06:29:54PM +, Adam D Ruppe via Digitalmars-d-learn wrote: [...] > Yeah, I used to be pro-TLS by default, then got bit by it several > times and moved to the fence, and now I'm anti. > > Data races aren't actually prevented by it (maybe forcing you to > specify shared

Re: What are (were) the most difficult parts of D?

2022-05-13 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 12, 2022 at 11:45:47PM +, Guillaume Piolat via Digitalmars-d-learn wrote: > On Thursday, 12 May 2022 at 17:34:30 UTC, H. S. Teoh wrote: > > > > Why is TLS by default a problem? > > > > It's not really for optimization, AIUI, it's more for thread safety: > > module-global state

Re: Back to Basics at DConf?

2022-05-13 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 13, 2022 at 03:43:09PM +, Johan via Digitalmars-d-learn wrote: > On Thursday, 12 May 2022 at 21:58:33 UTC, Ali Çehreli wrote: > > I am considering proposing a presentation for DConf 2022. > > > > Would a "Back to Basics" style presentation be interesting? If, so > > what exact

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