Platinum Oval Rings: Pure Luxury & Sparkle

2025-05-27 Thread Kristen Mitchell via Digitalmars-d-learn
a timeless piece that speaks of enduring commitment and style, platinum is pure perfection.

Re: How to fake pure

2025-04-08 Thread Dom DiSc via Digitalmars-d-learn
On Tuesday, 8 April 2025 at 15:54:52 UTC, Timon Gehr wrote: In any case, casting a memory allocator to `pure` should be fine. Any reasonable definition of `pure` we can come up with in the future would be compatible with that. Yes, this is also what I think. Of course an allocator cannot be

Re: How to fake pure

2025-04-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, April 8, 2025 9:07:45 AM MDT Guillaume Piolat via Digitalmars-d-learn wrote: > On Tuesday, 8 April 2025 at 14:00:56 UTC, Jonathan M Davis wrote: > > Of course, I'm also increasingly of the opinion that pure was a > > mistake in general, because it does almost

Re: How to fake pure

2025-04-08 Thread Timon Gehr via Digitalmars-d-learn
On 4/8/25 17:07, Guillaume Piolat wrote: On Tuesday, 8 April 2025 at 14:00:56 UTC, Jonathan M Davis wrote: Of course, I'm also increasingly of the opinion that pure was a mistake in general, because it does almost nothing in practice but routinely doesn't work with straightforward

Re: How to fake pure

2025-04-08 Thread Guillaume Piolat via Digitalmars-d-learn
On Tuesday, 8 April 2025 at 14:00:56 UTC, Jonathan M Davis wrote: Of course, I'm also increasingly of the opinion that pure was a mistake in general, because it does almost nothing in practice but routinely doesn't work with straightforward code - and it's definitely one of t

Re: How to fake pure

2025-04-08 Thread Dom DiSc via Digitalmars-d-learn
On Tuesday, 8 April 2025 at 14:00:56 UTC, Jonathan M Davis wrote: You basically have to lie to the compiler and cast the function pointer to pure [...]. That being said, core.memory has pureMalloc and pureFree which do that for you already, including mucking around with errno to ensure

Re: How to fake pure

2025-04-08 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, April 8, 2025 5:28:57 AM MDT Dom DiSc via Digitalmars-d-learn wrote: > Hi. > > I want to create my own allocator, but using malloc is not pure > (it internally has to have some "global state"). But the GC also > has this "global state" and still is

How to fake pure

2025-04-08 Thread Dom DiSc via Digitalmars-d-learn
Hi. I want to create my own allocator, but using malloc is not pure (it internally has to have some "global state"). But the GC also has this "global state" and still is considered "pure". So internally the impurity of the allocators has been hidden. How

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

2023-10-28 Thread Nick Treleaven via Digitalmars-d-learn
On Monday, 16 October 2023 at 18:05:04 UTC, Paul 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 functions only have access to their arguments and

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 t

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 t

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

