Hi,
Is it possible for D to create lazy functions, lazy arrays? Or in
addition to the function arguments can't be lazy in D?
For example,
lazy int sum(int a = 3, int b = 5) {
return a + b;
}
That is, if the function is not invoked, it should not be
calculated at compile time.
On Friday, 20 March 2015 at 10:02:27 UTC, Dennis Ritchie wrote:
For example,
lazy int sum(int a = 3, int b = 5) {
return a + b;
}
That is, if the function is not invoked, it should not be
calculated at compile time.
I don't understand what you mean. You mean a function that isn't
co
On Friday, 20 March 2015 at 10:38:17 UTC, John Colvin wrote:
I don't understand what you mean. You mean a function that
isn't compiled if it isn't used anywhere?
Yes. That's exactly what I mean.
On Friday, 20 March 2015 at 12:15:22 UTC, Dennis Ritchie wrote:
On Friday, 20 March 2015 at 10:38:17 UTC, John Colvin wrote:
I don't understand what you mean. You mean a function that
isn't compiled if it isn't used anywhere?
Yes. That's exactly what I mean.
Use case?
Use case?
No. I need to be able to make an array "factorials" is not
evaluated, if I don't.
import std.stdio;
enum N = 15;
static int[] factorials = memoizeFactorials(N); // lazy array? :)
int[] memoizeFactorials(int n)
{
if (!__ctfe) {
// Make sure that this function is never
Now I am totally confused. lazy and eager evaluation are
unrelated to compile time and run time.
On Friday, 20 March 2015 at 13:35:10 UTC, Dennis Ritchie wrote:
Use case?
No. I need to be able to make an array "factorials" is not
evaluated, if I don't.
import std.stdio;
enum N = 15;
static int[] factorials = memoizeFactorials(N); // lazy array?
:)
int[] memoizeFactorials(int n)
{
On Friday, 20 March 2015 at 14:20:16 UTC, John Colvin wrote:
On Friday, 20 March 2015 at 13:35:10 UTC, Dennis Ritchie wrote:
Use case?
No. I need to be able to make an array "factorials" is not
evaluated, if I don't.
import std.stdio;
enum N = 15;
static int[] factorials = memoizeFactoria
On Friday, 20 March 2015 at 12:52:16 UTC, Tobias Pankrath wrote:
Use case?
I do this with local imports so a module works without
dependencies unless you use the specific functions that need the
additional module.
On Friday, 20 March 2015 at 14:27:06 UTC, John Colvin wrote:
I made a mistake about the static variable and thread-local
storage.
immutable(int)[] factorials()() @property
{
static immutable int[N] results = memoizeFactorials(N);
return results[];
}
is the correct way to do it if you h
On Friday, 20 March 2015 at 16:01:51 UTC, Dennis Ritchie wrote:
On Friday, 20 March 2015 at 14:27:06 UTC, John Colvin wrote:
I made a mistake about the static variable and thread-local
storage.
immutable(int)[] factorials()() @property
{
static immutable int[N] results = memoizeFactorials(N
12 matches
Mail list logo