Skip to content

Commit

Permalink
not really pure
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jun 26, 2011
1 parent d6c471b commit 4f28db6
Show file tree
Hide file tree
Showing 5 changed files with 294 additions and 294 deletions.
14 changes: 7 additions & 7 deletions std/bigint.d
Expand Up @@ -366,7 +366,7 @@ public:
}
/// Returns the value of this BigInt as a long,
/// or +- long.max if outside the representable range.
long toLong() pure const
long toLong() const
{
return (sign ? -1 : 1) *
(data.ulongLength() == 1 && (data.peekUlong(0) <= cast(ulong)(long.max))
Expand All @@ -375,7 +375,7 @@ public:
}
/// Returns the value of this BigInt as an int,
/// or +- int.max if outside the representable range.
long toInt() pure const
long toInt() const
{
return (sign ? -1 : 1) *
(data.uintLength() == 1 && (data.peekUint(0) <= cast(uint)(int.max))
Expand All @@ -384,13 +384,13 @@ public:
}
/// Number of significant uints which are used in storing this number.
/// The absolute value of this BigInt is always < 2^^(32*uintLength)
@property size_t uintLength() pure const
@property size_t uintLength() const
{
return data.uintLength();
}
/// Number of significant ulongs which are used in storing this number.
/// The absolute value of this BigInt is always < 2^^(64*ulongLength)
@property size_t ulongLength() pure const
@property size_t ulongLength() const
{
return data.ulongLength();
}
Expand Down Expand Up @@ -440,16 +440,16 @@ private:
if (!data.isZero())
sign = !sign;
}
bool isZero() pure const
bool isZero() const
{
return data.isZero();
}
bool isNegative() pure const
bool isNegative() const
{
return sign;
}
// Generate a runtime error if division by zero occurs
void checkDivByZero() pure const
void checkDivByZero() const
{
assert(!isZero(), "BigInt division by zero");
if (isZero())
Expand Down
2 changes: 1 addition & 1 deletion std/complex.d
Expand Up @@ -113,7 +113,7 @@ struct Complex(T) if (isFloatingPoint!T)
T im;


@safe pure nothrow // The following functions depend only on std.math.
@safe nothrow // The following functions depend only on std.math.
{

/** Calculate the absolute value (or modulus) of the number. */
Expand Down

8 comments on commit 4f28db6

@dsimcha
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??? Why isn't the stuff in std.parallelism pure?

@WalterBright
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's referring to non-immutable members of a non-local variable.

@jmdavis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't the std.datetime stuff be pure? None of it is accessing non-immutable, non-local variables.

@WalterBright
Copy link
Member Author

@WalterBright WalterBright commented on 4f28db6 Jun 26, 2011 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dnadlinger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Walter decided to »tighten purity checks« in dlang/dmd@84b4fd1

@jmdavis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, weakly pure functions are supposed to be able to do that.

@jmdavis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without that, how can much in the way of member functions be pure?

@yebblies
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WalterBright
With the weak purity rules, functions should be able to do anything they like with any passed in parameters, including the implicit this parameter. Their only restriction is they they cannot directly access non-immutable global variables directly. They can even access globals if they are passed a pointer to them.
Purity isn't violated as strong-pure functions would never be able to pass global data into weak pure functions anyway.

Please sign in to comment.