Re: purity question

2017-05-30 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, May 30, 2017 at 11:10:19AM -0700, Jonathan M Davis via Digitalmars-d-learn wrote: [...] > Yeah, basically, D's pure was originally what is now sometimes called > "strongly pure," which is quite close to functionally pure in that the > same input results in the same output (it still allows

Re: purity question

2017-05-30 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, May 30, 2017 16:54:13 ag0aep6g via Digitalmars-d-learn wrote: > On 05/30/2017 11:12 AM, Rene Zwanenburg wrote: > > If malloc were marked as pure, wouldn't that mean it must return the > > same pointer every time you call it with the same size? > > D's `pure` mostly means: "does not

Re: purity question

2017-05-30 Thread ag0aep6g via Digitalmars-d-learn
On 05/30/2017 11:12 AM, Rene Zwanenburg wrote: If malloc were marked as pure, wouldn't that mean it must return the same pointer every time you call it with the same size? D's `pure` mostly means: "does not access mutable state, and does not do input/output". There is never a requirement

Re: purity question

2017-05-30 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 13:45:07 UTC, Rene Zwanenburg wrote: On Tuesday, 30 May 2017 at 11:34:52 UTC, ketmar wrote: If malloc were marked as pure, wouldn't that mean it must return the same pointer every time you call it with the same size? of course. but D "pure" is not what other world

Re: purity question

2017-05-30 Thread ketmar via Digitalmars-d-learn
Rene Zwanenburg wrote: On Tuesday, 30 May 2017 at 11:34:52 UTC, ketmar wrote: If malloc were marked as pure, wouldn't that mean it must return the same pointer every time you call it with the same size? of course. but D "pure" is not what other world knows as "pure". we love to mess with

Re: purity question

2017-05-30 Thread Rene Zwanenburg via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 11:34:52 UTC, ketmar wrote: If malloc were marked as pure, wouldn't that mean it must return the same pointer every time you call it with the same size? of course. but D "pure" is not what other world knows as "pure". we love to mess with words. Well, there's the

Re: purity question

2017-05-30 Thread ketmar via Digitalmars-d-learn
Rene Zwanenburg wrote: On Monday, 29 May 2017 at 01:36:24 UTC, Jonathan M Davis wrote: A simple example: anything that has a malloc/free pair. Yeah, if you do it right, you should be fine, but you have to do it right, and it's very easy to miss some detail that makes it wrong to insist to

Re: purity question

2017-05-30 Thread Rene Zwanenburg via Digitalmars-d-learn
On Monday, 29 May 2017 at 01:36:24 UTC, Jonathan M Davis wrote: A simple example: anything that has a malloc/free pair. Yeah, if you do it right, you should be fine, but you have to do it right, and it's very easy to miss some detail that makes it wrong to insist to the compiler that what

Re: purity question

2017-05-29 Thread Seb via Digitalmars-d-learn
On Monday, 29 May 2017 at 08:49:07 UTC, ketmar wrote: Brad Roberts wrote: libraries that themselves aren't marked pure, there's a real need for escape hatches. A simple example: anything that has a malloc/free pair. they aren't pure. it is a sad misconception about purity, which D makes

Re: purity question

2017-05-29 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 29 May 2017 at 11:25:06 UTC, ketmar wrote: almost all of them, 'cause they depends on FPU rounding settings. Well, yeah. IIRC contemporary floating point machine language instructions allow embedding of rounding mode into the instruction. A pity languages are lagging behind,

Re: purity question

2017-05-29 Thread ketmar via Digitalmars-d-learn
Ola Fosheim Grøstad wrote: On Monday, 29 May 2017 at 08:49:07 UTC, ketmar wrote: pure. and while various functions in std.math, for example, are marked `pure`, they aren't too. Out of curiosity, which functions in std.math aren't "pure" in the D sense? almost all of them, 'cause they

Re: purity question

2017-05-29 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 29 May 2017 at 08:49:07 UTC, ketmar wrote: pure. and while various functions in std.math, for example, are marked `pure`, they aren't too. Out of curiosity, which functions in std.math aren't "pure" in the D sense?

Re: purity question

2017-05-29 Thread ketmar via Digitalmars-d-learn
Brad Roberts wrote: libraries that themselves aren't marked pure, there's a real need for escape hatches. A simple example: anything that has a malloc/free pair. they aren't pure. it is a sad misconception about purity, which D makes even more complex by allowing to mark, for example,

Re: purity question

