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

purity question

2017-05-28 Thread Brad Roberts via Digitalmars-d-learn
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 possibly state of the heap or gc return s; }

Re: Input interrupt

2017-05-28 Thread helxi via Digitalmars-d-learn
On Sunday, 28 May 2017 at 22:14:46 UTC, Adam D. Ruppe wrote: On Sunday, 28 May 2017 at 22:07:12 UTC, helxi wrote: So I tried using C's EOF but the types aren't compatible since EOF is probably aliased to -1 The readln docs for D say it returns null on end of file. The example given is:

Re: Input interrupt

2017-05-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 28 May 2017 at 22:07:12 UTC, helxi wrote: So I tried using C's EOF but the types aren't compatible since EOF is probably aliased to -1 The readln docs for D say it returns null on end of file. The example given is: import std.stdio; void main() { string line; while

Input interrupt

2017-05-28 Thread helxi via Digitalmars-d-learn
Hello, I just wrote a mock-up of Unix's $cat. However unlike the actual $cat, when input interrupt (Cntrl+D) is pressed the following program does not stop. So I tried using C's EOF but the types aren't compatible since EOF is probably aliased to -1 //... if (args.length < 2) {

Re: need to emulate scope(failure) with struct destructor

2017-05-28 Thread Dukc via Digitalmars-d-learn
On Sunday, 28 May 2017 at 20:06:42 UTC, piotrklos wrote: I need to perform an action, in multiple separate functions, if scope exits with an exception. The trouble is I don't want to litter my code with scope(failure) everywhere. I already create an instance of a struct at each location, with

need to emulate scope(failure) with struct destructor

2017-05-28 Thread piotrklos via Digitalmars-d-learn
I need to perform an action, in multiple separate functions, if scope exits with an exception. The trouble is I don't want to litter my code with scope(failure) everywhere. I already create an instance of a struct at each location, with the sole purpose of doing things at the end of scope. So

Re: How to call readf

2017-05-28 Thread Petras via Digitalmars-d-learn
On Sunday, 28 May 2017 at 15:00:30 UTC, Ali Çehreli wrote: On 05/28/2017 07:55 AM, Petras wrote: > Hi, I am learning how to use readf to read integers. I follow the > example in https://dlang.org/library/std/stdio/readf.html > > The sample code use readf in following way > readf!" %d"(a);

Re: gtkd build fail on windows with dmd 2.074.0

2017-05-28 Thread Mike Wey via Digitalmars-d-learn
On 05/28/2017 03:30 PM, Mike Wey wrote: On 05/28/2017 03:20 PM, Mike Wey wrote: On 05/27/2017 11:42 PM, greatsam4sure wrote: rdmd Build.d fail on windows with dmd 2.074.0,dmd 2.073.0. it says std.file.FileException@std\file.d(814)gtkd2.obj:The system cannot find the file specifield. I have

Re: How to call readf

2017-05-28 Thread Ali Çehreli via Digitalmars-d-learn
On 05/28/2017 07:55 AM, Petras wrote: > Hi, I am learning how to use readf to read integers. I follow the > example in https://dlang.org/library/std/stdio/readf.html > > The sample code use readf in following way > readf!" %d"(a); Providing the format string as a template argument and being

How to call readf

2017-05-28 Thread Petras via Digitalmars-d-learn
Hi, I am learning how to use readf to read integers. I follow the example in https://dlang.org/library/std/stdio/readf.html The sample code use readf in following way readf!" %d"(a); It works when I use dmd 2.074. However, I got compile error when I switch to ldc2

Re: gtkd build fail on windows with dmd 2.074.0

2017-05-28 Thread Mike Wey via Digitalmars-d-learn
On 05/28/2017 03:20 PM, Mike Wey wrote: On 05/27/2017 11:42 PM, greatsam4sure wrote: rdmd Build.d fail on windows with dmd 2.074.0,dmd 2.073.0. it says std.file.FileException@std\file.d(814)gtkd2.obj:The system cannot find the file specifield. I have to use dmd 2.071.0 to build it I will

Re: gtkd build fail on windows with dmd 2.074.0

2017-05-28 Thread Mike Wey via Digitalmars-d-learn
On 05/27/2017 11:42 PM, greatsam4sure wrote: rdmd Build.d fail on windows with dmd 2.074.0,dmd 2.073.0. it says std.file.FileException@std\file.d(814)gtkd2.obj:The system cannot find the file specifield. I have to use dmd 2.071.0 to build it I will appreciate your help sorry for the mistake

Re: How to Get Screenshot on Windows ?

2017-05-28 Thread Vladimir Panteleev via Digitalmars-d-learn
On Sunday, 28 May 2017 at 04:05:47 UTC, Softwarez wrote: Hi can anyone please help me how to get screenshot on Windows using D, because all the other threads are using linux to get screenshot. In the same way you'd do it in C. Here is a more convoluted D example in the form of a program I