2023-10-16 Thread Paul via Digitalmars-d-learn
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 functions only have access to their arguments and to what they can access via their arguments (be it by

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

2023-10-16 Thread Paul via Digitalmars-d-learn
On Thursday, 12 October 2023 at 21:20:44 UTC, Jonathan M Davis wrote: Thanks Jonathan

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

2023-10-13 Thread Nick Treleaven via Digitalmars-d-learn
On Thursday, 12 October 2023 at 19:33:32 UTC, Paul wrote: If **int x** is global mutable state, what does static mutable state look like? In addition to Jonathan's reply, see: https://dlang.org/spec/function.html#local-static-variables

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; > immut

Re: Why is GC.collect `pure`

2023-08-02 Thread Jonathan M Davis via Digitalmars-d-learn
ring why those functions are marked `pure` - they > >> must affect the GC's bookkeeping state. > > I guess it was because the GC's internal state is not supposed to > be observable outside internal GC functions. I find it harder to > accept some of those than `GC.malloc` b

Re: Why is GC.collect `pure`

2023-08-02 Thread Nick Treleaven via Digitalmars-d-learn
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` - they must affect the GC's bookkeeping state. I guess it was because the GC's intern

Re: Why is GC.collect `pure`

2023-08-02 Thread Nick Treleaven via Digitalmars-d-learn
On Wednesday, 2 August 2023 at 17:52:00 UTC, Nick Treleaven wrote: Now I'm wondering why those functions are marked `pure` - they must affect the GC's bookkeeping state. Here's the pull that added it: https://github.com/dlang/druntime/pull/3561

Re: Pure D frontend as library.

2022-12-27 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 27 December 2022 at 12:22:45 UTC, Johan wrote: does semantic analysis (create AST; note that there is a ton of calls needed to complete SeMa), and finally outputs object code. If you want to capitalize the word use SemA. ;)

Re: Pure D frontend as library.

2022-12-27 Thread Johan via Digitalmars-d-learn
On Monday, 26 December 2022 at 19:13:01 UTC, Alexandru Ermicioi wrote: Hi team, I'd like to ask a lazy question: How easy is to use D compiler frontend without backend? How complicated would be to write a transpiler, and from which files should you start modifications? I'm wondering if somet

Re: Pure D frontend as library.

2022-12-27 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 27/12/2022 9:34 PM, Alexandru Ermicioi wrote: Any idea from which file should I start at least learning about this glue code? You can look at dmd's... but realistically the work hasn't been done at that level to make it easy to work with. https://github.com/dlang/dmd/blob/master/compiler/

Re: Pure D frontend as library.

2022-12-27 Thread Alexandru Ermicioi via Digitalmars-d-learn
On Monday, 26 December 2022 at 23:08:59 UTC, Richard (Rikki) Andrew Cattermole wrote: ... That on the other hand... Yeah, things aren't great on that front. The thing you want to implement is what we call glue code and isn't really setup right now for this (nobody has tried like this, ignorin

Re: Pure D frontend as library.

2022-12-26 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 27/12/2022 8:13 AM, Alexandru Ermicioi wrote: How easy is to use D compiler frontend without backend? Easy. https://github.com/dlang/dmd/blob/master/compiler/test/dub_package/frontend.d How complicated would be to write a transpiler, and from which files should you start modifications?

Pure D frontend as library.

2022-12-26 Thread Alexandru Ermicioi via Digitalmars-d-learn
Hi team, I'd like to ask a lazy question: How easy is to use D compiler frontend without backend? How complicated would be to write a transpiler, and from which files should you start modifications? I'm wondering if something like https://typescripttolua.github.io/ could be done, but with d

Re: how to benchmark pure functions?

2022-10-29 Thread max haughton via Digitalmars-d-learn
out } } void f2() { foreach(i; 0..4_000_000) { // defeat optimizations asm @safe pure nothrow @nogc {} } } auto r = benchmark!(f0, f1, f2)(1); writeln(r[0]); // 4 μs writeln(r[1]); // 4 μs writeln(r[2]); // 1 ms

Re: how to benchmark pure functions?

2022-10-28 Thread Siarhei Siamashka via Digitalmars-d-learn
On Friday, 28 October 2022 at 09:48:14 UTC, ab wrote: Thanks to H.S. Teoh and Dennis for the suggestions, they both work. I like the empty asm block a bit more because it is less invasive, but it only works with ldc. I used the volatileLoad/volatileStore functions to ensure that the compiler

Re: how to benchmark pure functions?

2022-10-28 Thread Imperatorn via Digitalmars-d-learn
On Friday, 28 October 2022 at 09:48:14 UTC, ab wrote: On Thursday, 27 October 2022 at 17:17:01 UTC, ab wrote: [...] Thanks to H.S. Teoh and Dennis for the suggestions, they both work. I like the empty asm block a bit more because it is less invasive, but it only works with ldc. @Imperatorn

Re: how to benchmark pure functions?

2022-10-28 Thread ab via Digitalmars-d-learn
On Thursday, 27 October 2022 at 17:17:01 UTC, ab wrote: Hi, when trying to compare different implementations of the optimized builds of a pure function using benchmark from std.datetime.stopwatch, I get times equal to zero, I suppose because the functions are not executed as they do not have

Re: how to benchmark pure functions?

2022-10-27 Thread Dennis via Digitalmars-d-learn
..4_000_000) { // defeat optimizations asm @safe pure nothrow @nogc {} } } auto r = benchmark!(f0, f1, f2)(1); writeln(r[0]); // 4 μs writeln(r[1]); // 4 μs writeln(r[2]); // 1 ms } ```

Re: how to benchmark pure functions?

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

Re: how to benchmark pure functions?

2022-10-27 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 27 October 2022 at 17:17:01 UTC, ab wrote: Hi, when trying to compare different implementations of the optimized builds of a pure function using benchmark from std.datetime.stopwatch, I get times equal to zero, I suppose because the functions are not executed as they do not have

how to benchmark pure functions?

2022-10-27 Thread ab via Digitalmars-d-learn
Hi, when trying to compare different implementations of the optimized builds of a pure function using benchmark from std.datetime.stopwatch, I get times equal to zero, I suppose because the functions are not executed as they do not have side effects. The same happens with the example from

Re: What is pure used for?

2021-11-25 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 25 November 2021 at 07:26:48 UTC, sclytrack wrote: int * pureFunction() 1) the pointer needs to be the same. 2) the value that the pointer points to needs to be the same. I call this the "value of interest" with relation to pure. The pointer doesn't matter. 3) b

