Check whether function/delegate uses any shared or global variables
Is there any way to check whether a function/delegate passed to a function uses any shared or global variables ? I could not find any in std.traits.
Re: Check whether function/delegate uses any shared or global variables
On Monday, 12 December 2016 at 11:15:28 UTC, Nicholas Wilson wrote: On Monday, 12 December 2016 at 11:02:21 UTC, Nikhil Jacob wrote: Is there any way to check whether a function/delegate passed to a function uses any shared or global variables ? I could not find any in std.traits. there is the pure function attribute, how ever this still allows you to use globals *if you pass them as parameters to the function*. see https://dlang.org/spec/function.html#pure-functions Make sense.. I have two follow up questions 1. What about delegates ? 2. If a function is not explicitly declared as pure but satisfies the conditions of a pure function then can i check whether the function is pure using functionAttributes in std.traits.
Re: Check whether function/delegate uses any shared or global variables
On Monday, 12 December 2016 at 12:30:42 UTC, Jacob Carlborg wrote: On 2016-12-12 12:15, Nicholas Wilson wrote: there is the pure function attribute, how ever this still allows you to use globals *if you pass them as parameters to the function*. And it can access immutable global data. Thank you all for the help
How to override impure function from pure function
In the D spec for pure functions it says that a pure function can override "can override an impure function, but an impure function cannot override a pure one" Can anyone help me how to do this ?
Re: How to override impure function from pure function
On Tuesday, 13 December 2016 at 05:10:02 UTC, Nicholas Wilson wrote: On Tuesday, 13 December 2016 at 04:48:11 UTC, Nikhil Jacob wrote: In the D spec for pure functions it says that a pure function can override "can override an impure function, but an impure function cannot override a pure one" Can anyone help me how to do this ? what this means is class Foo { void foo() { ... } } class Bar : Foo { override void foo() pure { ... } } is allowed. but int someglobal; class Foo { void foo() pure { ... } } class Bar : Foo { override void foo() { someglobal = 42; } } in not. I mistook the original statement to mean that an impure function can be called from a pure function with some manual overrides. Thank you for the clarification.
Pointer to private structure
In C, we can define a struct without body in an include file and use pointer to that structure For examples in public header file. struct data; data* new_data(); We can then define the elements of struct data privately inside the implementation of library. Can we do this in D without using void* ?
Re: Pointer to private structure
On Monday, 19 December 2016 at 06:21:10 UTC, ketmar wrote: i bet that just trying this with D compiler will take less time than writing forum post. I did try but it seems to give compilation failure... Let me try once more and I will get back with more details.
Re: Pointer to private structure
On Monday, 19 December 2016 at 10:14:49 UTC, Ali wrote: On Monday, 19 December 2016 at 06:42:27 UTC, Nikhil Jacob wrote: [...] What're you trying to do here? Forward declarations in C++ are used to solve a few different things: 1. Reduce build times (unneeded in D AFAIK) 2. Break cyclic references (unneeded in D again?) 3. Give APIs visibility (D's modules and Access layers solve this) 4. Maintain binary compatibility while allowing internal data changes (aka pimlp idiom) <-- This I believe you cannot do in D - https://wiki.dlang.org/Access_specifiers_and_visibility (someone correct me if I'm wrong) I've seen something about .di files in D. But they seem flakey a bit. I was trying to do something similar to pimlp idiom. But after thinking over it, I found a better way in D. Thanks for pointing to the wiki