2017-05-28 Thread Seb via Digitalmars-d-learn
On Sunday, 28 May 2017 at 23:49:16 UTC, Brad Roberts wrote: Is there a mechanism for declaring something pure when it's built from parts which individually aren't? string foo(string s) { // do something arbitrarily complex with s that doesn't touch globals or change global state except

Re: purity question

2017-05-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 28, 2017 18:46:22 Brad Roberts via Digitalmars-d-learn wrote: > Again, of course it's possible to do it wrong. Escape hatches are like > that. And of course things are being worked on and improved, I'm one of > the ones that's done a good bit of that at various points in time.

Re: purity question

2017-05-28 Thread Brad Roberts via Digitalmars-d-learn
On 5/28/2017 6:46 PM, Brad Roberts via Digitalmars-d-learn wrote: Here's the bug that I'm digging into today, a clear example of an api that _should_ be pure, but based on the implementation is rather difficult for the compiler to infer. https://issues.dlang.org/show_bug.cgi?id=17442

Re: purity question

2017-05-28 Thread Brad Roberts via Digitalmars-d-learn
On 5/28/2017 6:36 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Sunday, May 28, 2017 17:53:25 Brad Roberts via Digitalmars-d-learn wrote: On 5/28/2017 5:34 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Sunday, May 28, 2017 16:49:16 Brad Roberts via Digitalmars-d-learn wrote:

Re: purity question

2017-05-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 28, 2017 18:39:02 Brad Roberts via Digitalmars-d-learn wrote: > On 5/28/2017 6:27 PM, Jonathan M Davis via Digitalmars-d-learn wrote: > > There was a whole discussion or 3 is PRs about making malloc pure, and > > IIRC, it was done and then decided that it wasn't safe to do some for

Re: purity question

2017-05-28 Thread Brad Roberts via Digitalmars-d-learn
On 5/28/2017 6:27 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Monday, May 29, 2017 01:01:46 Stefan Koch via Digitalmars-d-learn wrote: On Monday, 29 May 2017 at 00:53:25 UTC, Brad Roberts wrote: On 5/28/2017 5:34 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Sunday, May

Re: purity question

2017-05-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 28, 2017 17:53:25 Brad Roberts via Digitalmars-d-learn wrote: > On 5/28/2017 5:34 PM, Jonathan M Davis via Digitalmars-d-learn wrote: > > On Sunday, May 28, 2017 16:49:16 Brad Roberts via Digitalmars-d-learn wrote: > >> Is there a mechanism for declaring something pure when it's

Re: purity question

2017-05-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, May 29, 2017 01:01:46 Stefan Koch via Digitalmars-d-learn wrote: > On Monday, 29 May 2017 at 00:53:25 UTC, Brad Roberts wrote: > > On 5/28/2017 5:34 PM, Jonathan M Davis via Digitalmars-d-learn > > > > wrote: > >> On Sunday, May 28, 2017 16:49:16 Brad Roberts via > >> > >>

Re: purity question

2017-05-28 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 29 May 2017 at 01:12:53 UTC, Era Scarecrow wrote: ... Hmm didn't notice the post had split. Otherwise i wouldn't have replied... That and thinking about the GC state (outside of allocating memory)...

Re: purity question

2017-05-28 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 28 May 2017 at 23:49:16 UTC, Brad Roberts wrote: // do something arbitrarily complex with s that doesn't touch globals or change global state except possibly state of the heap or gc Sounds like the basic definition of pure to me; At least in regards to D. Memory allocation

Re: purity question

2017-05-28 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 29 May 2017 at 01:01:46 UTC, Stefan Koch wrote: There is void[] myPureMalloc(uint size) pure @trusted nothrow @nogc { import core.stdc.stdlib : malloc; alias pure_malloc_t = @nogc pure nothrow void* function(size_t size); return (cast(pure_malloc_t))(size)[0 .. size]; }

Re: purity question

2017-05-28 Thread Brad Roberts via Digitalmars-d-learn
On 5/28/2017 6:01 PM, Stefan Koch via Digitalmars-d-learn wrote: On Monday, 29 May 2017 at 00:53:25 UTC, Brad Roberts wrote: On 5/28/2017 5:34 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Sunday, May 28, 2017 16:49:16 Brad Roberts via Digitalmars-d-learn wrote: Is there a mechanism

Re: purity question

2017-05-28 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 29 May 2017 at 00:53:25 UTC, Brad Roberts wrote: On 5/28/2017 5:34 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Sunday, May 28, 2017 16:49:16 Brad Roberts via Digitalmars-d-learn wrote: Is there a mechanism for declaring something pure when it's built from parts which

Re: purity question

2017-05-28 Thread Brad Roberts via Digitalmars-d-learn
On 5/28/2017 5:34 PM, Jonathan M Davis via Digitalmars-d-learn wrote: On Sunday, May 28, 2017 16:49:16 Brad Roberts via Digitalmars-d-learn wrote: Is there a mechanism for declaring something pure when it's built from parts which individually aren't? string foo(string s) { // do

Re: purity question

2017-05-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 28, 2017 16:49:16 Brad Roberts via Digitalmars-d-learn wrote: > Is there a mechanism for declaring something pure when it's built from > parts which individually aren't? > > string foo(string s) > { > // do something arbitrarily complex with s that doesn't touch > globals or