Proposal: Relax rules for 'pure'

Steven Schveighoffer schveiguy at yahoo.com
Thu Sep 23 13:47:59 PDT 2010


On Thu, 23 Sep 2010 16:43:13 -0400, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> On 9/23/10 15:25 CDT, Don wrote:
>> Steven Schveighoffer wrote:
>>> On Thu, 23 Sep 2010 08:47:36 -0400, Robert Jacques <sandford at jhu.edu>
>>> wrote:
>>>
>>>> On Thu, 23 Sep 2010 02:51:28 -0400, Don <nospam at nospam.com> wrote:
>>>>
>>>>> Jesse Phillips wrote:
>>>>>> Steven Schveighoffer Wrote:
>>>>>>> If we can define weakly pure functions this way, they most likely
>>>>>>> will be way more common than unpure functions. I know I avoid
>>>>>>> accessing global variables in most of my functions. Think about a
>>>>>>> range, almost all the methods in a range can be weakly pure. So
>>>>>>> that means you need to mark every function as pure.
>>>>>
>>>>> I think that's true. I/O is impure, but most other things are not.
>>>>
>>>> The GC also impure :)
>>>
>>> The GC must be assumed to be pure even though it's not. Otherwise,
>>> pure functions can't do any heap allocation, and that makes them
>>> pretty useless in a garbage collected languages.
>>>
>>> In functional languages, allocating memory is usually considered pure.
>>
>> In the D spec, it already says that 'new' is considered pure.
>
> Which is wrong :o(. new invokes the constructor, which may do a variety  
> of impure things.

Wouldn't they need to be pure constructors to be called in pure functions?

-Steve


More information about the Digitalmars-d mailing list