Re: Goto skipping declarations

2024-05-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, May 3, 2024 1:15:16 PM MDT Ben Jones via Digitalmars-d-learn wrote: > In general, you can't skip a declaration with goto, but it seems > to be allowed if the declaration you're skipping is labelled... > Is that expected or an accepts invalid bug? > > https://godbolt.org/z/4qx8Pf6G7 > > `

Re: Goto skipping declarations

2024-05-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, May 3, 2024 2:38:31 PM MDT Jonathan M Davis via Digitalmars-d-learn wrote: > On Friday, May 3, 2024 1:15:16 PM MDT Ben Jones via Digitalmars-d-learn wrote: > > In general, you can't skip a declaration with goto, but it seems > > to be allowed if the declaratio

Re: Problem with clear on shared associative array?

2024-05-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 26, 2024 8:39:53 AM MDT Andy Valencia via Digitalmars-d-learn wrote: > The following code fails to compile; it appears from the error > message that the library's clear() function is not ready to act > on a shared AA? > > synchronized class F { > > private: > string[int] mydict

Re: Socket and spawn()

2024-05-31 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, May 31, 2024 10:07:23 AM MDT Andy Valencia via Digitalmars-d-learn wrote: > I'm coding a server which takes TCP connections. I end up in the > main thread with .accept() which hands me a Socket. I'd like to > hand this off to a spawn()'ed thread to do the actual work. > > Aliases

Re: Socket and spawn()

2024-05-31 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, May 31, 2024 6:28:27 PM MDT Andy Valencia via Digitalmars-d-learn wrote: > On Friday, 31 May 2024 at 16:59:08 UTC, Jonathan M Davis wrote: > > Speaking as an old kernel engineer for the Sequent multiprocessor > product line, this is all very comfortable to me. I'm very glad > that D ha

Re: Pointer to dlang spec for this alias construct?

2024-06-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, June 16, 2024 10:32:50 PM MDT Andy Valencia via Digitalmars-d-learn wrote: > In the alias: > > alias Unshared(T) = T; > alias Unshared(T: shared U, U) = U; > > as used in: > > cast(Unshared!mytype)value > > turns a mytype with shared attribute into one without shared. > >

Re: importC Error: undefined identifier `__atomic_thread_fence`

2024-06-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, June 21, 2024 12:39:44 PM MDT mw via Digitalmars-d-learn wrote: > Looks like `__atomic_thread_fence` is a GCC built-in function, so > how to make importC recognize it? dmd cannot handle it. gcc or ldc might, but dmd generally needs standard C code. Stuff like gcc built-ins basically has

Re: Why does this mixin fail to compile?

2024-07-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, July 2, 2024 1:23:42 AM MDT ryuukk_ via Digitalmars-d-learn wrote: > I said it 2 times already, i don't want string concatenation, > i'll benchmark later, but not right now, right now i'm looking > for a functioning code without string concatenation D has two options for mixins, and bo

Re: Unexpected range assignment behaviour

2024-07-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, July 19, 2024 12:02:55 PM MDT H. S. Teoh via Digitalmars-d-learn wrote: > On Fri, Jul 19, 2024 at 05:48:37PM +, Dennis via Digitalmars-d-learn wrote: > > On Friday, 19 July 2024 at 17:20:22 UTC, matheus wrote: > > > couldn't this case for example be caught during the compiling time

Re: copy must be const?!?

2024-07-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 25, 2024 12:50:04 AM MDT Dom DiSc via Digitalmars-d-learn wrote: > On Wednesday, 24 July 2024 at 15:40:28 UTC, Dennis wrote: > >> Is there a way to tell the compiler that it should discard > >> "const" and "immutable" if it needs to create a copy? > >> Unqual!T doesn't work :-( >

Re: copy must be const?!?

2024-07-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 25, 2024 6:00:58 AM MDT Dom DiSc via Digitalmars-d-learn wrote: > > And no, in general, you don't want to be casting away const or > > immutable. There are cases where it can work (e.g. if the cast > > does a copy, which it would with an integer type) > > But a parameter given by

Re: Prevent self-comparison without taking the address

