digitalmars.D - Feature request: lazy as a type constructor
- Janice Caron (28/28) Sep 25 2007 Please may we have "lazy" as a type constructor (as well as a
- BCS (2/8) Sep 25 2007 This sounds like a useful addition
- Jarrett Billingsley (5/9) Sep 25 2007 vote += real.max;
- downs (4/17) Sep 25 2007 OH PLEASE.
- Christopher Wright (3/14) Sep 25 2007 vote += real.nan;
- BCS (6/25) Sep 25 2007 qsort(taskBuffer.ptr, Task.sizeof, function int(void* a, void* b)
- Janice Caron (32/32) Sep 26 2007 The thing is, I say these things without having thought them through
- Stewart Gordon (15/20) Sep 26 2007 I'm not sure how the implementation of this would work in general.
- renoX (7/10) Oct 07 2007 Uh?
- Nathan Reed (5/7) Oct 07 2007 Lazy parameters are implemented as delegates, so actually an array of
- Janice Caron (6/11) Oct 07 2007 What Nathan said.
Please may we have "lazy" as a type constructor (as well as a parameter storage class)? Currently I can declare a lazy array of ints, but not an array of lazy ints. That means we can't have variadic functions with lazy variadic parameters. It would be quite useful to be able to do: void f(lazy(int)[]a...) { } The intent here is to declare that a is a variadic array of lazy ints - that is, an array of delegates, so that when I do void f(lazy(int)[]a...) { foreach(d;a) { if (a == 0) return; } } int show(int n) { writefln(n); return n; } f(show(1),show(0),show(2)); we would expect show() to be called only twice (with parameters 0 and 1). show(2) won't have happened because of the laziness. Unfortunately I can't do that right now, because lazy is a storage class, not a type modifier. I can make the entire array lazy, but not the array's elements.
Sep 25 2007
Reply to Janice,Please may we have "lazy" as a type constructor (as well as a parameter storage class)? Currently I can declare a lazy array of ints, but not an array of lazy ints. That means we can't have variadic functions with lazy variadic parameters. It would be quite useful to be able to do:This sounds like a useful addition
Sep 25 2007
"Janice Caron" <caron800 googlemail.com> wrote in message news:mailman.300.1190729504.16939.digitalmars-d puremagic.com...Please may we have "lazy" as a type constructor (as well as a parameter storage class)? Currently I can declare a lazy array of ints, but not an array of lazy ints. That means we can't have variadic functions with lazy variadic parameters.vote += real.max; While we're at it.. make ref a type constructor too. REF RETURNS WOOO can't wait for those.
Sep 25 2007
Jarrett Billingsley wrote:"Janice Caron" <caron800 googlemail.com> wrote in message news:mailman.300.1190729504.16939.digitalmars-d puremagic.com...OH PLEASE. vote=real.infinity; // for both :D --downs aka mr. "I lost my key pair"Please may we have "lazy" as a type constructor (as well as a parameter storage class)? Currently I can declare a lazy array of ints, but not an array of lazy ints. That means we can't have variadic functions with lazy variadic parameters.vote += real.max; While we're at it.. make ref a type constructor too. REF RETURNS WOOO can't wait for those.
Sep 25 2007
Jarrett Billingsley wrote:"Janice Caron" <caron800 googlemail.com> wrote in message news:mailman.300.1190729504.16939.digitalmars-d puremagic.com...vote += real.nan; I abstain, for myself and everyone else.Please may we have "lazy" as a type constructor (as well as a parameter storage class)? Currently I can declare a lazy array of ints, but not an array of lazy ints. That means we can't have variadic functions with lazy variadic parameters.vote += real.max; While we're at it.. make ref a type constructor too. REF RETURNS WOOO can't wait for those.
Sep 25 2007
Reply to Christopher,Jarrett Billingsley wrote:qsort(taskBuffer.ptr, Task.sizeof, function int(void* a, void* b) { return (cast(Task*)a).vote !< (cast(Task*)b).vote; }) // now nan is at the head of the list :b"Janice Caron" <caron800 googlemail.com> wrote in message news:mailman.300.1190729504.16939.digitalmars-d puremagic.com...vote += real.nan; I abstain, for myself and everyone else.Please may we have "lazy" as a type constructor (as well as a parameter storage class)? Currently I can declare a lazy array of ints, but not an array of lazy ints. That means we can't have variadic functions with lazy variadic parameters.vote += real.max; While we're at it.. make ref a type constructor too. REF RETURNS WOOO can't wait for those.
Sep 25 2007
The thing is, I say these things without having thought them through properly, and then all the thinking happens as we're having these discussions. What I /wanted/ was to be able to declare a function with an unknown number of lazy arguments. My suggestion may have been overkill. Perhaps it would suffice to define that void f(lazy T[]...) shall mean an array of delegates. That would solve the problem that I wanted solving. But since I did put the original suggestion on the table, lets think it through and see where it would lead. It would mean that you would be able to declare lazy variables locally. Is this a good thing? I really don't know. Let's see what an example would look like: lazy(int) n; here, n is not really an int, it's a lazy(int) - that is, a delegate returning an int. So when we assign it, we're not giving it a value, we're giving it a function body, and then when we read it, we're executing that function. lazy(int) n = x + 1; for (x=0; x<10; ++x) { writefln(n); } What would this do? I think it would print the numbers 1 to 10. Do we want to go down that road? I suspect not, as it's too big a departure from the way we expect things to work. On the other hand, to expect void f(lazy T[]...) to mean an array of lazies, rather than a lazy array, is perhaps not that unreasable. I think, therefore, that I must withdraw my original request, and replace it with this, much simpler one: Please may there be a way to declare a variadic function with (an unknown number of) lazy arguments?
Sep 26 2007
"Janice Caron" <caron800 googlemail.com> wrote in message news:mailman.300.1190729504.16939.digitalmars-d puremagic.com...Please may we have "lazy" as a type constructor (as well as a parameter storage class)?I'm not sure how the implementation of this would work in general.Currently I can declare a lazy array of ints, but not an array of lazy ints. That means we can't have variadic functions with lazy variadic parameters.<snip> Actually you can: http://www.digitalmars.com/d/function.html "Lazy Variadic Functions If the variadic parameter is an array of delegates with no parameters: void foo(int delegate()[] dgs ...); Then each of the arguments whose type does not match that of the delegate is converted to a delegate." Stewart. -- My e-mail address is valid but not my primary mailbox. Please keep replies on the 'group where everybody may benefit.
Sep 26 2007
Janice Caron a écrit :Please may we have "lazy" as a type constructor (as well as a parameter storage class)? Currently I can declare a lazy array of ints, but not an array of lazy ints.Uh? An int is a 32b machine word, so an array of int is a pretty efficient structure, so you cannot assingn a special value to an int not created. So an array of lazy int is probably an array of references to int, which is not very efficient.. renoX
Oct 07 2007
renoX wrote:So an array of lazy int is probably an array of references to int, which is not very efficient..Lazy parameters are implemented as delegates, so actually an array of lazy ints would be an array of delegates returning ints. Thanks, Nathan Reed
Oct 07 2007
On 10/7/07, renoX <renosky free.fr> wrote:Janice Caron a écrit :What Nathan said. Plus, I retracted this request a few posts up, and replaced it with a simpler one, which was this: please could lazy T[]... be interpreted as an array of delegates? (Currently it is interpreted as a delegate returning an array of Ts).Please may we have "lazy" as a type constructor (as well as a parameter storage class)? Currently I can declare a lazy array of ints, but not an array of lazy ints.Uh?
Oct 07 2007