Re: vibe.d: How to get the conent of a file upload ?

2020-09-20 Thread wjoe via Digitalmars-d-learn
On Sunday, 20 September 2020 at 00:36:30 UTC, Adam D. Ruppe wrote: [...] I browsed in your arsd docs a bit and I'll have a closer look at the CGI module a bit later. Your http2 module piqued my interest as it could come in handy some time later :) Looks like your modules cover everything I

How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread wjoe via Digitalmars-d-learn
I have some similar functions: void register(C: IFoo)() { _insert!C(); } void register(C)() if (behavesLikeFoo!C) { _insert!C(); } There are more overloads with parameters so I want to merge them void register(C, ARGS...)(ARGS args) if (behavesLikeFoo!C || isInstanceOf!(C, IFoo)) { _in

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread wjoe via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 18:50:28 UTC, H. S. Teoh wrote: Try this: interface I {} class C : I {} class D {} struct S {} pragma(msg, is(C : I)); // true pragma(msg, is(D : I)); // false pragma(msg, is(S : I)); // false So probabl

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread wjoe via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 18:49:28 UTC, data pulverizer wrote: On Wednesday, 23 September 2020 at 18:37:45 UTC, wjoe wrote: [...] A class at compile time is it's own static type, OOP polymorphism is a runtime feature not compile time. You have to write your own traits for specific o

Re: How can I test at compile time whether T is an instance of an interface ?

2020-09-23 Thread wjoe via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 19:08:47 UTC, data pulverizer wrote: On Wednesday, 23 September 2020 at 18:56:33 UTC, wjoe wrote: [...] Didn't think that the compiler didn't know but wasn't aware that you could use that information to statically dispatch. My mistake, I'll shut up now! A

Is it possible to set function attributes conditionally?

2021-06-04 Thread wjoe via Digitalmars-d-learn
Hi, Consider Allocators, e.g.: ```d struct Mallocator { enum usesGC = false; /// implement alloc, free, etc. @nogc } struct GCAllocator { enum usesGC = true; /// implement alloc, free, etc. via the GC } ``` Now I want to have the function attributes set depending on the allocator

Re: Is it possible to set function attributes conditionally?

2021-06-04 Thread wjoe via Digitalmars-d-learn
On Friday, 4 June 2021 at 11:36:09 UTC, Adam D. Ruppe wrote: On Friday, 4 June 2021 at 11:33:32 UTC, wjoe wrote: This is a contrived example. In reality I would use this with custom array, hash map and other container implementations so I could use them in @nogc territory by just switching out

Re: how to filter associative arrays with foreach ?

2021-06-21 Thread wjoe via Digitalmars-d-learn
On Monday, 21 June 2021 at 03:59:10 UTC, someone wrote: I often need to iterate through a filtered collection (associative array) as following: ```d string strComputerIDunwanted = "WS2"; /// associative array key to exclude foreach (strComputerID, udtComputer; udtComputers) { /// .remove!(a

Error with implicit cast of ^^=

2021-07-13 Thread wjoe via Digitalmars-d-learn
```D byte x = some_val; long y = some_val; x ^^= y; // Error: cannot implicitly convert expression pow(cast(long)cast(int)x, y) of type long to byte ``` Is there a way to do this via ^^= ? This is part of a unittest for opIndexOpAssign where the type of x is that of i.opIndex(_i). It's gene

Re: Error with implicit cast of ^^=

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Tuesday, 13 July 2021 at 15:14:26 UTC, Ali Çehreli wrote: On 7/13/21 4:12 AM, wjoe wrote: > ```D > byte x = some_val; > long y = some_val; > > x ^^= y; // Error: cannot implicitly convert expression > pow(cast(long)cast(int)x, y) of type long to byte [...] > I rewrote it to something like >

opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
I'm want to do something like this ```D part_int_t!(1,2,3) i; auto x = -i[0]; --i[1]; // 1 i[1]++; // 2 ``` I think the operator I need to overload would be opIndexUnary which I did. (1) compiles. (2) doesn't - the compiler complains that i.opIndex isn't an lvalue and can't be modified. The l

Re: catching segfault using try_ catch

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 00:10:59 UTC, seany wrote: On Tuesday, 13 July 2021 at 17:49:54 UTC, Adam D Ruppe wrote: On Tuesday, 13 July 2021 at 16:52:43 UTC, seany wrote: [...] true if it succeeded. [...] You mean transparently rerun some code? That's better done with the lowlevel sig

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 11:31:36 UTC, Tejas wrote: ``` {auto a = i[1] , ++i[1] , a} //note the , not the ;``` Sorry I can't provide something even more concrete. Yes I saw that, and I suppose it would work just fine if it were rewritten to just ```++i[1]```. What I'm struggling to und

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 12:49:58 UTC, Tejas wrote: I think it's a bug, because the following works: ```d import std.stdio; struct abc{ int[100] a; int opIndex(int index){ return a[index]; } int opIndexUnary(string s)(int index) if(s == "++"){ re

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 14:39:03 UTC, vit wrote: On Wednesday, 14 July 2021 at 13:16:49 UTC, Tejas wrote: On Wednesday, 14 July 2021 at 13:09:56 UTC, vit wrote: On Wednesday, 14 July 2021 at 12:49:58 UTC, Tejas wrote: [...] From doc: https://dlang.org/spec/operatoroverloading.html Post

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 14:50:01 UTC, Mike Parker wrote: On Wednesday, 14 July 2021 at 12:35:07 UTC, wjoe wrote: [...] It's how the contract of post-inc/dec work---pre-inc/dec return the modified value, post-inc/dec return the original value. [...] That makes a lot of sense now, tha

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 16:13:35 UTC, Tejas wrote: On Wednesday, 14 July 2021 at 15:08:56 UTC, wjoe wrote: On Wednesday, 14 July 2021 at 14:50:01 UTC, Mike Parker wrote: On Wednesday, 14 July 2021 at 12:35:07 UTC, wjoe wrote: [...] It's how the contract of post-inc/dec work---pre-inc/d

Re: opIndexUnary post in-/decrement how to ?

2021-07-15 Thread wjoe via Digitalmars-d-learn
On Thursday, 15 July 2021 at 04:01:15 UTC, Tejas wrote: I'm so sorry all this was basically useless for you. I can't spend more time on this, so as a last resort I leave you this: https://dlang.org/phobos/std_bitmanip.html This is the official bit manipulation standard library, maybe it wil

Re: opIndexUnary post in-/decrement how to ?

2021-07-15 Thread wjoe via Digitalmars-d-learn
On Thursday, 15 July 2021 at 04:07:49 UTC, Tejas wrote: Your code ```d auto x = i[1]++; ``` Expands to: ```d auto x = (auto e = i[1]/*notice opIndex*/, ++i[1]/* notice opIndexUnary*/, return e;); ``` This doesn't happen with pre increment. No compiler shenanigans. Interesting to see it spelt

Re: Error with implicit cast of ^^=

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

Re: opIndexUnary post in-/decrement how to ?

2021-07-15 Thread wjoe via Digitalmars-d-learn
On Thursday, 15 July 2021 at 12:09:20 UTC, Tejas wrote: [...] Oh yes, that is what happens. I was trying to be a little concise. You are correct, this is what the code will look in the gory details (I believe) : ```d auto x = (auto e = i.opIndex(1), i.opIndexUnary("++")(1)/*this may or may n

Re: opIndexUnary post in-/decrement how to ?

2021-07-16 Thread wjoe via Digitalmars-d-learn
On Thursday, 15 July 2021 at 15:39:59 UTC, Tejas wrote: On Thursday, 15 July 2021 at 13:28:19 UTC, wjoe wrote: On Thursday, 15 July 2021 at 12:09:20 UTC, Tejas wrote: [...] The only way, for me, to explain the error message ```opIndex isn't an lvalue and can't be modified.``` for ```i[1]++``

Generate docs for generated code?

2021-07-23 Thread wjoe via Digitalmars-d-learn
Is there a way for the compiler to consider doc comments in auto generated, mixed in code? E.g. ```D string fooImpl = q{ /// Bar does fancy things. const void bar() { /*do something fancy*/ } }; /// This is Foo struct Foo(A, B, C) { mixin(fooImpl); } ``` So that the documentation for ``

Re: Generate docs for generated code?

2021-07-23 Thread wjoe via Digitalmars-d-learn
On Friday, 23 July 2021 at 10:42:22 UTC, user1234 wrote: On Friday, 23 July 2021 at 10:04:55 UTC, wjoe wrote: Is there a way for the compiler to consider doc comments in auto generated, mixed in code? E.g. ```D string fooImpl = q{ /// Bar does fancy things. const void bar() { /*do somethi

Re: Generate docs for generated code?

2021-07-23 Thread wjoe via Digitalmars-d-learn
On Friday, 23 July 2021 at 10:54:33 UTC, Adam D Ruppe wrote: On Friday, 23 July 2021 at 10:04:55 UTC, wjoe wrote: Is there a way for the compiler to consider doc comments in auto generated, mixed in code? If you use my adrdox generator (which runs on the dpldocs.info website), it handles mixi

Conditional compilation: Which version identifier for release code ? version(assert) ?

2021-08-05 Thread wjoe via Digitalmars-d-learn
If it's to be determined whether or not the code is being compiled in debug or release mode, i.e. e.g. the dmd ```-release``` or ```-g``` options, which version identifier is supposed to be used ? There's no ```release``` identifier and ```-debug``` switch and ```debug()``` condition are some

Re: Conditional compilation: Which version identifier for release code ? version(assert) ?

2021-08-05 Thread wjoe via Digitalmars-d-learn
On Thursday, 5 August 2021 at 10:08:12 UTC, Mike Parker wrote: On Thursday, 5 August 2021 at 09:18:08 UTC, wjoe wrote: Given that we have `version(assert)` and `version(D_NoBoundsChecks)`, it probably makes sense to also have equivalents to test if contracts are enabled, or if bounds checking

Re: Conditional compilation: Which version identifier for release code ? version(assert) ?

2021-08-06 Thread wjoe via Digitalmars-d-learn
On Thursday, 5 August 2021 at 11:01:56 UTC, Adam D Ruppe wrote: On Thursday, 5 August 2021 at 09:18:08 UTC, wjoe wrote: If it's to be determined whether or not the code is being compiled in debug or release mode, i.e. e.g. the dmd ```-release``` You should never use the -release flag. It shou

Re: Conditional compilation: Which version identifier for release code ? version(assert) ?

2021-08-06 Thread wjoe via Digitalmars-d-learn
On Thursday, 5 August 2021 at 11:54:38 UTC, Mike Parker wrote: On Thursday, 5 August 2021 at 10:43:01 UTC, wjoe wrote: Could you elaborate on ```version(assert)``` a bit more, please ? Like I compiled with ```-release, -g``` and without the 2 options but the ```assert``` branch was always t

Re: Nondeterministic unittest debugging problem.

2021-08-16 Thread wjoe via Digitalmars-d-learn
On Sunday, 15 August 2021 at 10:32:27 UTC, Rekel wrote: Note you might need to open the screenshots externally, as they are cut off by the forum. This looks like your build system fails to detect file changes and links outdated .o file(s), or library, which causes a mismatch between your debu

Re: What is the point of nothrow?

2018-06-13 Thread wjoe via Digitalmars-d-learn
On Wednesday, 13 June 2018 at 12:59:27 UTC, Kagamin wrote: On Wednesday, 13 June 2018 at 02:02:54 UTC, wjoe wrote: it is possible to install a signal handler for almost every signal on POSIX, including segfault. The only signal you can't catch is signal 9 - sigkill if memory serves. So I could

Re: What is the point of nothrow?

2018-06-13 Thread wjoe via Digitalmars-d-learn
On Wednesday, 13 June 2018 at 13:05:44 UTC, Kagamin wrote: On Wednesday, 13 June 2018 at 10:56:41 UTC, wjoe wrote: I understand the idea that an Error is not supposed to be caught but why would such a 'feature' be desirable? Where's the benefit if nothing can be relied upon ? It's a debugging

Re: What is the point of nothrow?

2018-06-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 13 June 2018 at 20:08:06 UTC, Jonathan M Davis wrote: On Wednesday, June 13, 2018 10:56:41 wjoe via Digitalmars-d-learn wrote: On Wednesday, 13 June 2018 at 03:14:33 UTC, Jonathan M Davis > regardless of whether the decision to treat failed memory > allocations as an Error

Re: What is the point of nothrow?

2018-06-15 Thread wjoe via Digitalmars-d-learn
On Thursday, 14 June 2018 at 22:27:42 UTC, bauss wrote: On Thursday, 14 June 2018 at 19:06:07 UTC, Jonathan M Davis wrote: So in case of a thrown Error, you can catch it and log it to a database. No, you can't. Once the Error was thrown the program is in invalid state and you can't assume t

Re: What is the point of nothrow?

2018-06-15 Thread wjoe via Digitalmars-d-learn
On Friday, 15 June 2018 at 08:13:44 UTC, Kagamin wrote: On Wednesday, 13 June 2018 at 17:08:26 UTC, wjoe wrote: My question was more like what's the benefit of having thrown Errors corrupt your program state rendering it useless for debugging ? D allows various levels of performance and safe

Re: What is the point of nothrow?

2018-06-15 Thread wjoe via Digitalmars-d-learn
On Friday, 15 June 2018 at 17:27:13 UTC, bauss wrote: On Friday, 15 June 2018 at 17:25:18 UTC, wjoe wrote: On Thursday, 14 June 2018 at 22:27:42 UTC, bauss wrote: On Thursday, 14 June 2018 at 19:06:07 UTC, Jonathan M Davis wrote: So in case of a thrown Error, you can catch it and log it to a d

Re: What is the point of nothrow?

2018-06-16 Thread wjoe via Digitalmars-d-learn
On Thursday, 14 June 2018 at 19:06:07 UTC, Jonathan M Davis wrote: On Thursday, June 14, 2018 18:11:20 wjoe via Digitalmars-d-learn wrote: On Wednesday, 13 June 2018 at 20:08:06 UTC, Jonathan M Davis wrote: > On Wednesday, June 13, 2018 10:56:41 wjoe via > The idea is that because your p

Re: What is the point of nothrow?

2018-06-18 Thread wjoe via Digitalmars-d-learn
On Saturday, 16 June 2018 at 21:25:01 UTC, Jonathan M Davis wrote: On Saturday, June 16, 2018 18:45:53 wjoe via Digitalmars-d-learn wrote: What you said earlier: On Monday, 11 June 2018 at 00:47:27 UTC, Jonathan M Davis wrote: > [...] > > 2. If the compiler knows that a function ca

Re: What is the point of nothrow?

2018-06-19 Thread wjoe via Digitalmars-d-learn
On Monday, 18 June 2018 at 20:23:48 UTC, Jonathan M Davis wrote: On Monday, June 18, 2018 15:22:48 wjoe via Digitalmars-d-learn wrote: On Saturday, 16 June 2018 at 21:25:01 UTC, Jonathan M Davis wrote: > every feature that you can't use in betterC is considered a > loss, and effort

Re: What is the point of nothrow?

2018-06-19 Thread wjoe via Digitalmars-d-learn
On Tuesday, 19 June 2018 at 12:26:15 UTC, Kagamin wrote: On Friday, 15 June 2018 at 17:46:02 UTC, wjoe wrote: D allows various levels of performance and safety. Though I'd say Errors not working in debug mode is not intended, the Intention matters not. By definition all program state is inval

Re: What is the point of nothrow?

2018-06-21 Thread wjoe via Digitalmars-d-learn
On Wednesday, 20 June 2018 at 12:22:33 UTC, Kagamin wrote: On Tuesday, 19 June 2018 at 15:03:49 UTC, wjoe wrote: But maybe I missed something else and the only purpose of D is to make console applications for *NIX like OSs and expect users to be professional enough to save that stack trace bef

Re: What is the point of nothrow?

2018-06-23 Thread wjoe via Digitalmars-d-learn
On Thursday, 21 June 2018 at 19:52:25 UTC, Jonathan M Davis wrote: On Thursday, June 21, 2018 13:16:28 wjoe via Digitalmars-d-learn wrote: On Wednesday, 20 June 2018 at 12:22:33 UTC, Kagamin wrote: > Do you know how to extract information from it on an > unfamiliar OS? Reading stack tr

DUB conditional subPackage possible?

2019-04-11 Thread wjoe via Digitalmars-d-learn
I want to include subPackages depending either on the presence of command line options, or the availability of dependencies; think Gentoo USE flags. As far as I can tell it's not possible to specify configurations in a modular way, e.g. dub --config=withGUI --config=supportGTK --config=sup

Re: What Does @ Mean?

2019-04-12 Thread wjoe via Digitalmars-d-learn
On Monday, 8 April 2019 at 12:16:13 UTC, Adam D. Ruppe wrote: On Monday, 8 April 2019 at 11:58:49 UTC, Ron Tarrant wrote: And while I'm asking, does an underscore have special meaning when used either at the beginning or end of a variable name? Nothing special there, you are allowed to use the

Re: [windows] Can't delete a closed file?

2019-05-10 Thread wjoe via Digitalmars-d-learn
On Thursday, 9 May 2019 at 10:09:23 UTC, Cym13 wrote: Hi, this is likely not related to D itself but hopefully someone can help me with this since I'm rather new to windows programming, I mainly work on linux. I'm trying to bundle a DLL in a binary, write it in a temp folder, use it and remov

Re: 1 - 17 ms, 553 ╬╝s, and 1 hnsec

2019-05-27 Thread wjoe via Digitalmars-d-learn
On Thursday, 16 May 2019 at 15:52:05 UTC, Steven Schveighoffer wrote: On 5/16/19 4:27 PM, Vladimir Panteleev wrote: On Thursday, 16 May 2019 at 15:19:03 UTC, Alex wrote: What's an hnsec anyways? Hecto-nano-second, the smallest representable unit of time in SysTime and Duration. The outpu

Re: Setting default values for Main function's args Array

2019-06-27 Thread wjoe via Digitalmars-d-learn
On Thursday, 27 June 2019 at 17:05:05 UTC, Vaidas wrote: Is it possible to set the default values for the Main function's arguments? It seems that I'm getting Range error. import std.stdio : writeln; void main(string[] args = ["asdsfasdf", "asdklfajsdk", "asdfasdfasd"]){ writeln("", args

can DDOC generate files names including the full path ?

2019-08-14 Thread wjoe via Digitalmars-d-learn
For example if the source tree looks like this: source/ foo/ baz.d bar/ baz.d and generating the docs with something like this: dmd -D -Dd=docs foo/baz.d bar/baz.d the output looks like this: docs/ baz.html one baz overwrites the other. I'd like to have something like th

Re: Desktop app with vibe.d

2019-08-14 Thread wjoe via Digitalmars-d-learn
On Monday, 12 August 2019 at 10:41:57 UTC, GreatSam4sure wrote: Pls I want to know if it is possible to build desktop app with vibe.d just like nodejs. I am not satisfy with the GUI of Dlang such as dlangui and gtkd. I don't think they have good styling capabilities like HTML and CSS. I will

Re: Abstract classes vs interfaces, casting from void*

2019-08-14 Thread wjoe via Digitalmars-d-learn
On Saturday, 10 August 2019 at 08:20:46 UTC, John Colvin wrote: On Friday, 9 August 2019 at 13:39:53 UTC, Simen Kjærås wrote: Thanks for the extra detail. Is there a solid reason to ever use an interface over an abstract class? (Other than multiple inheritance). I'm such a noob at anythin

Re: can DDOC generate files names including the full path ?

2019-08-19 Thread wjoe via Digitalmars-d-learn
On Monday, 19 August 2019 at 04:23:48 UTC, Jonathan M Davis wrote: [...] Thanks for the explanation. I'm in quite a dilemma now as I can't decide on which to choose :)

Re: MobI? Really?

2021-09-22 Thread wjoe via Digitalmars-d-learn
On Tuesday, 21 September 2021 at 16:14:52 UTC, Chris_D wrote: Thanks for the replies. jfondren: Sorry, but I am talking about documentation. For me, online web pages don't qualify; they are in the cloud, unreal, with no substance. Does anyone really read 300 pages online, in a web browser?

toString and code coverage...

2021-09-22 Thread wjoe via Digitalmars-d-learn
Is there a convenient way to exclude it from coverage ? Because adjusting the -cov=xx percentage is kind of annoying and may omit other things as well. Do you care and if yes how do you handle it ?

Re: toString and code coverage...

2021-09-22 Thread wjoe via Digitalmars-d-learn
On Wednesday, 22 September 2021 at 18:59:11 UTC, user1234 wrote: [...] I'd use option 2. Thanks, I'll do just that :)

Re: Why sometimes stacktraces are printed and sometimes not?

2021-09-30 Thread wjoe via Digitalmars-d-learn
On Wednesday, 29 September 2021 at 12:15:30 UTC, Steven Schveighoffer wrote: On 9/29/21 6:57 AM, JN wrote: What makes the difference on whether a crash stacktrace gets printed or not? Sometimes I get a nice clean stacktrace with line numbers, sometimes all I get is "segmentation fault error -

Code coverage exit code 1 on failure?

2021-09-30 Thread wjoe via Digitalmars-d-learn
What's the reasoning behind picking exit code 1 ? Makes it pretty much impossible to distinguish between a lack of coverage code 1 and a process code 1. Is there a handler where it can be overridden ?

What does dual-context mean?

2022-03-01 Thread wjoe via Digitalmars-d-learn
Hello, what's a dual context as in the deprecation message? ```d struct MockFile { [...] void writef(alias fmt, A...)(A args) { // Deprecation: function 'writef': function requires a dual-context, which is deprecated import std.format: format; write(format!fmt(args)); } [...]

Re: What does dual-context mean?

2022-03-02 Thread wjoe via Digitalmars-d-learn
On Tuesday, 1 March 2022 at 17:58:24 UTC, Paul Backus wrote: On Tuesday, 1 March 2022 at 14:51:47 UTC, wjoe wrote: Hello, what's a dual context as in the deprecation message? It means you have a struct or class member function that accesses its calling context via a template alias parameter.

Re: Importing version identifiers from another file?

2022-04-11 Thread wjoe via Digitalmars-d-learn
On Monday, 11 April 2022 at 08:57:12 UTC, KytoDragon wrote: [...] Sadly this results in an identifier conflict, as the version set in config.d does not seem to affect library.d. Is there any way to import version specifiers from a separate file? I don't want to pollute the users build files (d

Re: Why do immutable variables need reference counting?

2022-04-11 Thread wjoe via Digitalmars-d-learn
On Monday, 11 April 2022 at 03:24:11 UTC, Ali Çehreli wrote: On 4/10/22 20:05, norm wrote: > On Sunday, 10 April 2022 at 23:19:47 UTC, rikki cattermole wrote: > In my mind immutable data > means the data will not change and neither will the result of reading > that data, ever. Yes. > I don't g

Re: Why do immutable variables need reference counting?

2022-04-12 Thread wjoe via Digitalmars-d-learn
On Monday, 11 April 2022 at 22:10:07 UTC, Ali Çehreli wrote: On 4/11/22 05:57, wjoe wrote: > And because the data could be > in ROM any modification is an error. Fully agreed. However, how could I initialize such an object then? (You may have meant a read-only memory page instead of ROM.)

Re: Why do immutable variables need reference counting?

2022-04-14 Thread wjoe via Digitalmars-d-learn
On Tuesday, 12 April 2022 at 22:23:18 UTC, ag0aep6g wrote: On Tuesday, 12 April 2022 at 19:54:13 UTC, wjoe wrote: Especially since it's only a promise and the compiler accepts this: void foo (const(char)[] arr) { cast(char[])arr[0..3] = "baz"; } string bar = "123"; foo(bar); assert(bar=="baz

Re: Why do immutable variables need reference counting?

2022-04-14 Thread wjoe via Digitalmars-d-learn
On Tuesday, 12 April 2022 at 23:23:59 UTC, Ali Çehreli wrote: [...] Looking at this from a technical perspective - everything you say is true - and thanks for clearing up some of my confusion in that department. Looking at this from a natural language (English) perspective - words prompt i

Re: Why do immutable variables need reference counting?

2022-04-17 Thread wjoe via Digitalmars-d-learn
On Thursday, 14 April 2022 at 12:10:04 UTC, ag0aep6g wrote: On 14.04.22 13:42, wjoe wrote: Undefined behavior yes, but regardless the example proves it can be done in @system code. A few versions ago, possibly due to a bug or regression, the compiler didn't complain in @safe code either. Of c

Re: Why do immutable variables need reference counting?

2022-04-18 Thread wjoe via Digitalmars-d-learn
On Sunday, 17 April 2022 at 14:14:37 UTC, H. S. Teoh wrote: Not entirely true. See paragraph 3 in: https://dlang.org/spec/unittest.html and 10.24.11.3 in: https://dlang.org/spec/expression.html#assert_expressions T Thanks. Either I missed that the last time I checked or it

How are delegate attributes in fn signature inferred?

2022-05-23 Thread wjoe via Digitalmars-d-learn
Hello, Consider this example: ```d module foo; import std.stdio; import std.algorithm; import std.traits; import std.range; void print(R)(R r) { static assert(isIterable!R); r.each!writeln; } auto construct(R)(R r, ElementType!R delegate(ulong i) fn) { static assert(isIterable!R && hasAs

Re: How are delegate attributes in fn signature inferred?

2022-05-23 Thread wjoe via Digitalmars-d-learn
On Monday, 23 May 2022 at 13:53:02 UTC, Adam D Ruppe wrote: On Monday, 23 May 2022 at 13:44:53 UTC, wjoe wrote: [...] You can actually make this work with `construct!(int[])` rather than plain `construct`. This is a (really annoying) deficiency in dmd's implementation. (that sdc solved btw

Cannot copy void[] to void[] in @safe code?

2022-07-08 Thread wjoe via Digitalmars-d-learn
Why is that ? My understanding is that a void[] doesn't have a distinct type but since the length is bytes and not elements this makes me believe that under the hood they are byte arrays - or, rather, managed chunks of memory. How's copying memory without a distinct type different from copying

Re: Unwrap variadic template into vararg of pointers of the same types

2022-07-08 Thread wjoe via Digitalmars-d-learn
On Friday, 8 July 2022 at 12:20:13 UTC, ryuukk_ wrote: I'm not sure how to phrase it so it'll try with code I have this piece of code that i would like to improve, right now i have to create bunch of duplicates ```D void view_it(A, B)(void function(entity_t, A*, B*) cb) { fore

Re: Unwrap variadic template into vararg of pointers of the same types

2022-07-08 Thread wjoe via Digitalmars-d-learn
Corrections: On Friday, 8 July 2022 at 12:40:52 UTC, wjoe wrote: alias Recurse = AliasSeq!(Arg[0]*, Recurse!(Arg[0..$]); ```d alias Recurse = AliasSeq!(Arg[0]*, Recurse!(Arg[1..$]); ``` void view_it(Args...)(void function(entity_t, Includes!(Args) ) ```d void view_it(Args..

Re: Cannot copy void[] to void[] in @safe code?

2022-07-08 Thread wjoe via Digitalmars-d-learn
On Friday, 8 July 2022 at 12:26:03 UTC, ag0aep6g wrote: You're allowed to copy from `ubyte[]` to `ubyte[]`. But you're not allowed to copy from `ubyte[]` to `int*[]`, because reinterpreting a bunch of bytes as pointers is not safe. The thing about `void[]` is that it can point to memory that

toString doesn't compile with -dip1000 switch

2022-08-01 Thread wjoe via Digitalmars-d-learn
struct Foo() { import std.format: FormatSpec; const void toString( scope void delegate(const(char)[]) @safe sink, FormatSpec!char fmt) {} } struct Bar { import std.format: FormatSpec; const void toString( scope void delegate(const(char)[]) @safe sink, FormatSpec!char fmt

Re: toString doesn't compile with -dip1000 switch

2022-08-01 Thread wjoe via Digitalmars-d-learn
On Monday, 1 August 2022 at 13:09:01 UTC, Kagamin wrote: Bar.toString is typed `@system`. Even if I'd declare everything @safe: at module scope?

Re: toString doesn't compile with -dip1000 switch

2022-08-01 Thread wjoe via Digitalmars-d-learn
On Monday, 1 August 2022 at 17:07:43 UTC, wjoe wrote: On Monday, 1 August 2022 at 13:09:01 UTC, Kagamin wrote: Bar.toString is typed `@system`. Even if I'd declare everything @safe: at module scope? I wrote that on my phone and it got a bit messy... ``` D module x; @safe: struct Foo() {

Re: Code compiles and run fine with LDC but segfault with DMD

2022-08-30 Thread wjoe via Digitalmars-d-learn
On Monday, 29 August 2022 at 21:46:48 UTC, ryuukk_ wrote: What `-g` does that makes this code compile and work with DMD? This flag adds symbolic debug info. But I'm confident you knew that already.

Re: Forked GC explained

2022-09-03 Thread wjoe via Digitalmars-d-learn
On Saturday, 3 September 2022 at 13:35:39 UTC, frame wrote: I'm not sure I fully understand how it works. I know that the OS creates read only memory pages for both and if a memory section is about to be written, the OS will issue a copy of the pages so any write operation will be done in it's

Re: Detect uninitialized class var access

2022-09-26 Thread wjoe via Digitalmars-d-learn
On Sunday, 25 September 2022 at 02:10:00 UTC, Salih Dincer wrote: On Saturday, 24 September 2022 at 13:17:19 UTC, rassoc wrote: Recently I refactored some old code of mine, now utilizing classes instead structs, and I got hit by an uninitialized variable access pattern similar to the simplified

Re: Detect uninitialized class var access

2022-09-26 Thread wjoe via Digitalmars-d-learn
On Monday, 26 September 2022 at 16:51:11 UTC, rikki cattermole wrote: Currently in D you would be forced to create a vtable struct manually. Or I could just use classes. The cure shouldn't be worse than the disease. But if we had something like signatures you could do this: ```d struct Foo {

Re: Why are globals set to tls by default? and why is fast code ugly by default?

2023-03-27 Thread wjoe via Digitalmars-d-learn
On Sunday, 26 March 2023 at 18:07:03 UTC, ryuukk_ wrote: It should be the opposite Slow code ugly Fast code beautiful What's fast today may not be fast tomorrow but the language might still be relevant. e.g.: It used to be faster to ... - pre-calculate sin/cos tables, now the memory look

<    1   2