Re: What is pure used for?

2021-11-25 Thread zjh via Digitalmars-d-learn
On Thursday, 25 November 2021 at 07:26:48 UTC, sclytrack wrote: My understanding is that pure is used for compiler optimization in loops and expressions. It leaves out multiple calls if it figures out it is not needed. [one link](https://klickverbot.at/blog/2012/05/purity-in-d

Re: What is pure used for?

2021-11-25 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 25 November 2021 at 07:26:48 UTC, sclytrack wrote: My understanding is that pure is used for compiler optimization in loops and expressions. It leaves out multiple calls if it figures out it is not needed. Is pure used for anything else? int * pureFunction() 1) the pointer

What is pure used for?

2021-11-24 Thread sclytrack via Digitalmars-d-learn
My understanding is that pure is used for compiler optimization in loops and expressions. It leaves out multiple calls if it figures out it is not needed. Is pure used for anything else? int * pureFunction() 1) the pointer needs to be the same. 2) the value that the pointer points to needs

Re: cast to pure function stop work after upgrade

2021-08-02 Thread Tejas via Digitalmars-d-learn
On Monday, 2 August 2021 at 15:10:06 UTC, vit wrote: On Monday, 2 August 2021 at 11:28:46 UTC, Tejas wrote: [...] Try this: ```d void main(){ fp = cast(typeof(fp))&VFORMAT; //fails } ``` Agh, stupid me. You the man!!

Re: cast to pure function stop work after upgrade

2021-08-02 Thread vit via Digitalmars-d-learn
p;Fn))) { enum N = __traits(identifier, Fn); enum string asPure = "private alias " ~ N ~ "_PURE = " ~ typeof(&Fn).stringof ~ " pure;\n" ~ "__gshared immutable " ~ N ~ "_PURE " ~ P ~"= cast(" ~ N ~ "_PURE) &" ~ N ~ &

Re: cast to pure function stop work after upgrade

2021-08-02 Thread vit via Digitalmars-d-learn
null; } extern (C) string function(LogLevel level, string file, size_t line, char[] tmp, bool line_break, string tag, string fmt, ...) @nogc nothrow pure fp; void main(){ fp = &VFORMAT; //fails } ``` Try this: ```d void main(){ fp = cast(typeof(fp))&VFORMAT; //fails } ```

Re: cast to pure function stop work after upgrade

2021-08-02 Thread Tejas via Digitalmars-d-learn
p;Fn))) { enum N = __traits(identifier, Fn); enum string asPure = "private alias " ~ N ~ "_PURE = " ~ typeof(&Fn).stringof ~ " pure;\n" ~ "__gshared immutable " ~ N ~ "_PURE " ~ P ~"= cast(" ~ N ~ "_PURE) &" ~ N ~ &

cast to pure function stop work after upgrade

2021-06-14 Thread baby_tiger via Digitalmars-d-learn
ring asPure = "private alias " ~ N ~ "_PURE = " ~ typeof(&Fn).stringof ~ " pure;\n" ~ "__gshared immutable " ~ N ~ "_PURE " ~ P ~"= cast(" ~ N ~ "_PURE) &" ~ N ~ " ;" ; } enum xx = asPure!("VFORMATP&

Re: GC.addRange in pure function

2021-02-12 Thread Petar via Digitalmars-d-learn
On Friday, 12 February 2021 at 12:17:13 UTC, Per Nordlöw wrote: On Tuesday, 9 February 2021 at 03:05:10 UTC, frame wrote: On Sunday, 7 February 2021 at 14:13:18 UTC, vitamin wrote: Why using 'new' is allowed in pure functions but calling GC.addRange or GC.removeRange isn't a

Re: GC.addRange in pure function

2021-02-12 Thread Petar via Digitalmars-d-learn
for you :P [...] Thanks, Yes, I am implementing container (ref counted pointer). When allcoator is Mallcoator (pure allocate and deallocate) and constructor of Type inside rc pointer has pure constructor and destructor, then only impure calls was GC.addRange and GC.removeRange. Now there are mark

Re: GC.addRange in pure function

2021-02-12 Thread vitamin via Digitalmars-d-learn
ef counted pointer). When allcoator is Mallcoator (pure allocate and deallocate) and constructor of Type inside rc pointer has pure constructor and destructor, then only impure calls was GC.addRange and GC.removeRange. Now there are marked as pure.