2024-07-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 25, 2024 4:50:04 AM MDT Dom DiSc via Digitalmars-d-learn wrote: > I have copied some source from C++, where the following pattern > is common (operator== already renamed): > > ```d > @safe: > struct S > { > bool opEquals(const ref S x) const > { >if(&x==&this) ret

Re: What is an rvalue constructor?

2024-07-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 25, 2024 4:48:06 PM MDT Quirin Schroll via Digitalmars-d- learn wrote: > It seems one can’t have one in a struct together with a copy > constructor, but what is it? When is it called? What is it for? An rvalue constructor is a constructor that takes the same type as the struct th

Re: copy must be const?!?

2024-07-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, July 26, 2024 2:17:21 AM MDT Dom DiSc via Digitalmars-d-learn wrote: > On Thursday, 25 July 2024 at 13:07:03 UTC, Jonathan M Davis wrote: > > On Thursday, July 25, 2024 6:00:58 AM MDT Dom DiSc via > > > >> But a parameter given by value is ALWAYS a copy. > > > > It has to be a _full_, i

Re: create fixed length string of characters

2024-08-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, August 16, 2024 9:58:31 AM MDT Nick Treleaven via Digitalmars-d- learn wrote: > On Friday, 16 August 2024 at 13:30:53 UTC, IchorDev wrote: > > On Friday, 16 August 2024 at 11:37:08 UTC, Nick Treleaven wrote: > >> On Friday, 16 August 2024 at 06:15:18 UTC, Bruce wrote: > >> ```d > >> stri

Re: create fixed length string of characters

2024-08-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, August 16, 2024 10:37:45 AM MDT Nick Treleaven via Digitalmars-d- learn wrote: > On Friday, 16 August 2024 at 16:30:09 UTC, Jonathan M Davis wrote: > > Whether the result of dup is then able to be implicitly > > converted to immutable based on whether the operation is pure > > depends on

Re: Understanding the Behavior of i + ++i in D Language

2024-08-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, August 28, 2024 3:44:59 PM MDT Johann Lermer via Digitalmars-d- learn wrote: > On Friday, 23 August 2024 at 08:58:16 UTC, Me'vâ wrote: > > writeln("Result: ", i + ++i); > > I would definitely expect 11 as result (but I still have K&R on > my book shelf, maybe I'm a bit biased). So

Re: Problem with assertThrown

2024-09-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, September 9, 2024 5:46:18 PM MDT kookman via Digitalmars-d-learn wrote: > It seems like assertThrown works as expected for case 4, but > mysteriously not working for case 5 - despite the code under test > raising the same exception. Am I missing something stupid here? At a glance, it l

Re: Problem with assertThrown

2024-09-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, September 9, 2024 6:40:07 PM MDT kookman via Digitalmars-d-learn wrote: > On Tuesday, 10 September 2024 at 00:27:43 UTC, Jonathan M Davis > > wrote: > > On Monday, September 9, 2024 5:46:18 PM MDT kookman via > > > > Digitalmars-d-learn wrote: > >> It seems like assertThrown works as ex

Re: assert

2024-09-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, September 10, 2024 10:01:53 PM MDT f via Digitalmars-d-learn wrote: > i mean , is this a bug? No, it's not a bug. Assertions with an expression that is known to be false at compile time are treated as special. They are always left in the generated code so that they will kill your prog

Re: Calling C functions that modify a string

2023-06-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 15, 2023 7:18:06 AM MDT Steven Schveighoffer via Digitalmars-d-learn wrote: > But in general, if you want a mutable character array that's zero > terminated, you need to make a copy with a zero terminator, but type it > as mutable. I'm surprised there isn't a way to do this easil

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

2023-06-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 15, 2023 7:18:25 PM MDT zjh via Digitalmars-d-learn wrote: > On Friday, 16 June 2023 at 01:00:05 UTC, Steven Schveighoffer > > wrote: > > B b = B.make(); // call factory function > > > > -Steve > > Thank you for your tip. > If could simplify it a bit more, it would be even better.

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

2023-06-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 15, 2023 7:54:22 PM MDT Jonathan M Davis via Digitalmars-d- learn wrote: > On Thursday, June 15, 2023 7:18:25 PM MDT zjh via Digitalmars-d-learn wrote: > > On Friday, 16 June 2023 at 01:00:05 UTC, Steven Schveighoffer > > > > wrote: > > > B b = B.ma

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

2023-06-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, June 18, 2023 2:24:10 PM MDT Cecil Ward via Digitalmars-d-learn wrote: > I wasn’t intending to use DMD, rather ldc if possible or GDC > because of their excellent optimisation, in which DMD seems > lacking, is that fair? (Have only briefly looked at dmd+x86 and > haven’t given DMD’s bac

Re: A couple of questions about arrays and slices

2023-06-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, June 20, 2023 8:09:26 PM MDT Cecil Ward via Digitalmars-d-learn wrote: > First is an easy one: > > 1.) I have a large array and a sub-slice which I want to set up > to be pointing into a sub-range of it. What do I write if I know > the start and end indices ? Concerned about an off-by-

Re: A couple of questions about arrays and slices

