UDAs on function calls or return locations?

2021-06-14 Thread Mike Brown via Digitalmars-d-learn
Hi all, Is it possible to add a UDA onto either the function call, and detect its present? or onto the variable that the result will go to? E.g. auto int x = function() @UDA; int function() { if (hasUDA(call_site)) { ... } } or @UDA int y = function(); int function() {

Predicates Within Strings

2021-06-14 Thread Justin Choi via Digitalmars-d-learn
Could somebody explain or point me to documentation that helps to explain the usage of strings in predicates? My main question is how D infers the omitted variable specifications given otherwise - for example: `filter!(a => a < 3)(arr);` and `filter!"a < 3"(arr);` produce the same result.

Re: Financial Library

2021-06-14 Thread WebFreak001 via Digitalmars-d-learn
On Sunday, 13 June 2021 at 12:46:29 UTC, Financial Wiz wrote: What are some of the best Financial Libraries for D? I would like to be able to aggregate as much accurate information as possible. Thanks. if you want a type-safe money handling type, try https://code.dlang.org/packages/money

Re: cannot take address of scope local in safe function

2021-06-14 Thread ag0aep6g via Digitalmars-d-learn
On 13.06.21 19:49, vit wrote: Is possible create and use scope output range allocated on stack in @safe code? Example: ```d //-dip1000     struct OutputRange{     private bool valid = true;     private void* ptr;     int count = 0;     void put(Val)(auto ref scope Val

cast to pure function stop work after upgrade

2021-06-14 Thread baby_tiger via Digitalmars-d-learn
this used work for me, after upgrade I get this error. how to fix it ? import std.traits; enum LogLevel : ubyte { INFO = 0, WARN, ERROR, FATAL, } extern (C) string

Re: Wrote a Protobuf-like D (de)serialisation library - asking for comments / suggestions

2021-06-14 Thread Sinisa Susnjar via Digitalmars-d-learn
On Sunday, 13 June 2021 at 00:18:56 UTC, Ali Çehreli wrote: - If a struct contains all bitwise copyable members, instead of (de)serializing each member individually, the whole struct can by memcpy'ed. This may be a performance gain especially for arrays of structs: You can memcpy the whole

Re: Wrote a Protobuf-like D (de)serialisation library - asking for comments / suggestions

2021-06-14 Thread Sinisa Susnjar via Digitalmars-d-learn
On Monday, 14 June 2021 at 07:14:27 UTC, Imperatorn wrote: Is it on dub? published it just now :)

Re: Unpacking Slices

2021-06-14 Thread Vladimir Panteleev via Digitalmars-d-learn
On Monday, 14 June 2021 at 18:08:27 UTC, Justin Choi wrote: Is there any shortcut for unpacking slices like I'd want to do in a scenario like this? `info = readln.strip.split;` `string a = info[0], b = info[1], c = info[2];` I tried to implement PHP's "list" language construct here, which

Dynamically allocated Array mutable but non resizeable

2021-06-14 Thread Jalil David Salamé Messina via Digitalmars-d-learn
I'm searching for a way to do something like this in D: ```cpp struct MyStruct { const size_t length; int *const data; MyStruct(size_t n) : length(n) { data = new int[length]; } } ``` This way it is mutable, but non resizeable: ```cpp MyStruct s = MyStruct(10); s.data[0] = 42;

Re: Unpacking Slices

2021-06-14 Thread Ali Çehreli via Digitalmars-d-learn
On 6/14/21 11:08 AM, Justin Choi wrote: Is there any shortcut for unpacking slices like I'd want to do in a scenario like this? `info = readln.strip.split;` `string a = info[0], b = info[1], c = info[2];` D does not have automatic unpacking. Here is a quick, dirty, and fun experiment:

Re: Dynamically allocated Array mutable but non resizeable

2021-06-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/14/21 11:09 AM, Jalil David Salamé Messina wrote: I'm searching for a way to do something like this in D: ```cpp struct MyStruct {   const size_t length;   int *const data;   MyStruct(size_t n) : length(n) {     data = new int[length];   } } ``` This way it is mutable, but non

Re: Predicates Within Strings

2021-06-14 Thread jfondren via Digitalmars-d-learn
On Monday, 14 June 2021 at 15:01:01 UTC, Justin Choi wrote: Could somebody explain or point me to documentation that helps to explain the usage of strings in predicates? My main question is how D infers the omitted variable specifications given otherwise - for example: `filter!(a => a <

Unpacking Slices

2021-06-14 Thread Justin Choi via Digitalmars-d-learn
Is there any shortcut for unpacking slices like I'd want to do in a scenario like this? `info = readln.strip.split;` `string a = info[0], b = info[1], c = info[2];`

Re: Unpacking Slices

2021-06-14 Thread jfondren via Digitalmars-d-learn
On Monday, 14 June 2021 at 18:08:27 UTC, Justin Choi wrote: Is there any shortcut for unpacking slices like I'd want to do in a scenario like this? `info = readln.strip.split;` `string a = info[0], b = info[1], c = info[2];` This doesn't leave you with multiple local variables, but it leaves

Re: In general, who should do more work: popFront or front?

2021-06-14 Thread mw via Digitalmars-d-learn
On Tuesday, 15 June 2021 at 04:24:09 UTC, surlymoor wrote: All my custom range types perform all their meaningful work in their respective popFront methods, in addition to its expected source data iteration duties. The reason I do this is because I swear I read in a github discussion that

Re: In general, who should do more work: popFront or front?

2021-06-14 Thread surlymoor via Digitalmars-d-learn
On Tuesday, 15 June 2021 at 04:43:38 UTC, jfondren wrote: Well, consider this program: ```d import std; struct Noisy { int[] source; int pops, fronts; bool empty() { return source.empty; } void popFront() { writeln("popFront #", ++pops); source.popFront; } int front() {

Re: In general, who should do more work: popFront or front?

2021-06-14 Thread mw via Digitalmars-d-learn
On Tuesday, 15 June 2021 at 05:03:45 UTC, surlymoor wrote: On Tuesday, 15 June 2021 at 04:57:45 UTC, mw wrote: In English, `front` is a noun, `popFront` have a verb in it, so you know who should do more work :-) Sure, but, for example, the front method of Phobos' MapResult is the one

Re: In general, who should do more work: popFront or front?

2021-06-14 Thread surlymoor via Digitalmars-d-learn
On Tuesday, 15 June 2021 at 04:57:45 UTC, mw wrote: In English, `front` is a noun, `popFront` have a verb in it, so you know who should do more work :-) Sure, but, for example, the front method of Phobos' MapResult is the one applying the predicate to the source's front. There's a clear

In general, who should do more work: popFront or front?

2021-06-14 Thread surlymoor via Digitalmars-d-learn
All my custom range types perform all their meaningful work in their respective popFront methods, in addition to its expected source data iteration duties. The reason I do this is because I swear I read in a github discussion that front is expected to be O(1), and the only way I can think to

Re: In general, who should do more work: popFront or front?

2021-06-14 Thread surlymoor via Digitalmars-d-learn
On Tuesday, 15 June 2021 at 05:17:06 UTC, mw wrote: I think there is another convention (although it's not formally enforced, but should be) is: -- `obj.front() [should be] const`, i.e. it shouldn't modify `obj`, so can be called multiple times at any given state, and produce the same result

Re: In general, who should do more work: popFront or front?

2021-06-14 Thread ag0aep6g via Digitalmars-d-learn
On 15.06.21 07:17, mw wrote: https://dlang.org/library/std/range/primitives/front.html the 2nd decl: dchar front(T) (   scope const(T)[] a ) pure @property @safe if (isAutodecodableString!(T[])); you can see `const` but https://dlang.org/library/std/range/primitives/pop_front.html void

Re: In general, who should do more work: popFront or front?

2021-06-14 Thread jfondren via Digitalmars-d-learn
On Tuesday, 15 June 2021 at 04:24:09 UTC, surlymoor wrote: All my custom range types perform all their meaningful work in their respective popFront methods, in addition to its expected source data iteration duties. The reason I do this is because I swear I read in a github discussion that

Re: Financial Library

2021-06-14 Thread Financial Wiz via Digitalmars-d-learn
On Sunday, 13 June 2021 at 22:32:16 UTC, Bastiaan Veelo wrote: On Sunday, 13 June 2021 at 12:46:29 UTC, Financial Wiz wrote: What are some of the best Financial Libraries for D? I would like to be able to aggregate as much accurate information as possible. Thanks. I am not into financials,

Re: Financial Library

2021-06-14 Thread mw via Digitalmars-d-learn
On Monday, 14 June 2021 at 06:47:01 UTC, Financial Wiz wrote: Ok, what I'm talking about by Financial library is mainly aggregating data in to D from sources that provide them such as yahoo or google so I can do what I want with the data. http/ftp client library, inspired by python-requests

Re: Wrote a Protobuf-like D (de)serialisation library - asking for comments / suggestions

2021-06-14 Thread Imperatorn via Digitalmars-d-learn
On Saturday, 12 June 2021 at 21:59:13 UTC, Sinisa Susnjar wrote: Hi, D newbie here, The library is on par with Google Protobuf performance-wise and does not need a pre-compiler like Protobuf does, but instead uses the meta programming facilities of D to (de)serialise D data types from/to