Re: GC.addRange in pure function

2021-02-12 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 9 February 2021 at 03:05:10 UTC, frame wrote: On Sunday, 7 February 2021 at 14:13:18 UTC, vitamin wrote: Why using 'new' is allowed in pure functions but calling GC.addRange or GC.removeRange isn't allowed? Would making `new T[]` inject a call to `GC.addRange` ba

Re: GC.addRange in pure function

2021-02-10 Thread Petar via Digitalmars-d-learn
calls in Array.~this() can be marked as `pure`, as the Array type as a whole implements the RAII design pattern and offers at least basic exception-safety guarantees: https://github.com/dlang/phobos/blob/81a968dee68728f7ea245b6983eb7236fb3b2981/std/container/array.d#L296-L298 (The whole function

Re: GC.addRange in pure function

2021-02-10 Thread Petar via Digitalmars-d-learn
On Wednesday, 10 February 2021 at 13:44:53 UTC, vit wrote: On Wednesday, 10 February 2021 at 12:17:43 UTC, rm wrote: On 09/02/2021 5:05, frame wrote: On Sunday, 7 February 2021 at 14:13:18 UTC, vitamin wrote: Why using 'new' is allowed in pure functions but calling GC.a

Re: GC.addRange in pure function

2021-02-10 Thread vit via Digitalmars-d-learn
On Wednesday, 10 February 2021 at 12:17:43 UTC, rm wrote: On 09/02/2021 5:05, frame wrote: On Sunday, 7 February 2021 at 14:13:18 UTC, vitamin wrote: Why using 'new' is allowed in pure functions but calling GC.addRange or GC.removeRange isn't allowed? Does 'new' vi

Re: GC.addRange in pure function

2021-02-10 Thread rm via Digitalmars-d-learn
On 09/02/2021 5:05, frame wrote: On Sunday, 7 February 2021 at 14:13:18 UTC, vitamin wrote: Why using 'new' is allowed in pure functions but calling GC.addRange or GC.removeRange isn't allowed? Does 'new' violate the 'pure' paradigm? Pure function

Re: GC.addRange in pure function

2021-02-10 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 9 February 2021 at 21:00:39 UTC, Paul Backus wrote: On Tuesday, 9 February 2021 at 19:53:27 UTC, Temtaime wrote: pure is broken. Just don't [use it] Allowing memory allocation in pure code in a language that can distinguish between pointer equality and value equality is,

Re: GC.addRange in pure function

2021-02-09 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 9 February 2021 at 20:50:12 UTC, Max Haughton wrote: On Tuesday, 9 February 2021 at 19:53:27 UTC, Temtaime wrote: On Sunday, 7 February 2021 at 14:13:18 UTC, vitamin wrote: Why using 'new' is allowed in pure functions but calling GC.addRange or GC.removeRange isn't

Re: GC.addRange in pure function

2021-02-09 Thread Max Haughton via Digitalmars-d-learn
On Tuesday, 9 February 2021 at 19:53:27 UTC, Temtaime wrote: On Sunday, 7 February 2021 at 14:13:18 UTC, vitamin wrote: Why using 'new' is allowed in pure functions but calling GC.addRange or GC.removeRange isn't allowed? pure is broken. Just don't [use it] [Citation needed]

Re: GC.addRange in pure function