2023-06-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, June 21, 2023 7:05:28 PM MDT Paul Backus via Digitalmars-d-learn wrote: > On Thursday, 22 June 2023 at 00:10:19 UTC, Cecil Ward wrote: > > Is .reserve()’s argument scaled by the entry size after it is > > supplied, that is it is quoted in elements or is it in bytes? > > I’m not sure

Re: A couple of questions about arrays and slices

2023-06-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, June 23, 2023 7:02:12 PM MDT Cecil Ward via Digitalmars-d-learn wrote: > I just had a fight with LDC over the following code when I tried > out reserve. I have an associative array that maps strings to > ‘ordinals’ ie uints that are unique, and the compiler hates the > call to reserve.

Re: A couple of questions about arrays and slices

2023-06-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, June 24, 2023 1:43:53 AM MDT Cecil Ward via Digitalmars-d-learn wrote: > On Saturday, 24 June 2023 at 07:36:26 UTC, Cecil Ward wrote: > > Jonathan, is it possible that I wanted one thing and got > > another? My description in the earlier post was of the _aim_ of > > the program. What

Re: A couple of questions about arrays and slices

2023-06-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, June 24, 2023 8:43:00 AM MDT Cecil Ward via Digitalmars-d-learn wrote: > I started out looking into a number of runtime library routines, > but in the end it seemed quicker to roll my own code for a crude > recursive descent parser/lexer that parses part of D’s grammar > for expressio

Re: Counting an initialised array, and segments

2023-06-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, June 25, 2023 4:08:19 PM MDT Cecil Ward via Digitalmars-d-learn wrote: > I recently had some problems > > dchar[] arr = [ ‘ ‘, TAB, CR, LF … ]; > > and I got errors from the compiler which led to me having to > count the elements in the initialiser and declare the array with > an explic

Re: Counting an initialised array, and segments

2023-06-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, June 26, 2023 5:08:06 AM MDT Cecil Ward via Digitalmars-d-learn wrote: > On Monday, 26 June 2023 at 08:26:31 UTC, Jonathan M Davis wrote: > > On Sunday, June 25, 2023 4:08:19 PM MDT Cecil Ward via > > > > Digitalmars-d-learn wrote: > >> I recently had some problems > >> > >> dchar[] arr

Re: Counting an initialised array, and segments

2023-06-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, June 26, 2023 1:09:24 PM MDT Cecil Ward via Digitalmars-d-learn wrote: > No, point taken, a sloppy example. I don’t in fact do that in the > real code. I use dchar everywhere appropriate instead of uint. In > fact I have aliases for dstring and dchar and successfully did an > alternativ

Re: pragma msg field name?

2023-06-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, June 26, 2023 10:25:13 PM MDT Chris Katko via Digitalmars-d-learn wrote: > inside a static foreach I can do > > ``` > enum rep; > > class myObject{ > int field1, field2, field3; > > static foreach(field; getSymbolsByUDA!(typeof(this), rep)) > { > pragma(msg, field); // fails > prag

Re: Debugging by old fashioned trace log printfs / writefln

2023-06-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, June 29, 2023 12:27:22 PM MDT Cecil Ward via Digitalmars-d-learn wrote: > I’m trying to debug my D program with old-fashioned printfs stuck > in various strategic places, actually using writefln(). My > problem is that the addition of printf fights with the existing > declarations for

Re: Pre-import version statements

2023-07-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, July 19, 2023 10:56:26 PM MDT Chris Piker via Digitalmars-d- learn wrote: > Hi D > > In my C code I used to typically put the line: > ``` > #define _POSIX_C_SOURCE 200112L > ``` > in the source before importing any standard library headers. Is > there something equivalent for phobos?

Re: Recommendation on plotting library

2023-07-20 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 20, 2023 10:57:22 PM MDT Chris Piker via Digitalmars-d-learn wrote: > (Warning, possible ill-informed opinions ahead...) > > In a way there is a need to reinvent the wheel. With python I > can run `pip install matplotlib` and get whatever binaries I need > to get the job done.

Re: Recommendation on plotting library

2023-07-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, July 21, 2023 1:03:47 AM MDT Chris Piker via Digitalmars-d-learn wrote: > On Friday, 21 July 2023 at 06:15:10 UTC, Jonathan M Davis wrote: > > On Thursday, July 20, 2023 10:57:22 PM MDT Chris Piker via > > Digitalmars-d-learn wrote: > > > > Regardless though, dub really isn't designed w

Re: Recommendation on plotting library

