## digitalmars.D - pure and (fully) lazy?

• J. Shimizu (19/19) Oct 14 2010 I have heard of D once or twice, so in a paroxysm of profligacy in a boo...
• bearophile (4/6) Oct 14 2010 The lazy attribute may be deprecated, but I don't remember a final word ...
J. Shimizu <tamayo89 gmail.com> writes:
```I have heard of D once or twice, so in a paroxysm of profligacy in a bookstore
recently, I picked up Dr Alexandrescu's very enjoyable book "The D Programming
Language."  One thing he does not discuss therein, however, is lazy parameters.

In the book, Dr Alexandrescu most properly deplores the teaching of the
Fibonacci function as a direct recursion.  He goes on of course to show how
the D language is willing to call any procedure that has no observable
side-effects (for stringent values of "observable") a pure function, by
showing that the D compiler accepts the iterative version of the Fibonacci
function as pure.

He and the compiler are right, naturally, but there is one thing that he did
not mention and that the compiler could not be expected to discover.  The
iterative Fibonacci function is mechanically derivable from its recursive
expression by means of dynamic programming, and dynamic programming can be
simulated by memoization.

From what I understand from the web site, however, the lazy attribute on a D
function parameter makes it call-by-name, not call-by-need.  Consequently, I
see no way to implement a memoized recursive version of the Fibonacci function
(or any other pure function) and still have the compiler believe me when I
call that function "pure".  I respectfully hope I might be disabused of that
fear.
```
Oct 14 2010
bearophile <bearophileHUGS lycos.com> writes:
```J. Shimizu:

From what I understand from the web site, however, the lazy attribute on a D
function parameter makes it call-by-name, not call-by-need.

The lazy attribute may be deprecated, but I don't remember a final word on
this. I don't know what's meant to replace them, of if there is a way to fix &
keep them.

Bye,
bearophile
```
Oct 14 2010
```bearophile napisaĆ:

The lazy attribute may be deprecated, but I don't remember a final word on
this.

Me neither.

I don't know what's meant to replace them

AFAIR, implicit conversion of expressions to parameterless delegates.

--
Tomek
```
Oct 14 2010
Jonathan M Davis <jmdavisProg gmx.com> writes:
```On Thursday, October 14, 2010 12:32:06 bearophile wrote:
J. Shimizu:
From what I understand from the web site, however, the lazy attribute on
a D function parameter makes it call-by-name, not call-by-need.

The lazy attribute may be deprecated, but I don't remember a final word on
this. I don't know what's meant to replace them, of if there is a way to
fix & keep them.

Bye,
bearophile

I'm pretty sure that it isn't deprecated, but I believe thatthere was some
discussion of possibly deprecating it. Again, a list of the exact list of
features which is currently supported but intended for deprecation would be
good
but has never materialized. They usually don't even need -d to compile, so you
have to have been paying attention to the newsgroups and remember the way such
discussions went if you want to have any idea of what they are. And even then,
you can't be completely sure.

- Jonathan M Davis
```
Oct 14 2010