On Tuesday, 21 October 2014 at 08:02:52 UTC, bearophile wrote:
Currently this code gets rejected:
const int[] a = [1];
void main() pure {
auto y = a[0];
}
test2.d(3,14): Error: pure function 'D main' cannot access
mutable static data 'a'
test2.d(3,14): Error: pure function 'D main'
Minas Mina:
Aren't pure functions supposed to return the same result every
time? If yes, it is correct to not accept it.
But how can main() not be pure? Or, how can't the 'a' array be
immutable?
Bye,
bearophile
On Tuesday, 21 October 2014 at 08:25:07 UTC, bearophile wrote:
Minas Mina:
Aren't pure functions supposed to return the same result every
time? If yes, it is correct to not accept it.
But how can main() not be pure? Or, how can't the 'a' array be
immutable?
Bye,
bearophile
There can
On Tuesday, 21 October 2014 at 08:48:09 UTC, safety0ff wrote:
On Tuesday, 21 October 2014 at 08:25:07 UTC, bearophile wrote:
Minas Mina:
Aren't pure functions supposed to return the same result
every time? If yes, it is correct to not accept it.
But how can main() not be pure? Or, how can't
Szymon Gatner:
const int[] a;
int[] b;
static this()
{
b = [1];
a = b;
}
Ant this code works? What is the point of const then if you can
assign it to mutable slice?
It works, and I think it should work. Inside the (module)
constructor the const state is handled differently.
Thank
On Tuesday, 21 October 2014 at 08:48:09 UTC, safety0ff wrote:
On Tuesday, 21 October 2014 at 08:25:07 UTC, bearophile wrote:
Minas Mina:
Aren't pure functions supposed to return the same result
every time? If yes, it is correct to not accept it.
But how can main() not be pure? Or, how can't
On Tuesday, 21 October 2014 at 12:08:35 UTC, Solomon E wrote:
On Tuesday, 21 October 2014 at 08:48:09 UTC, safety0ff wrote:
const int[] a;
int[] b;
static this()
{
b = [1];
a = b;
}
`a` isn't a reference to `b`. `a` is assigned by value and has
its own storage.
`a` is indeed a copy
On Tuesday, 21 October 2014 at 12:30:30 UTC, anonymous wrote:
On Tuesday, 21 October 2014 at 12:08:35 UTC, Solomon E wrote:
On Tuesday, 21 October 2014 at 08:48:09 UTC, safety0ff wrote:
const int[] a;
int[] b;
static this()
{
b = [1];
a = b;
}
`a` isn't a reference to `b`. `a` is
On Tue, 21 Oct 2014 13:43:29 +
Solomon E via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:
`b[0] = 8;` or `b[] = 8;` changes a. Printing the values for a
and b shows they're different pointers, but (a is b) returns
true. So I still have more to learn about how it does
On Tue, 21 Oct 2014 17:25:09 +0300
ketmar via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:
On Tue, 21 Oct 2014 13:43:29 +
Solomon E via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:
`b[0] = 8;` or `b[] = 8;` changes a. Printing the values for a
and b
On Tuesday, 21 October 2014 at 08:02:52 UTC, bearophile wrote:
Currently this code gets rejected:
const int[] a = [1];
void main() pure {
auto y = a[0];
}
test2.d(3,14): Error: pure function 'D main' cannot access
mutable static data 'a'
test2.d(3,14): Error: pure function 'D main'
On Tuesday, 21 October 2014 at 14:25:20 UTC, ketmar via
Digitalmars-d-learn wrote:
On Tue, 21 Oct 2014 13:43:29 +
Solomon E via Digitalmars-d-learn
digitalmars-d-learn@puremagic.com
wrote:
`b[0] = 8;` or `b[] = 8;` changes a. Printing the values for
a and b shows they're different
On Tuesday, October 21, 2014 08:02:50 bearophile via
Digitalmars-d-learn
wrote:
Currently this code gets rejected:
const int[] a = [1];
void main() pure {
auto y = a[0];
}
test2.d(3,14): Error: pure function 'D main' cannot access
mutable static data 'a'
test2.d(3,14): Error: pure
On Tue, 21 Oct 2014 16:47:04 +
Solomon E via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:
That's unsafe because the implementation might change, and
pointer arithmetic is unsafe in general.
sure, ponter casting is implementation-dependend. but .ptr is
guaranteed to work as
On Tuesday, 21 October 2014 at 15:51:27 UTC, MachineCode wrote:
...
...
pure functions are also supposed to don't use global variables
at all, according to functional programming paradigm
Pure functions are immutables (constants but not const in the D
or C++ senses) and can use other
On Tuesday, 21 October 2014 at 16:56:06 UTC, Solomon E wrote:
On Tuesday, 21 October 2014 at 15:51:27 UTC, MachineCode wrote:
...
...
pure functions are also supposed to don't use global variables
at all, according to functional programming paradigm
Pure functions are immutables (constants
On Tuesday, 21 October 2014 at 15:51:27 UTC, MachineCode wrote:
pure functions are also supposed to don't use global variables
at all, according to functional programming paradigm
The functional programming paradigm is kind of irrelevant to D's
pure, which should really be something more like
On Tuesday, 21 October 2014 at 17:00:49 UTC, Meta wrote:
There is no such thing as global scope in D.
While that's technically true (and very good for avoiding symbol
conflicts), modules at the module level are still typically
referred to as global variables.
18 matches
Mail list logo