2023-07-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, July 21, 2023 11:40:25 AM MDT Greggor via Digitalmars-d-learn wrote: > >> So as far as I can tell, python pip originally only dealt with > >> python code, but eventually wheels were added for binary > >> support. > >> > >> Just as a wild guess, do you see dub ever evolving in that > >

Re: array index out of bound may not throw exception?

2023-07-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, July 21, 2023 3:27:45 PM MDT mw via Digitalmars-d-learn wrote: > Hi, > > I have thought array index out of bound always throw exceptions. > > However, I just debugged a case, where out of bound array index > didn't throw exception, and just hang the thread, which is much > harder to debu

Re: AA vs __gshared

2023-07-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 27, 2023 9:57:51 AM MDT IchorDev via Digitalmars-d-learn wrote: > I've been getting a lot of segfaults from using associative > arrays recently. The faults happen seemingly at random, and from > pretty mundane stuff like `if(auto x = y in z)` that run very > often: > ``` > Segmen

Re: How can overloads be distinguished on attributes alone?

2023-07-31 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, July 31, 2023 4:55:44 AM MDT Quirin Schroll via Digitalmars-d-learn wrote: > Apparently, functions can be overloaded solely distinguished by > attributes: > ```d > void f(ref int x) pure { x = 1; } > void f(ref int x) { x = 2; static int s; ++s; } > ``` > > I thought that, maybe, a

Re: Why is GC.collect `pure`

2023-08-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, August 2, 2023 12:02:35 PM MDT Nick Treleaven via Digitalmars-d- learn wrote: > On Wednesday, 2 August 2023 at 17:55:12 UTC, Nick Treleaven wrote: > > On Wednesday, 2 August 2023 at 17:52:00 UTC, Nick Treleaven > > > > wrote: > >> Now I'm wondering why those functions are marked `pure

Re: Setting up a final switch from a list

2023-08-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, August 2, 2023 12:19:55 PM MDT Cecil Ward via Digitalmars-d- learn wrote: > Am I right in thinking that final switch can be used to check > that all the elements in an enum are handled in cases? Thinking > that this is a worthwhile safety check, I’d like to convert an > existing list

Re: Mach status support

2023-08-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, August 21, 2023 2:54:02 PM MDT Sergey via Digitalmars-d-learn wrote: > When I worked with one C code translation, I found that command > clock_gettime, that available in POSIX systems is not implemented > in MacOS. > This SO thread > > https://stackoverflow.com/questions/5167269/clock-g

Re: Cool pattern or tragic?

2023-08-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, August 25, 2023 3:00:08 PM MDT Guillaume Piolat via Digitalmars-d- learn wrote: > The idea is to deliberately mark @system functions that need > special scrutiny to use, regardless of their memory-safety. > Function that would typically be named `assumeXXX`. > > > > ```d > class MyEncode

Re: Function to get the current hostname for both Windows and Posix

2023-08-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, August 27, 2023 10:02:35 AM MDT vino via Digitalmars-d-learn wrote: > Hi All, > > May i know whether these is function to find the current > hostname both in windows and Posix. > > From, > Vino It looks like std.socket's Socket.hostName will do the trick. https://dlang.org/phobos/std

Re: I don't understand betterC

2023-09-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, September 2, 2023 4:38:41 AM BST confused via Digitalmars-d-learn wrote: > On Friday, 1 September 2023 at 13:45:05 UTC, evilrat wrote: > > It is shadowing default implicit "import object;", here a > > demonstration > > > > ```d > > // this example shows default implicit import of "obj

Re: Is sizeof() available in D language?

2023-09-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, September 4, 2023 2:34:08 PM MDT Olivier Pisano via Digitalmars-d- learn wrote: > On Monday, 4 September 2023 at 09:41:54 UTC, BoQsc wrote: > > I've seen everyone using **datatype**`.sizeof` property. > > > > https://dlang.org/spec/property.html#sizeof > > > > It's great, but I wonder if

Re: Weird floating point rounding - Bug or how to control it correctly