2021-02-09 Thread Temtaime via Digitalmars-d-learn
On Sunday, 7 February 2021 at 14:13:18 UTC, vitamin wrote: Why using 'new' is allowed in pure functions but calling GC.addRange or GC.removeRange isn't allowed? pure is broken. Just don't [use it]

Re: GC.addRange in pure function

2021-02-08 Thread frame via Digitalmars-d-learn
On Sunday, 7 February 2021 at 14:13:18 UTC, vitamin wrote: Why using 'new' is allowed in pure functions but calling GC.addRange or GC.removeRange isn't allowed? Does 'new' violate the 'pure' paradigm? Pure functions can only call pure functions and GC

GC.addRange in pure function

2021-02-07 Thread vitamin via Digitalmars-d-learn
Why using 'new' is allowed in pure functions but calling GC.addRange or GC.removeRange isn't allowed?

Re: Escape this in pure members

2020-09-23 Thread ag0aep6g via Digitalmars-d-learn
On 23.09.20 02:06, DlangUser38 wrote: The following analysis might be wrong but I think that `scope` as a **member** function attribute is not supposed to be used as that is not even documented. It's documented here: https://dlang.org/spec/memory-safe-d.html#scope-return-params Quote: "[`scop

Re: Escape this in pure members

2020-09-23 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 23 September 2020 at 00:06:38 UTC, DlangUser38 wrote: Hmm, why would `b` have longer lifetime? Isn't the lifetime of `b` throughout `bar`? The following analysis might be wrong but I think that `scope` as a **member** function attribute is not supposed to be used as that is not

Re: Escape this in pure members

