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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: Why does Nullable implicitly casts when assigning a variable but not when returning from a function?

2024-04-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, April 10, 2024 2:41:56 PM MDT Lettever via Digitalmars-d-learn wrote: > ``` > import std; > > Nullable!int func() => 3; > void main() { > Nullable!int a = 3; > //works fine > Nullable!int b = func(); > //does not compile > } Technically, no implicit conversion is

Re: Using core/sys/posix/mqueue.d on FreeBSD

2024-04-06 Thread Jonathan M Davis via Digitalmars-d-learn
Actually, since I'm usually the one who does the FreeBSD ones anyway, here you go: https://github.com/dlang/dmd/pull/16359 The declarations compile, and they should match the ones in C, since I copied them over and then tweaked them, but I haven't actually tested them. All that being said, even

Re: Using core/sys/posix/mqueue.d on FreeBSD

2024-04-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, April 6, 2024 3:57:46 AM MDT Arjan via Digitalmars-d-learn wrote: > I'm using posix mqueue in a D application on Linux. Works fine. > But on FreeBSD it fails to compile due to the version statement: > > [version (CRuntime_Glibc):]( > https://github.com/dlang/dmd/blob/0cfdd7a589fd34fdf9

Re: impure

2024-04-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, April 5, 2024 3:11:42 AM MDT Dom DiSc via Digitalmars-d-learn wrote: > On Sunday, 24 March 2024 at 09:16:20 UTC, Jonathan M Davis wrote: > > So, yes, you've run into a problem that it would be nice to > > have a better fix for, but even if we could negate attributes > > in general, ther

Re: How can I get an identifiquer of an usb or a harddisk? using C or Cpp or Dlang

2024-04-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, April 1, 2024 5:37:56 PM MDT dany via Digitalmars-d-learn wrote: > Actually I would get an ID's Usb That's going to depend on the operating system, and it's also going to depend on exactly what kind of ID you're looking for. - Jonathan M Davis

Re: How to make fields inaccessible (unreadable and unachangeable) outside of the structure?

2024-03-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, March 29, 2024 4:50:53 PM MDT curiousprogramma08 via Digitalmars-d- learn wrote: > ```d > struct QueueNode > { > > private int data; > private QueueNode *next = null; > > this(int data) > { > this.data = data; > } > } > ``` > I also tried to write it lik

Re: Setting up a final switch from a list

2024-03-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, March 28, 2024 4:21:03 PM MDT Salih Dincer via Digitalmars-d- learn wrote: > How can we add all members of an enum type to a list without > duplicating code? As the documentation for EnumMembers explains, you can use std.meta.NoDuplicates to strip out duplicates if you want to do some

Re: impure

2024-03-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 24, 2024 1:41:41 AM MDT Dom DiSc via Digitalmars-d-learn wrote: > I'm creating a library that is completely pure, but it doesn't > compile with pure: at the top because of one impure unittest > (which uses random to test some things only probabilistic)! > > So do I really need to

Re: Mutate immutable inside shared static constructor

2024-03-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, March 23, 2024 3:23:23 PM MDT Nick Treleaven via Digitalmars-d- learn wrote: > I've not used static constructors before, but it seems like the > following should not be allowed: > > ```d > import std.stdio; > > immutable int x; > > @safe shared static this() > { > x.writeln(); //

Re: Mutability issue

2024-03-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, March 23, 2024 1:30:29 PM MDT Menjanahary R. R. via Digitalmars- d-learn wrote: > The next code works as is but ... > > ``` > import std.stdio; > import std.traits; > > bool isPrime(T)(T n) if (isIntegral!T) { > if (n <= T(3)) return n > T(1); > > if (n % T(2) == T(0) || n %

Re: Implicit conversion of string to array of immutable ubytes

2024-03-22 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, March 23, 2024 12:11:15 AM MDT Per Nordlöw via Digitalmars-d- learn wrote: > Why doesn't string implicitly convert to immutable(ubyte)[] in > @safe mode? Why would it? They're different types. Their elements happen to have the same size, but that doesn't mean that they're used for the

Re: The std.file rename method fails in the docker environment.

2024-03-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 13, 2024 3:49:55 PM MDT zoujiaqing via Digitalmars-d-learn wrote: > On Wednesday, 13 March 2024 at 21:21:21 UTC, Jonathan M Davis > > wrote: > > On Wednesday, March 13, 2024 3:03:30 PM MDT zoujiaqing via > > > > Digitalmars-d-learn wrote: > >> upload file to server in docker, b

Re: The std.file rename method fails in the docker environment.

2024-03-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 13, 2024 3:03:30 PM MDT zoujiaqing via Digitalmars-d-learn wrote: > upload file to server in docker, but upload directory volume to > host machine. > > Exception error: > ``` > Invalid cross-device link > ``` > > Have other function like move(a, b) ? > > https://github.com/hunt

Re: static functions?

2024-03-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, March 11, 2024 10:51:48 AM MDT Andy Valencia via Digitalmars-d- learn wrote: > On Monday, 11 March 2024 at 16:25:13 UTC, Jonathan M Davis wrote: > > ... > > But what exactly static means varies based on the context. > > Thank you for the list! But none of those appear to apply to a > fu

Re: static functions?

2024-03-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, March 11, 2024 9:56:24 AM MDT Andy Valencia via Digitalmars-d-learn wrote: > Leveraging my knowledge of C, I assumed a "static" function would > be hidden outside of its own source file. I can't find any > statement about the semantics of a static function in the > documentation, and i

Re: chain of exceptions, next method

2024-03-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 6, 2024 6:06:34 AM MST kdevel via Digitalmars-d-learn wrote: > On Saturday, 10 September 2022 at 08:48:39 UTC, Andrej Mitrovic > > wrote: > > [...] > > I wish the compiler would rewrite scope(failure) to use chained > > exceptions. Otherwise any exceptions thrown within > > sco

Re: Are exceptions caught in unittests?

2024-02-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, February 16, 2024 1:06:26 AM MST Ferhat Kurtulmuş via Digitalmars- d-learn wrote: > On Friday, 16 February 2024 at 07:43:24 UTC, Ferhat Kurtulmuş > > wrote: > > When I tried to catch exceptions in my unit test, I found that > > exceptions were not thrown or caught in the unit test blocks

Re: what was the problem with the old post blit operator already ?

2024-02-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, February 14, 2024 7:17:15 PM MST Basile B. via Digitalmars-d- learn wrote: > From what I remember, it was that there was no reference to the > source. Things got blitted and you had to fix the copy, already > blitted. Was that the only issue ? There were probably some use cases wher

Re: std.string.assumeUTF() silently casting mutable to immutable?

2024-02-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 13, 2024 12:40:57 AM MST Forest via Digitalmars-d-learn wrote: > I may have found a bug in assumeUTF(), but being new to D, I'm > not sure. > > The description: > > Assume the given array of integers arr is a well-formed UTF > > string and return it typed as a UTF string. > >

Re: The difference between the dates in years

2024-02-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, February 10, 2024 7:31:47 PM MST Steven Schveighoffer via Digitalmars-d-learn wrote: > On Saturday, 10 February 2024 at 23:48:56 UTC, Jonathan M Davis > > wrote: > > If I understand correctly, he cares about how far into the > > month the dates > > are, whereas diffMonths ignores the

Re: The difference between the dates in years

2024-02-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, February 10, 2024 4:20:33 PM MST Steven Schveighoffer via Digitalmars-d-learn wrote: > On Saturday, 10 February 2024 at 15:53:09 UTC, Alexander Zhirov > > wrote: > > Is it possible to calculate the difference between dates in > > years using regular means? Something like that > > > >

Re: The difference between the dates in years

2024-02-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, February 10, 2024 3:11:48 PM MST Brad Roberts via Digitalmars-d- learn wrote: > Back when I was doing lots of software developer interviews, one of my > frequent questions involved date math. This wasn't because it's > difficult from a coding standpoint, but that it's NOT a coding pro

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

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: 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-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: 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: 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: 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: 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: 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: 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-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: 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: 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: 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 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: 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: 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-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: 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: 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: 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: 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: 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: 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: 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: 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 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-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: 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: 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: 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: 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: 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: 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: 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: 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: 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-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: 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: 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: 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 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-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: 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: 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: 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: 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: 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: 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: 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-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: 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: 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: 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: 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: 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: 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: 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

  1   2   3   4   5   6   7   8   9   10   >