2023-09-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, September 13, 2023 9:23:48 PM MDT An Pham via Digitalmars-d- learn wrote: > import std.stdio; > > void main() > { > float f = 6394763.345f; > > import std.format : sformat; > > char[80] vBuffer = void; > writeln("6394763.345 = ", sformat(v

Re: std.file: read, readText and UTF-8 decoding

2023-09-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, September 21, 2023 9:29:17 AM MDT Uranuz via Digitalmars-d-learn wrote: > Hello! > I have some strange problem. I am trying to parse XML files and > extract some information from it. > I use library dxml for it by Jonathan M Davis. But I have a > probleme that I have multiple XML fil

Re: parallelism with delegate

2023-09-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, September 21, 2023 10:33:44 PM MDT Vitaliy Fadeev via Digitalmars-d-learn wrote: > On Friday, 22 September 2023 at 04:24:19 UTC, Vitaliy Fadeev > > wrote: > > ... > > Skip this thread. I see solution. > > How to delete missed posts on this forum ? This forum is esentially just a web

Re: std.file: read, readText and UTF-8 decoding

2023-09-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, September 22, 2023 12:28:39 AM MDT Uranuz via Digitalmars-d-learn wrote: > OK. Thanks for response. I wish that there it was some API to > handle it "out of the box". Do I need to write some issue or > something in order to not forget about this? You can open an issue if you want, thou

Re: Is it possible to create a kernel for an operating system in D?

2023-09-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, September 25, 2023 9:31:36 PM MDT I come from chill. via Digitalmars-d-learn wrote: > It seems very obvious, but I have not been able to find any > information on the subject to confirm this. So I'm wondering if > it's possible. > > ** Maybe I shouldn't have created the account, literal

Re: Straight Forward Arrays

2023-10-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 1, 2023 11:13:43 AM MDT dhs via Digitalmars-d-learn wrote: > On Sunday, 1 October 2023 at 13:27:37 UTC, Adam D Ruppe wrote: > > On Sunday, 1 October 2023 at 09:01:53 UTC, dhs wrote: > >> When D creates a dynamic array, it returns a slice. Functions > >> that add or remove element

Re: The difference between T[] opIndex() and T[] opSlice()

2023-10-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 1, 2023 11:51:17 AM MDT Salih Dincer via Digitalmars-d- learn wrote: > On Sunday, 1 October 2023 at 17:41:08 UTC, Salih Dincer wrote: > > Also, is it correct to use [] when returning? > > > > Thanks... > > [Here](https://dlang.org/spec/operatoroverloading.html#slice), > the opInd

Re: Type constraint

2023-10-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 3, 2023 8:35:31 AM MDT Joel via Digitalmars-d-learn wrote: > Oh, I found, > ```d > static if (isIntegral!T) > ``` > seems to work. Yeah. static if will compile in the code in that branch based on whether the condition is true, whereas if without the static will branch at runtim

Re: Type constraint

2023-10-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 3, 2023 7:46:42 PM MDT Joel via Digitalmars-d-learn wrote: > I think the if without static is still static, since it's part of > the function name part, or so (outside of the curly bracket > scope). if on a template (or on a templated function) is a template constraint, in whic

Re: array setting : Whats going in here?

2023-10-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, October 7, 2023 10:59:47 AM MDT claptrap via Digitalmars-d-learn wrote: > On Saturday, 7 October 2023 at 00:49:39 UTC, H. S. Teoh wrote: > > On Sat, Oct 07, 2023 at 12:00:48AM +, claptrap via > > Digitalmars-d-learn wrote: > > > > > > When you write `foo[]` you're taking a slice o

Re: how to assign multiple variables at once by unpacking array?

2023-10-07 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, October 7, 2023 1:31:45 AM MDT mw via Digitalmars-d-learn wrote: > https://stackoverflow.com/questions/47046850/is-there-any-way-to-assign-mult > iple-variable-at-once-with-dlang > > How to do this Python code in D: > > ``` > > >>> s = "1 2 3" > >>> A,B,C = map(int, s.split(" ")) > >>>

Re: array setting : Whats going in here?

2023-10-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 8, 2023 8:08:46 AM MDT Imperatorn via Digitalmars-d-learn wrote: > On Saturday, 7 October 2023 at 00:00:48 UTC, claptrap wrote: > > char[] foo; > > foo.length = 4; > > foo[] = 'a'; // ok sets all elements > > foo[] = "a"; // range error at runtime? > > foo[] = "ab"; // range err

Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?

2023-10-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, October 9, 2023 10:55:41 AM MDT rempas via Digitalmars-d-learn wrote: > On Monday, 9 October 2023 at 16:53:55 UTC, mw wrote: > > but you `import std.stdio;`? > > > > Or copy the std/conv.d over to your build, > > > > or copy / write a toString(int) function yourself, which is > > compil

Re: The Power of Grammar Checkers: A Game-Changer for Writers!

2023-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, October 12, 2023 2:19:20 AM MDT Imperatorn via Digitalmars-d- learn wrote: > On Thursday, 12 October 2023 at 06:08:43 UTC, charles reiley > > wrote: > > I hope you're all doing well in your writing endeavors! Today, > > I wanted to share my thoughts and experiences with grammar > > che

Re: dlang.org/spec/function.html#pure-functions example

2023-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, October 12, 2023 1:33:32 PM MDT Paul via Digitalmars-d-learn wrote: > The spec doc has the following statement and corresponding > example: > ***"Pure functions cannot directly access global or static > mutable state."*** > > ```d > int x; > immutable int y; > > pure int foo(int i) >

Re: dlang.org/spec/function.html#pure-functions example

2023-10-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, October 16, 2023 12:05:04 PM MDT Paul via Digitalmars-d-learn wrote: > On Thursday, 12 October 2023 at 21:20:44 UTC, Jonathan M Davis > > wrote: > > look like? > > > > Types can have static members. > > > > Basically what it comes down to is that outside of immutable > > data, pure f

Re: dlang.org/spec/function.html#pure-functions example

2023-10-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, October 16, 2023 12:05:04 PM MDT Paul via Digitalmars-d-learn wrote: > On Thursday, 12 October 2023 at 21:20:44 UTC, Jonathan M Davis > > wrote: > > look like? > > > > Types can have static members. > > > > Basically what it comes down to is that outside of immutable > > data, pure func

Re: bigEndian in std.bitmanip

2023-10-31 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 31, 2023 4:09:53 AM MDT Salih Dincer via Digitalmars-d- learn wrote: > Hello, > > Why isn't Endian.littleEndian the default setting for read() in > std.bitmanip? Why would you expect little endian to be the default? The typical thing to do when encoding integral values in a pla

Re: bigEndian in std.bitmanip

2023-10-31 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 31, 2023 8:23:28 AM MDT Salih Dincer via Digitalmars-d- learn wrote: > On Tuesday, 31 October 2023 at 10:24:56 UTC, Jonathan M Davis > > wrote: > > On Tuesday, October 31, 2023 4:09:53 AM MDT Salih Dincer via > > > > Digitalmars-d- learn wrote: > >> Hello, > >> > >> Why isn't En

Re: Keyword "package" prevents from importing a package module "package.d"

2023-11-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 2, 2023 7:04:37 AM MDT Adam D Ruppe via Digitalmars-d- learn wrote: > On Thursday, 2 November 2023 at 12:52:35 UTC, BoQsc wrote: > > Therefore the need to import `package.d` is needed and I can't > > see a solution, which means > > tbh package.d should never be used. It is a p

Re: Keyword "package" prevents from importing a package module "package.d"

2023-11-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, November 3, 2023 5:20:56 AM MDT Andrey Zherikov via Digitalmars-d- learn wrote: > On Friday, 3 November 2023 at 00:52:18 UTC, H. S. Teoh wrote: > > Supposedly you can do this: > > /* Original: */ > > > > // pkg/mymodule.d > > module mymodule; > > ... // code here > > > >

Re: Convert String to Date and Add ±N Hours

2023-11-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, November 4, 2023 12:11:53 PM MDT Vahid via Digitalmars-d-learn wrote: > Hi, > > I have a date string with the format of "2023-11-04 23:10:20". I > want to convert this string to Date object and also, add ±N hours > to it. For example: > > `"2023-11-04 23:10:20" + "+2:00" = "2023-11-05

Re: DUB: Is it possible to set release as a default build for a dub package?

2023-11-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, November 3, 2023 1:21:42 PM MDT BoQsc via Digitalmars-d-learn wrote: > While using `dub`, you might notice that after running `dub` or > `dub run` command you will end up with notice: > > ``` > Starting Performing "debug" build using > C:\D\dmd2\windows\bin64\dmd.exe for x86_64. > ``` >

Re: why remove octal literal support?

2023-11-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, November 5, 2023 9:59:22 PM MST d007 via Digitalmars-d-learn wrote: > On Friday, 3 November 2023 at 15:34:37 UTC, Steven Schveighoffer > > wrote: > > On Friday, 3 November 2023 at 15:07:41 UTC, d007 wrote: > >> dlang is know for compile speed, but in reality d project > >> compile slow

Re: How to do reflection on alias symbols

2023-11-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 16, 2023 3:03:25 AM MST Arafel via Digitalmars-d-learn wrote: > Hi all, > > Please consider the following currently non-working code: > > ```d > struct bar { > public alias pubInt = int; > private alias privInt = int; > } > > static foreach(member ; __traits(allMemb

Re: How to do reflection on alias symbols

2023-11-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 16, 2023 6:04:43 PM MST Jonathan M Davis via Digitalmars-d-learn wrote: > I would suggest that you open up a bug report for it - > https://issues.dlang.org - and certainly, there's a good argument that what > you're seeing here is a bug. I fully expe

Re: How to do reflection on alias symbols

2023-11-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, November 17, 2023 2:11:30 AM MST Arafel via Digitalmars-d-learn wrote: > I mean, in order to know if something is an `enum`, I need to do: > > ```d > enum isEnum(alias a) = is(typeof(a)) && !is(typeof(&a)); > ``` > > which feels like the wrong approach, and too much error-prone. I also

Re: How to write an interface but with different signatures

2023-11-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, November 19, 2023 1:13:16 AM MST Chris Katko via Digitalmars-d- learn wrote: > I know that sounds stupid on the face of it. An interface > shouldn't change. But consider this: > > A frame timer and a clock timer(seconds) that re-use > functionality from a parent class/interface. > > ```

Re: comparing with c strings

2023-11-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 23, 2023 11:29:09 AM MST denis via Digitalmars-d-learn wrote: > Let's say I have a D application, with some callbacks from C, > where some arguments to the callbacks are `const char* path`. > What is the recommended way to compare them to D strings? Without > making allocatio

Re: interface opEquals

2023-11-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 23, 2023 2:20:25 PM MST Antonio via Digitalmars-d-learn wrote: > * Why, when applied to interface, ```opEquals``` called directly > behavior is not the same that when calling ```==``` ? > > * Is it the expected behaviour? I'd have to take the time to study your code in deta

Re: D Phobos Library Documentation: What is the Internal API for?

2023-11-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, November 27, 2023 6:03:22 AM MST BoQsc via Digitalmars-d-learn wrote: > This is pretty basic question. > If you open [D Library > Reference](https://dlang.org/phobos/index.html) you are bound to > see the **Internal API** section in the table of content. > > What is the **Internal API**

Re: anonymous structs within structs

2023-12-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, December 4, 2023 11:26:07 AM MST DLearner via Digitalmars-d-learn wrote: > Suppose we need a construct like: > ``` > void main() { > > struct A { >int I1; >int I2; >char X; > } > > struct B { >A Dummy; >int Var1; >int Var2; >

Re: pegged: non@safe semantic actions

2023-12-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, December 8, 2023 10:13:21 AM MST Dmitry Ponyatov via Digitalmars-d- learn wrote: > What's wrong with using non@safe actions which creates and > modifies some external objects? > > ```D > class Layer { > int index; > string name; > this(int index, string name) { > > class S

Re: Checking path name

2023-12-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, December 14, 2023 12:33:36 PM MST cc via Digitalmars-d-learn wrote: > On Thursday, 14 December 2023 at 09:38:30 UTC, Joel wrote: > > On Thursday, 14 December 2023 at 08:47:49 UTC, Anonymouse wrote: > >> On Thursday, 14 December 2023 at 03:58:37 UTC, Joel wrote: > >> https://dlang.org/

Re: Synchronisation help

2024-01-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, January 1, 2024 8:48:16 AM MST Anonymouse via Digitalmars-d-learn wrote: > I have a `shared string[int]` AA that I access from two different > threads. The function I spawn to start the second thread takes > the AA as an argument. > > ```d > class Foo > { > shared string[int] bucke

Re: Synchronisation help

2024-01-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, January 2, 2024 4:39:12 AM MST Anonymouse via Digitalmars-d-learn wrote: > On Tuesday, 2 January 2024 at 11:05:33 UTC, user1234 wrote: > > Do not use `shared` AA. Use `__gshared` + sync primitives. > > `shared` AA will lead to all sort of bugs: > > > > - https://issues.dlang.org/show_b

Re: Synchronisation help

2024-01-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, January 2, 2024 3:41:55 AM MST Anonymouse via Digitalmars-d-learn wrote: > On Monday, 1 January 2024 at 19:49:28 UTC, Jonathan M Davis wrote: > > [...] > > Thank you. Yes, `Foo` is a class for the purposes of inheritance > -- I left that out of the example. > > So a completely valid so

Re: static array is not a range

2024-01-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, January 9, 2024 3:11:35 AM MST Alexibu via Digitalmars-d-learn wrote: > It looks like isInputRange is false for arrays with fixed length > by design. > > I can do: > > ```d > float[4] arr; > foreach(x;arr) > writefln("%s",x) > ``` > but not : > > ```d > arr.each!(a => a.writefln("%

Re: static array is not a range

2024-01-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, January 9, 2024 4:13:23 AM MST Alexibu via Digitalmars-d-learn wrote: > On Tuesday, 9 January 2024 at 10:44:34 UTC, Jonathan M Davis > > wrote: > > How would it even be possible for a static array to be a range? > > It has a fixed length. For a type to work as a range, it needs > > to

Re: static array is not a range

2024-01-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, January 9, 2024 6:22:24 AM MST bachmeier via Digitalmars-d-learn wrote: > On Tuesday, 9 January 2024 at 10:11:35 UTC, Alexibu wrote: > > It looks like isInputRange is false for arrays with fixed > > length by design. > > > > I can do: > > > > ```d > > float[4] arr; > > foreach(x;arr) >

Re: Would you recommend TDPL today?

2024-01-15 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, January 15, 2024 7:25:32 PM MST matheus via Digitalmars-d-learn wrote: > Hi, I'm mostly a lurker in these Forums but sometimes I post here > and there, my first language was C and I still use today together > with my own library (A Helper) which is like a poor version of > STB (https://

Re: Understanding the Use of Nested Import and Selective Import in D

2024-01-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, January 16, 2024 6:19:59 AM MST Orfeo via Digitalmars-d-learn wrote: > I found myself a bit perplexed when it comes to the usage of > "nested imports" and selective imports. It seems that prominent D > programmers have varied opinions on the matter. I would love to > hear your insights

Re: Understanding the Use of Nested Import and Selective Import in D

2024-01-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, January 16, 2024 1:42:04 PM MST bomat via Digitalmars-d-learn wrote: > Wow, that was... exhaustive. Thanks for that. :) > One more question that I have, though... > > On Tuesday, 16 January 2024 at 19:05:43 UTC, Jonathan M Davis > > wrote: > > The downside of course is that you then ha

Re: Understanding the Use of Nested Import and Selective Import in D

2024-01-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 17, 2024 7:03:18 AM MST Renato via Digitalmars-d-learn wrote: > My main reasoning is that D tools, surprisingly, cannot do > "Optimize Imports" (turns out that with all the metaprogramming > going on , it's impossible to tell for sure which imports are > being used - or so I

Re: length's type.

2024-01-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 17, 2024 7:55:37 PM MST zjh via Digitalmars-d-learn wrote: > Can you change the type of 'length' from 'ulong' to 'int', so I > haven't to convert it every time! If you mean for arrays, length and array indices are specifically size_t so that their size will match the pointer

Re: length's type.

2024-01-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 17, 2024 11:33:48 PM MST zjh via Digitalmars-d-learn wrote: > On Thursday, 18 January 2024 at 04:30:33 UTC, Jonathan M Davis > wrote: > but for a lot of code, using auto and size_t makes it > > > so that you don't need to use int, and it would be a big > > problem in general

Re: Datetime format?

2024-01-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, January 18, 2024 4:26:42 PM MST zoujiaqing via Digitalmars-d- learn wrote: > ```D > import std.datetime : Clock, format; > import std.stdio : writeln; > > void main() > { > auto currentTime = Clock.currTime; > > auto formattedTime = currentTime.format("%Y-%m-%d %H:%M:%S"); >

Re: Datetime format?

2024-01-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, January 18, 2024 4:58:32 PM MST zoujiaqing via Digitalmars-d- learn wrote: > On Thursday, 18 January 2024 at 23:43:13 UTC, Jonathan M Davis > > wrote: > > On Thursday, January 18, 2024 4:26:42 PM MST zoujiaqing via > > > > Digitalmars-d- learn wrote: > >> ```D > >> import std.datetime

Re: User defined type and foreach

2024-01-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, January 19, 2024 3:49:29 AM MST Jim Balter via Digitalmars-d-learn wrote: > On Friday, 17 November 2017 at 17:55:30 UTC, Jonathan M Davis > > wrote: > > When you have > > > > foreach(e; range) > > > > it gets lowered to something like > > > > for(auto r = range; !r.empty; r.popFront())

Re: Constructing arrays of structs

2024-01-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, January 23, 2024 12:32:31 PM MST Stephen Tashiro via Digitalmars- d-learn wrote: > On Tuesday, 23 January 2024 at 18:23:22 UTC, Renato wrote: > > This works , your mistake was to not actually assign the array > > to the class' field! > > > > Change this line: > > > > ```d > > auto array

Re: User defined type and foreach

2024-01-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, January 25, 2024 1:57:56 AM MST Jim Balter via Digitalmars-d- learn wrote: > The specification of ranges, which is independent of > the D language, says that the way to copy a range is to use > save(). I'm sorry, but you're misunderstanding the range specification if you think that sa

Re: The difference between the dates in years

2024-02-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, February 10, 2024 8:53:09 AM MST Alexander Zhirov via Digitalmars-d-learn wrote: > Is it possible to calculate the difference between dates in years > using regular means? Something like that > > > ``` > writeln(Date(1999, 3, 1).diffMonths(Date(1999, 1, 1))); > ``` > > At the same tim

  1   2   3   4   5   6   7   8   9   10   >