2020-09-22 Thread DlangUser38 via Digitalmars-d-learn
into other parameters without the `scope` qualifier? This class Bar {     void bar(scope Bar b) @safe pure     {     b = this;     } } compiles but this class Bar {     scope void bar(scope Bar b) @safe pure     {     b = this; // Error: scope variable `this` assigned to `b

Re: Escape this in pure members

2020-09-22 Thread Jacob Carlborg via Digitalmars-d-learn
Bar {     void bar(scope Bar b) @safe pure     {     b = this;     } } compiles but this class Bar {     scope void bar(scope Bar b) @safe pure     {     b = this; // Error: scope variable `this` assigned to `b` with longer lifetime     } } Hmm, why would `b` have longer lifetime

Re: Escape this in pure members

2020-09-19 Thread Per Nordlöw via Digitalmars-d-learn
On Saturday, 19 September 2020 at 18:48:31 UTC, Jacob Carlborg wrote: A nested class seems to be able to escape the `this` reference: Ahh, thanks. I just realized that it can escape into other parameters without the `scope` qualifier? This class Bar { void bar(scope Bar b) @safe pure

Re: Escape this in pure members

2020-09-19 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-09-19 18:07, Per Nordlöw wrote: If an aggregate member is pure but not scope when can it escape the `this` pointer?. Only via return? I'm not sure if returning the `this` pointer is considered escaping it. The caller already had access to it. Under the hood, the `this` pointe

Re: Escape this in pure members

2020-09-19 Thread Per Nordlöw via Digitalmars-d-learn
On Saturday, 19 September 2020 at 16:07:24 UTC, Per Nordlöw wrote: If an aggregate member is pure but not scope when can it escape the `this` pointer?. Or rather when and, if so, how can the member allow its `this` pointer to escape? It seems to me like the `scope` qualifier is no effect in

Escape this in pure members

2020-09-19 Thread Per Nordlöw via Digitalmars-d-learn
If an aggregate member is pure but not scope when can it escape the `this` pointer?. Only via return? In the struct and class case?

Re: variant visit not pure?

2020-05-08 Thread Dukc via Digitalmars-d-learn
On Thursday, 7 May 2020 at 20:12:03 UTC, learner wrote: Modules of D standard library aren't in a good shape, if everyone suggests alternatives for a basic building block as variant. I don't think Variant as a whole is the problem, when one uses it as the infinite variant it does fairly muc

Re: variant visit not pure?

2020-05-08 Thread Dukc via Digitalmars-d-learn
On Thursday, 7 May 2020 at 15:36:36 UTC, Ben Jones wrote: I've been using SumType... What are the main differences between it and TaggedAlgebraic? I have not used the the algebraic type of Taggedalgebraic tbh, but it also has a tagged union type that I have good experiences with. Unlike Phobo

Re: variant visit not pure?

2020-05-08 Thread Dukc via Digitalmars-d-learn
On Thursday, 7 May 2020 at 10:21:26 UTC, Dukc wrote: that's the reason why `std.range.enumerate` does not infer attributes for example This was wrong. `enumerate` can infer. It's `lockstep` that cannot.

Re: variant visit not pure?

2020-05-07 Thread learner via Digitalmars-d-learn
On Thursday, 7 May 2020 at 14:53:10 UTC, Steven Schveighoffer wrote: On 5/7/20 5:22 AM, learner wrote: [...] Because VariantN (the base of Algebraic) can literally hold anything, it cannot be pure, @safe, nothrow, @nogc. As others have recommended, I suggest using TaggedAlgebraic. I

Re: variant visit not pure?

2020-05-07 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 7 May 2020 at 15:36:36 UTC, Ben Jones wrote: On Thursday, 7 May 2020 at 14:53:10 UTC, Steven Schveighoffer wrote: As others have recommended, I suggest using TaggedAlgebraic. I recently have been using it to create an algebraic type to hold a MYSQL value, so I can migrate the mys

Re: variant visit not pure?

2020-05-07 Thread Ben Jones via Digitalmars-d-learn
On Thursday, 7 May 2020 at 14:53:10 UTC, Steven Schveighoffer wrote: As others have recommended, I suggest using TaggedAlgebraic. I recently have been using it to create an algebraic type to hold a MYSQL value, so I can migrate the mysql-native library to be @safe (mysql-native currently uses

Re: variant visit not pure?

2020-05-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/7/20 5:22 AM, learner wrote: Good morning, Is there a reason why std.variant.visit is not inferring pure? ``` void test() pure {     Algebraic!(int, string) alg;     visit!( (string) => 0, (int) => 0)(alg); } Error: pure function test cannot call impure function test.visit!(Va

Re: variant visit not pure?

2020-05-07 Thread Dukc via Digitalmars-d-learn
On Thursday, 7 May 2020 at 13:17:21 UTC, learner wrote: I've find this: https://issues.dlang.org/show_bug.cgi?id=16662 Hmm, that explains why it can't infer attributes. An unlimited variant could contain an object, and using it might or might not be . Of course, it could still infer the att

Re: variant visit not pure?

2020-05-07 Thread learner via Digitalmars-d-learn
On Thursday, 7 May 2020 at 10:41:01 UTC, Simen Kjærås wrote: On Thursday, 7 May 2020 at 09:22:28 UTC, learner wrote: Good morning, Is there a reason why std.variant.visit is not inferring pure? ``` void test() pure { Algebraic!(int, string) alg; visit!( (string) => 0, (int) =>

Re: variant visit not pure?

2020-05-07 Thread Simen Kjærås via Digitalmars-d-learn
On Thursday, 7 May 2020 at 09:22:28 UTC, learner wrote: Good morning, Is there a reason why std.variant.visit is not inferring pure? ``` void test() pure { Algebraic!(int, string) alg; visit!( (string) => 0, (int) => 0)(alg); } Error: pure function test cannot call impure fu

Re: variant visit not pure?

2020-05-07 Thread Dukc via Digitalmars-d-learn
On Thursday, 7 May 2020 at 09:22:28 UTC, learner wrote: Good morning, Is there a reason why std.variant.visit is not inferring pure? I think `variant` will not infer any trributes. I'm not sure why. It could be some language limitation (that's the reason why `std.range.enumerate

variant visit not pure?

2020-05-07 Thread learner via Digitalmars-d-learn
Good morning, Is there a reason why std.variant.visit is not inferring pure? ``` void test() pure { Algebraic!(int, string) alg; visit!( (string) => 0, (int) => 0)(alg); } Error: pure function test cannot call impure function test.visit!(VariantN!(16LU, int, string)).visit ```

Re: Map, filter and pure functions

2019-11-29 Thread Paul Backus via Digitalmars-d-learn
On Friday, 29 November 2019 at 15:54:13 UTC, realhet wrote: On Friday, 29 November 2019 at 15:49:24 UTC, Paul Backus wrote: It's actually a much simpler reason: filter calls .front twice for each element in its input (once to check if the value satisfies the predicate, and then again to return

Re: Map, filter and pure functions

2019-11-29 Thread realhet via Digitalmars-d-learn
On Friday, 29 November 2019 at 15:49:24 UTC, Paul Backus wrote: It's actually a much simpler reason: filter calls .front twice for each element in its input (once to check if the value satisfies the predicate, and then again to return the value if it does), and the range returned by map doesn't

Re: Map, filter and pure functions

2019-11-29 Thread realhet via Digitalmars-d-learn
On Friday, 29 November 2019 at 15:30:22 UTC, realhet wrote: ... Unfortunately function purity is not the answer. I put a very long calculation into the transform function which is called from "map!". And the "filter!" is making the "map!" call my function 2 times: First for the "filter!" to

Re: Map, filter and pure functions

2019-11-29 Thread Paul Backus via Digitalmars-d-learn
remove the filter! it does only one transform function call per element. Is this because the function is NOT PURE, so Phobos thinks that the function can give different results for the same input? If I modify the function to be pure, will the transform function be called only once? It&#

Map, filter and pure functions

2019-11-29 Thread realhet via Digitalmars-d-learn
per element. Is this because the function is NOT PURE, so Phobos thinks that the function can give different results for the same input? If I modify the function to be pure, will the transform function be called only once?

Why is this pure function taking a string literal not CTFE-executable?

2019-06-01 Thread Simon via Digitalmars-d-learn
Hi Guys! In my programm, I have a custom String-type that I want to initialize some variables of at compile time by casting a string literal to said custom String type. I thought I could achieve this straight forwardly, but after trying a bit, I could not find a (simple) working solution. I m

Re: Why is my @pure function @system when placed in a struct?

2019-02-27 Thread ag0aep6g via Digitalmars-d-learn
On 27.02.19 19:10, Dukc wrote: I tested a bit, and it appears that attribute inference is not done at all for templates inside structs -the attribute need not be a delegate: struct S     {     static int fImpl(Ret)() { return Ret.init; }     pragma(msg, __traits(getFunctionAttribute

Re: Why is my @pure function @system when placed in a struct?

2019-02-27 Thread Dukc via Digitalmars-d-learn
On Wednesday, 27 February 2019 at 17:23:21 UTC, Q. Schroll wrote: For whatever reason, when I put the code in a struct, the @safe testing line tells me, it's @system now. I tested a bit, and it appears that attribute inference is not done at all for templates inside structs -the attribute need

Re: Why is my @pure function @system when placed in a struct?

2019-02-27 Thread Dukc via Digitalmars-d-learn
On Wednesday, 27 February 2019 at 18:06:49 UTC, Stefan Koch wrote: the struct gets drawn into your delegate-context. and I guess that taints the function. Even if it did, it should not make the delegate @system. And it does not, since this manifest with static functions and function pointer

Re: Why is my @pure function @system when placed in a struct?

2019-02-27 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 27 February 2019 at 17:23:21 UTC, Q. Schroll wrote: I have a template function `fImpl` I whish to instantiate manually using the new name `f`. Reason is simple: `f` should not be a template, but overloading it makes it easier that way. Nothing's more simple in D: [...] the stru

Why is my @pure function @system when placed in a struct?

2019-02-27 Thread Q. Schroll via Digitalmars-d-learn
I have a template function `fImpl` I whish to instantiate manually using the new name `f`. Reason is simple: `f` should not be a template, but overloading it makes it easier that way. Nothing's more simple in D: int fImpl(T)(T value) { return cast(int) value; } alias f = fImpl!int;

Re: Pure opEquals in a class

2018-08-20 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 20 August 2018 at 19:36:15 UTC, werter wrote: The code below doesn't work. Is it possible to make a pure opEquals in a class? [...] pure bool opEquals(const A rhs) const { return b == rhs.b; } It do

Pure opEquals in a class

2018-08-20 Thread werter via Digitalmars-d-learn
The code below doesn't work. Is it possible to make a pure opEquals in a class? void main() { class A { bool a; int b; this(bool g, int h) { a = g;

Re: float/double to string (pure nothrow @nogc)

2018-08-08 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 17:08:57 UTC, vit wrote: Hello, is in phobos some function which convert float/double to string and is pure @nogc and nothrow? Short answer: no. Long answer: https://issues.dlang.org/show_bug.cgi?id=17628

Re: float/double to string (pure nothrow @nogc)

2018-08-08 Thread ketmar via Digitalmars-d-learn
vit wrote: thanks, that code can be modified to pure nothrow @nogc @safe. Is that lib ok? Is little complicated... converting float to string is a *very* complicated task. that lib is quite small for what it is doing ('cause it hacks around some... interesting cases). the *real* thing

Re: float/double to string (pure nothrow @nogc)

2018-08-08 Thread vit via Digitalmars-d-learn
On Wednesday, 8 August 2018 at 17:40:11 UTC, ketmar wrote: vit wrote: Hello, is in phobos some function which convert float/double to string and is pure @nogc and nothrow? i don't think that you can make it `pure`, but you certainly can make it `nothrow`, `@nogc` and ctfe-able.

Re: float/double to string (pure nothrow @nogc)

2018-08-08 Thread ketmar via Digitalmars-d-learn
vit wrote: Hello, is in phobos some function which convert float/double to string and is pure @nogc and nothrow? i don't think that you can make it `pure`, but you certainly can make it `nothrow`, `@nogc` and ctfe-able. it's dangerous to go alone! take this[0]. [0] http://

Re: float/double to string (pure nothrow @nogc)

2018-08-08 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/8/18 1:08 PM, vit wrote: Hello, is in phobos some function which convert float/double to string and is pure @nogc and nothrow? Not one that I can see. formattedWrite doesn't seem to be pure. -Steve

float/double to string (pure nothrow @nogc)

2018-08-08 Thread vit via Digitalmars-d-learn
Hello, is in phobos some function which convert float/double to string and is pure @nogc and nothrow?

Re: Implicit conversion of struct with methods to immutable in pure function fails

2018-07-19 Thread Timoses via Digitalmars-d-learn
On Thursday, 19 July 2018 at 06:35:36 UTC, Simen Kjærås wrote: On Wednesday, 18 July 2018 at 11:28:54 UTC, Timoses wrote: But why is a context pointer a problem? Is it problematic because the context pointer to the main scope can not guarantee `immutable`? E.g. if I happened to use data from m

Re: Implicit conversion of struct with methods to immutable in pure function fails

2018-07-18 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 18 July 2018 at 11:28:54 UTC, Timoses wrote: But why is a context pointer a problem? Is it problematic because the context pointer to the main scope can not guarantee `immutable`? E.g. if I happened to use data from main in a function of the immutable struct then... well then what

Re: Implicit conversion of struct with methods to immutable in pure function fails

2018-07-18 Thread Timoses via Digitalmars-d-learn
On Tuesday, 17 July 2018 at 06:24:12 UTC, Simen Kjærås wrote: That makes sense. The problem is F has a context pointer to the main() block, since it's a non-static struct with methods inside a block. It doesn't actually use the context pointer for anything, so it possibly shouldn't have one,

Re: Implicit conversion of struct with methods to immutable in pure function fails

2018-07-16 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 16 July 2018 at 13:13:53 UTC, Timoses wrote: On Monday, 16 July 2018 at 12:00:57 UTC, Simen Kjærås wrote: On Monday, 16 July 2018 at 11:43:03 UTC, Timoses wrote: Why does this fail? It doesn't. Not using DMD 2.081.1 under Windows, at least. I tried adding a bitfield since you ment

Re: Implicit conversion of struct with methods to immutable in pure function fails

2018-07-16 Thread Seb via Digitalmars-d-learn
On Monday, 16 July 2018 at 13:13:53 UTC, Timoses wrote: On Monday, 16 July 2018 at 12:00:57 UTC, Simen Kjærås wrote: On Monday, 16 July 2018 at 11:43:03 UTC, Timoses wrote: Why does this fail? It doesn't. Not using DMD 2.081.1 under Windows, at least. I tried adding a bitfield since you ment

Re: Implicit conversion of struct with methods to immutable in pure function fails

2018-07-16 Thread Timoses via Digitalmars-d-learn
On Monday, 16 July 2018 at 12:00:57 UTC, Simen Kjærås wrote: On Monday, 16 July 2018 at 11:43:03 UTC, Timoses wrote: Why does this fail? It doesn't. Not using DMD 2.081.1 under Windows, at least. I tried adding a bitfield since you mentioned it, but it compiles nicely for me. Which version o

  1   2   3   4   5   6   >