digitalmars.D.announce - DMD 0.166 release
- Walter Bright (3/3) Aug 31 2006 The implicit conversion to delegate just broke too much. Instead, I'm
- Russ Lewis (7/11) Aug 31 2006 Is there any reason to not use "lazy" as a keyword to modify the
- Walter Bright (3/16) Aug 31 2006 One reason is lazy arguments and non-lazy arguments cannot be passed to
- Russ Lewis (3/14) Aug 31 2006 One of us is missing something. I'm not sure who :) Can you expand on
- Walter Bright (5/20) Aug 31 2006 foo(x + y);
- Russ Lewis (13/40) Aug 31 2006 Ah, I was wondering if that was what you meant. What I was suggesting
- Walter Bright (2/15) Aug 31 2006 Ok, that can work. But I don't see an application for it.
- Russ Lewis (7/24) Sep 01 2006 Heh, sems like I'm having a lot of trouble explaining myself here.
- Sean Kelly (4/31) Sep 01 2006 I believe this is the same as Derek's suggestion that in/out/inout be
- Walter Bright (5/35) Sep 01 2006 Yes, it would be the same. But I think the interface should be set by
- Derek Parnell (15/22) Sep 01 2006 Yes we agree. But the purpose of this suggestion is not to 'set the
- Walter Bright (8/28) Sep 02 2006 Setting the behavior at both the point of definition and point of use
- Ivan Senji (2/36) Sep 02 2006 Only it isn't "{ expression }" it is: "{ expression }()".
- Derek Parnell (26/56) Sep 02 2006 Why is it so hard to make my thoughts known to you?
- Chris Nicholson-Sauls (11/79) Sep 02 2006 I admit that I must have misunderstood as well, but looking at it this w...
- Ivan Senji (3/14) Sep 03 2006 This is a feature I would certainly be using. It can't do any harm but
- Rioshin an'Harthen (3/18) Sep 03 2006 I'll chime in with a resounding "me, too". Having in, out, inout or lazy...
- Walter Bright (2/11) Sep 03 2006 I misunderstood you. I didn't catch the optional bit. Sorry.
- Walter Bright (5/35) Sep 01 2006 Yes, it would be the same. But I think the interface should be set by
- Russ Lewis (6/9) Sep 05 2006 By that logic, shouldn't I be able to pass a delegate to a function with...
- Tom S (2/6) Aug 31 2006 Thanks Walter :) And thank you Oskar ! Now we can play with more IFTI :)
- Jarrett Billingsley (4/7) Aug 31 2006 Ahh, thank you. I wasn't really keen on the lazy stuff. I'd probably n...
- Kirk McDonald (8/12) Aug 31 2006 Nice. I'll have to play with the improved IFTI support.
- Jarrett Billingsley (4/5) Aug 31 2006 Hm. I missed this new feature. What does it include? There's not even...
- Kirk McDonald (6/18) Aug 31 2006 I'm referring to Oskar Linde's member template patches.
- Oskar Linde (8/16) Aug 31 2006 It is really just a small patch that enables implicit function template
- Ivan Senji (2/24) Aug 31 2006
- Jarrett Billingsley (6/12) Aug 31 2006 Ah!! This exactly solves the problem I was (am!) having with needing
- BCS (7/33) Aug 31 2006 Hot, Dog!!!
- Oskar Linde (6/47) Sep 02 2006 Certainly not. Feel free to go ahead. :)
- BCS (8/28) Sep 02 2006 I think 7d is actually more than is needed (But I'm no expert). Mine
- Derek Parnell (20/41) Aug 31 2006 In your example code you have ...
- Tom S (2/41) Aug 31 2006 Nope, since it only works for classes, and his SiQuantity is a struct
- Derek Parnell (9/50) Aug 31 2006 Damn! I didn't know that. What's the rationale for such a seemingly
- Walter Bright (2/4) Aug 31 2006 No virtual functions for structs!
- Derek Parnell (22/27) Aug 31 2006 Ok, that meant nothing to me until I translated it from the OO jargon. H...
- Kirk McDonald (6/9) Aug 31 2006 It could also be done with variadic templates.
- Bruno Medeiros (23/48) Sep 01 2006 Another alternative is a syntax using the concatenation operator:
- Oskar Linde (5/10) Sep 02 2006 If one considered toString() important enough it could be added to the
- Walter Bright (2/12) Sep 02 2006 That makes sense.
- Walter Bright (2/10) Aug 31 2006 Oskar had emailed me the patches.
- Ivan Senji (20/24) Sep 01 2006 Hmm, I am afraid I have to admit I'm a little bit puzzled by this lazy
- Chris Nicholson-Sauls (32/69) Sep 01 2006 This is because anonymous delegates are themselves expressions, and so y...
- Ivan Senji (35/83) Sep 01 2006 Hmm, there is something about this lazy stuff that is troubling me and
- Ivan Senji (17/109) Sep 01 2006 Actually I just figured out i can have both pretty cases :) Hooray, just...
- Sean Kelly (10/104) Sep 01 2006 It may be that delegates should be implicitly convertible to lazy
- Ivan Senji (5/116) Sep 01 2006 Maybe, that is what I expected it would do in the first place (it's too
- Chris Nicholson-Sauls (7/111) Sep 02 2006 Or... just put parentheses around it instead of braces, and use commas i...
- Lutger (4/8) Sep 03 2006 So there is IFTI for member functions functions now...I'm a little late,...
The implicit conversion to delegate just broke too much. Instead, I'm trying out Tom S.'s suggestion of using a 'lazy' parameter storage class. http://www.digitalmars.com/d/changelog.html
Aug 31 2006
Walter Bright wrote:The implicit conversion to delegate just broke too much. Instead, I'm trying out Tom S.'s suggestion of using a 'lazy' parameter storage class. http://www.digitalmars.com/d/changelog.htmlIs there any reason to not use "lazy" as a keyword to modify the expression, rather than the parameter? void foo(int delegate() dg) {...} void bar(int x,int y) { foo(lazy x+y); }
Aug 31 2006
Russ Lewis wrote:Walter Bright wrote:One reason is lazy arguments and non-lazy arguments cannot be passed to the same function.The implicit conversion to delegate just broke too much. Instead, I'm trying out Tom S.'s suggestion of using a 'lazy' parameter storage class. http://www.digitalmars.com/d/changelog.htmlIs there any reason to not use "lazy" as a keyword to modify the expression, rather than the parameter? void foo(int delegate() dg) {...} void bar(int x,int y) { foo(lazy x+y); }
Aug 31 2006
Walter Bright wrote:Russ Lewis wrote:One of us is missing something. I'm not sure who :) Can you expand on your response here?Is there any reason to not use "lazy" as a keyword to modify the expression, rather than the parameter? void foo(int delegate() dg) {...} void bar(int x,int y) { foo(lazy x+y); }One reason is lazy arguments and non-lazy arguments cannot be passed to the same function.
Aug 31 2006
Russ Lewis wrote:Walter Bright wrote:foo(x + y); foo(lazy x + y); can't work, because foo needs to know which it is. Just like you can't have the same parameter be both in and out.Russ Lewis wrote:One of us is missing something. I'm not sure who :) Can you expand on your response here?Is there any reason to not use "lazy" as a keyword to modify the expression, rather than the parameter? void foo(int delegate() dg) {...} void bar(int x,int y) { foo(lazy x+y); }One reason is lazy arguments and non-lazy arguments cannot be passed to the same function.
Aug 31 2006
Walter Bright wrote:Russ Lewis wrote:Ah, I was wondering if that was what you meant. What I was suggesting was that the code lazy x+y would just be syntax sugar for delegate int() { return x+y; } So, to expand on the previous example: void foo(int delegate() dg) {...} void foo(int i) {...} void bar(int x,int y) { foo(lazy x+y); // calls delegate version foo(x+y); // calls int version }Walter Bright wrote:foo(x + y); foo(lazy x + y); can't work, because foo needs to know which it is. Just like you can't have the same parameter be both in and out.Russ Lewis wrote:One of us is missing something. I'm not sure who :) Can you expand on your response here?Is there any reason to not use "lazy" as a keyword to modify the expression, rather than the parameter? void foo(int delegate() dg) {...} void bar(int x,int y) { foo(lazy x+y); }One reason is lazy arguments and non-lazy arguments cannot be passed to the same function.
Aug 31 2006
Russ Lewis wrote:Ah, I was wondering if that was what you meant. What I was suggesting was that the code lazy x+y would just be syntax sugar for delegate int() { return x+y; } So, to expand on the previous example: void foo(int delegate() dg) {...} void foo(int i) {...} void bar(int x,int y) { foo(lazy x+y); // calls delegate version foo(x+y); // calls int version }Ok, that can work. But I don't see an application for it.
Aug 31 2006
Walter Bright wrote:Russ Lewis wrote:Heh, sems like I'm having a lot of trouble explaining myself here. I'm not trying to argue that overloading a function with both delegate and literal versions has a lot of value. I was just trying to say that the syntax I was proposing was not ambiguous. My argument is that it would be good to make laziness explicit in the caller, so that the caller of the code knows what he can expect.Ah, I was wondering if that was what you meant. What I was suggesting was that the code lazy x+y would just be syntax sugar for delegate int() { return x+y; } So, to expand on the previous example: void foo(int delegate() dg) {...} void foo(int i) {...} void bar(int x,int y) { foo(lazy x+y); // calls delegate version foo(x+y); // calls int version }Ok, that can work. But I don't see an application for it.
Sep 01 2006
Russ Lewis wrote:Walter Bright wrote:I believe this is the same as Derek's suggestion that in/out/inout be specified at the call side as well. SeanRuss Lewis wrote:Heh, sems like I'm having a lot of trouble explaining myself here. I'm not trying to argue that overloading a function with both delegate and literal versions has a lot of value. I was just trying to say that the syntax I was proposing was not ambiguous. My argument is that it would be good to make laziness explicit in the caller, so that the caller of the code knows what he can expect.Ah, I was wondering if that was what you meant. What I was suggesting was that the code lazy x+y would just be syntax sugar for delegate int() { return x+y; } So, to expand on the previous example: void foo(int delegate() dg) {...} void foo(int i) {...} void bar(int x,int y) { foo(lazy x+y); // calls delegate version foo(x+y); // calls int version }Ok, that can work. But I don't see an application for it.
Sep 01 2006
Sean Kelly wrote:Russ Lewis wrote:Ok.Walter Bright wrote:Russ Lewis wrote:Heh, sems like I'm having a lot of trouble explaining myself here. I'm not trying to argue that overloading a function with both delegate and literal versions has a lot of value. I was just trying to say that the syntax I was proposing was not ambiguous.Ah, I was wondering if that was what you meant. What I was suggesting was that the code lazy x+y would just be syntax sugar for delegate int() { return x+y; } So, to expand on the previous example: void foo(int delegate() dg) {...} void foo(int i) {...} void bar(int x,int y) { foo(lazy x+y); // calls delegate version foo(x+y); // calls int version }Ok, that can work. But I don't see an application for it.Yes, it would be the same. But I think the interface should be set by the definition, not the use. That's the usual practice with programming languages, and I've never seen it raised as an issue before.My argument is that it would be good to make laziness explicit in the caller, so that the caller of the code knows what he can expect.I believe this is the same as Derek's suggestion that in/out/inout be specified at the call side as well.
Sep 01 2006
On Fri, 01 Sep 2006 10:59:18 -0700, Walter Bright wrote:Yes we agree. But the purpose of this suggestion is not to 'set the definition' but to 'document the usage' of the definition. The purpose is to help both the compiler and human reader to validate the intention of the coder. The definition would still be set when declaring the function but if the compiler optionally allowed parameter storage class keywords at the point of invocation, you could help ensure that the coder is doing what she intended to do. It is a form of DbC.suggestion that in/out/inout be specified at the call side as well.Yes, it would be the same. But I think the interface should be set by the definition, not the use.That's the usual practice with programming languages, and I've never seen it raised as an issue before.So what? You are in the wonderful position of creating a useful and superb tool that can be very special. You have been a trail blazer and can continue to be one. -- Derek Parnell Melbourne, Australia "Down with mediocrity!"
Sep 01 2006
Derek Parnell wrote:On Fri, 01 Sep 2006 10:59:18 -0700, Walter Bright wrote:Setting the behavior at both the point of definition and point of use may result in fewer programming bugs, it does so at the risk of making modifications harder and annoying programmers.Yes we agree. But the purpose of this suggestion is not to 'set the definition' but to 'document the usage' of the definition. The purpose is to help both the compiler and human reader to validate the intention of the coder. The definition would still be set when declaring the function but if the compiler optionally allowed parameter storage class keywords at the point of invocation, you could help ensure that the coder is doing what she intended to do. It is a form of DbC.suggestion that in/out/inout be specified at the call side as well.Yes, it would be the same. But I think the interface should be set by the definition, not the use.If people don't like adding { } around the lazy expressions, they aren't going to like putting 'lazy' in front of them, either. Every time I've seen a feature like this, the complexity was at the definition point, *not* the use point.That's the usual practice with programming languages, and I've never seen it raised as an issue before.So what? You are in the wonderful position of creating a useful and superb tool that can be very special. You have been a trail blazer and can continue to be one.
Sep 02 2006
Walter Bright wrote:Derek Parnell wrote:Only it isn't "{ expression }" it is: "{ expression }()".On Fri, 01 Sep 2006 10:59:18 -0700, Walter Bright wrote:Setting the behavior at both the point of definition and point of use may result in fewer programming bugs, it does so at the risk of making modifications harder and annoying programmers.Yes we agree. But the purpose of this suggestion is not to 'set the definition' but to 'document the usage' of the definition. The purpose is to help both the compiler and human reader to validate the intention of the coder. The definition would still be set when declaring the function but if the compiler optionally allowed parameter storage class keywords at the point of invocation, you could help ensure that the coder is doing what she intended to do. It is a form of DbC.suggestion that in/out/inout be specified at the call side as well.Yes, it would be the same. But I think the interface should be set by the definition, not the use.If people don't like adding { } around the lazy expressions, they aren't going to like putting 'lazy' in front of them, either. Every time I've seen a feature like this, the complexity was at the definition point, *not* the use point.That's the usual practice with programming languages, and I've never seen it raised as an issue before.So what? You are in the wonderful position of creating a useful and superb tool that can be very special. You have been a trail blazer and can continue to be one.
Sep 02 2006
On Sat, 02 Sep 2006 12:22:45 -0700, Walter Bright wrote:Derek Parnell wrote:Why is it so hard to make my thoughts known to you? I did *not* talk about "Setting the behavior at both the points". *THE* behavior is set at the declaration just as it is now. A new *AND OPTIONAL* behavior can be set at point of use. This new behavior of the compiler would be such that if no parameter storage class is used for a parameter then the compiler does nothing new (the default case). If the coder chooses to include an 'in', 'inout', 'out' or 'lazy' at the point of use then the compiler could ensure that the coder's belief in how the declararion signature is can be tested by the compiler and alert the coder to any mismatch. This *will* result in fewer bugs at the 'cost' of making the code easier to understand when read by a human. How is it annoying? If the coder chooses to use this feature then obviously they are not annoyed by it. If a future coder does not like this DbC feature then they can remove it, just as they can remove all those annoying "in{} out{} body{}" phrases.On Fri, 01 Sep 2006 10:59:18 -0700, Walter Bright wrote:Setting the behavior at both the point of definition and point of use may result in fewer programming bugs, it does so at the risk of making modifications harder and annoying programmers.Yes we agree. But the purpose of this suggestion is not to 'set the definition' but to 'document the usage' of the definition. The purpose is to help both the compiler and human reader to validate the intention of the coder. The definition would still be set when declaring the function but if the compiler optionally allowed parameter storage class keywords at the point of invocation, you could help ensure that the coder is doing what she intended to do. It is a form of DbC.suggestion that in/out/inout be specified at the call side as well.Yes, it would be the same. But I think the interface should be set by the definition, not the use.You seem to be think that this would be a mandatory requirement of the language where as I'm consistantly talking about optional, coder chosen, stuff. For example, I willing choose to use syntax that is 'wordier' in order to increase the ability of other humans to understand what I was intending by my coding. If you or anyone else choose not to do that, then fine. -- Derek Parnell Melbourne, Australia "Down with mediocrity!"If people don't like adding { } around the lazy expressions, they aren't going to like putting 'lazy' in front of them, either. Every time I've seen a feature like this, the complexity was at the definition point, *not* the use point.That's the usual practice with programming languages, and I've never seen it raised as an issue before.So what? You are in the wonderful position of creating a useful and superb tool that can be very special. You have been a trail blazer and can continue to be one.
Sep 02 2006
Derek Parnell wrote:On Sat, 02 Sep 2006 12:22:45 -0700, Walter Bright wrote:I admit that I must have misunderstood as well, but looking at it this way I actually feel supportive. This actually strikes me as similar to our already-optional 'override' attribute, which asks the compiler to ensure that our method actually does override a parent method. And if it does not, the compiler issues a helpful error. "Yay! Now we have an alert for API changes!" I see the ability to *optionally* apply in/out/inout/lazy redundantly at the caller as living in the same usefulness category. It would alert to API changes, and would make it clear that the call expression is reliant on the callee exhibiting certain behavior. I think I would probably use this, albeit sparingly. -- Chris Nicholson-SaulsDerek Parnell wrote:Why is it so hard to make my thoughts known to you? I did *not* talk about "Setting the behavior at both the points". *THE* behavior is set at the declaration just as it is now. A new *AND OPTIONAL* behavior can be set at point of use. This new behavior of the compiler would be such that if no parameter storage class is used for a parameter then the compiler does nothing new (the default case). If the coder chooses to include an 'in', 'inout', 'out' or 'lazy' at the point of use then the compiler could ensure that the coder's belief in how the declararion signature is can be tested by the compiler and alert the coder to any mismatch. This *will* result in fewer bugs at the 'cost' of making the code easier to understand when read by a human. How is it annoying? If the coder chooses to use this feature then obviously they are not annoyed by it. If a future coder does not like this DbC feature then they can remove it, just as they can remove all those annoying "in{} out{} body{}" phrases.On Fri, 01 Sep 2006 10:59:18 -0700, Walter Bright wrote:Setting the behavior at both the point of definition and point of use may result in fewer programming bugs, it does so at the risk of making modifications harder and annoying programmers.Yes we agree. But the purpose of this suggestion is not to 'set the definition' but to 'document the usage' of the definition. The purpose is to help both the compiler and human reader to validate the intention of the coder. The definition would still be set when declaring the function but if the compiler optionally allowed parameter storage class keywords at the point of invocation, you could help ensure that the coder is doing what she intended to do. It is a form of DbC.suggestion that in/out/inout be specified at the call side as well.Yes, it would be the same. But I think the interface should be set by the definition, not the use.You seem to be think that this would be a mandatory requirement of the language where as I'm consistantly talking about optional, coder chosen, stuff. For example, I willing choose to use syntax that is 'wordier' in order to increase the ability of other humans to understand what I was intending by my coding. If you or anyone else choose not to do that, then fine.If people don't like adding { } around the lazy expressions, they aren't going to like putting 'lazy' in front of them, either. Every time I've seen a feature like this, the complexity was at the definition point, *not* the use point.That's the usual practice with programming languages, and I've never seen it raised as an issue before.So what? You are in the wonderful position of creating a useful and superb tool that can be very special. You have been a trail blazer and can continue to be one.
Sep 02 2006
Derek Parnell wrote:Why is it so hard to make my thoughts known to you? I did *not* talk about "Setting the behavior at both the points". *THE* behavior is set at the declaration just as it is now. A new *AND OPTIONAL* behavior can be set at point of use. This new behavior of the compiler would be such that if no parameter storage class is used for a parameter then the compiler does nothing new (the default case). If the coder chooses to include an 'in', 'inout', 'out' or 'lazy' at the point of use then the compiler could ensure that the coder's belief in how the declararion signature is can be tested by the compiler and alert the coder to any mismatch.This is a feature I would certainly be using. It can't do any harm but can have extremely positive effects.
Sep 03 2006
"Ivan Senji" <ivan.senji_REMOVE_ _THIS__gmail.com> wrote:Derek Parnell wrote:I'll chime in with a resounding "me, too". Having in, out, inout or lazy marked at the place of calling would help returning to the same code later.Why is it so hard to make my thoughts known to you? I did *not* talk about "Setting the behavior at both the points". *THE* behavior is set at the declaration just as it is now. A new *AND OPTIONAL* behavior can be set at point of use. This new behavior of the compiler would be such that if no parameter storage class is used for a parameter then the compiler does nothing new (the default case). If the coder chooses to include an 'in', 'inout', 'out' or 'lazy' at the point of use then the compiler could ensure that the coder's belief in how the declararion signature is can be tested by the compiler and alert the coder to any mismatch.This is a feature I would certainly be using. It can't do any harm but can have extremely positive effects.
Sep 03 2006
Derek Parnell wrote:I did *not* talk about "Setting the behavior at both the points". *THE* behavior is set at the declaration just as it is now. A new *AND OPTIONAL* behavior can be set at point of use. This new behavior of the compiler would be such that if no parameter storage class is used for a parameter then the compiler does nothing new (the default case). If the coder chooses to include an 'in', 'inout', 'out' or 'lazy' at the point of use then the compiler could ensure that the coder's belief in how the declararion signature is can be tested by the compiler and alert the coder to any mismatch.I misunderstood you. I didn't catch the optional bit. Sorry.
Sep 03 2006
Sean Kelly wrote:Russ Lewis wrote:Ok.Walter Bright wrote:Russ Lewis wrote:Heh, sems like I'm having a lot of trouble explaining myself here. I'm not trying to argue that overloading a function with both delegate and literal versions has a lot of value. I was just trying to say that the syntax I was proposing was not ambiguous.Ah, I was wondering if that was what you meant. What I was suggesting was that the code lazy x+y would just be syntax sugar for delegate int() { return x+y; } So, to expand on the previous example: void foo(int delegate() dg) {...} void foo(int i) {...} void bar(int x,int y) { foo(lazy x+y); // calls delegate version foo(x+y); // calls int version }Ok, that can work. But I don't see an application for it.Yes, it would be the same. But I think the interface should be set by the definition, not the use. That's the usual practice with programming languages, and I've never seen it raised as an issue before.My argument is that it would be good to make laziness explicit in the caller, so that the caller of the code knows what he can expect.I believe this is the same as Derek's suggestion that in/out/inout be specified at the call side as well.
Sep 01 2006
Walter Bright wrote:Yes, it would be the same. But I think the interface should be set by the definition, not the use. That's the usual practice with programming languages, and I've never seen it raised as an issue before.By that logic, shouldn't I be able to pass a delegate to a function with pass-by-value semantics and have the delegate get automagically called and converted into a value? Assuming that you'll answer "no," they why is it ok for it to work the other way around?
Sep 05 2006
Walter Bright wrote:The implicit conversion to delegate just broke too much. Instead, I'm trying out Tom S.'s suggestion of using a 'lazy' parameter storage class. http://www.digitalmars.com/d/changelog.htmlThanks Walter :) And thank you Oskar ! Now we can play with more IFTI :)
Aug 31 2006
"Walter Bright" <newshound digitalmars.com> wrote in message news:ed79pv$3fc$1 digitaldaemon.com...The implicit conversion to delegate just broke too much. Instead, I'm trying out Tom S.'s suggestion of using a 'lazy' parameter storage class. http://www.digitalmars.com/d/changelog.htmlAhh, thank you. I wasn't really keen on the lazy stuff. I'd probably never use it, but the new syntax is a lot nicer (and more explicit).
Aug 31 2006
Walter Bright wrote:The implicit conversion to delegate just broke too much. Instead, I'm trying out Tom S.'s suggestion of using a 'lazy' parameter storage class. http://www.digitalmars.com/d/changelog.htmlNice. I'll have to play with the improved IFTI support. Also, I've added "lazy" to the keyword index: http://www.prowiki.org/wiki4d/wiki.cgi?LanguageSpecification/KeywordIndex -- Kirk McDonald Pyd: Wrapping Python with D http://pyd.dsource.org
Aug 31 2006
"Kirk McDonald" <kirklin.mcdonald gmail.com> wrote in message news:ed7ddg$6r2$1 digitaldaemon.com...Nice. I'll have to play with the improved IFTI support.Hm. I missed this new feature. What does it include? There's not even a link to a conversation, and I don't remember any threads about this.
Aug 31 2006
Jarrett Billingsley wrote:"Kirk McDonald" <kirklin.mcdonald gmail.com> wrote in message news:ed7ddg$6r2$1 digitaldaemon.com...I'm referring to Oskar Linde's member template patches. -- Kirk McDonald Pyd: Wrapping Python with D http://pyd.dsource.orgNice. I'll have to play with the improved IFTI support.Hm. I missed this new feature. What does it include? There's not even a link to a conversation, and I don't remember any threads about this.
Aug 31 2006
Jarrett Billingsley wrote:"Kirk McDonald" <kirklin.mcdonald gmail.com> wrote in message news:ed7ddg$6r2$1 digitaldaemon.com...It is really just a small patch that enables implicit function template instantiation for member function and operator templates. It should work identically to how IFTI works for free functions. It should open up quite a few door. Here is a quick demo I hacked together of how compile time dimensionality checking can be implemented: http://www.csc.kth.se/~ol/physical.d /OskarNice. I'll have to play with the improved IFTI support.Hm. I missed this new feature. What does it include? There's not even a link to a conversation, and I don't remember any threads about this.
Aug 31 2006
Oskar Linde wrote:Jarrett Billingsley wrote:Very, very nice!"Kirk McDonald" <kirklin.mcdonald gmail.com> wrote in message news:ed7ddg$6r2$1 digitaldaemon.com...It is really just a small patch that enables implicit function template instantiation for member function and operator templates. It should work identically to how IFTI works for free functions. It should open up quite a few door. Here is a quick demo I hacked together of how compile time dimensionality checking can be implemented: http://www.csc.kth.se/~ol/physical.dNice. I'll have to play with the improved IFTI support.Hm. I missed this new feature. What does it include? There's not even a link to a conversation, and I don't remember any threads about this./Oskar
Aug 31 2006
"Oskar Linde" <olREM OVEnada.kth.se> wrote in message news:ed7i39$bke$1 digitaldaemon.com...It is really just a small patch that enables implicit function template instantiation for member function and operator templates. It should work identically to how IFTI works for free functions.Ah!! This exactly solves the problem I was (am!) having with needing several very similar member methods which only differ by the parameter type. Thanks!It should open up quite a few door. Here is a quick demo I hacked together of how compile time dimensionality checking can be implemented: http://www.csc.kth.se/~ol/physical.dThat is really, really cool :)
Aug 31 2006
Oskar Linde wrote:Jarrett Billingsley wrote:Hot, Dog!!! This is a project I was hoping to get to a LONG time ago. (The d code side, not the getting-D-to-do-this side) Best I came up with was a Runtime version. http://www.webpages.uidaho.edu/~shro8822/unit.d Mind if I try to graft in a "few" ;) more units and some unittest?"Kirk McDonald" <kirklin.mcdonald gmail.com> wrote in message news:ed7ddg$6r2$1 digitaldaemon.com...It is really just a small patch that enables implicit function template instantiation for member function and operator templates. It should work identically to how IFTI works for free functions. It should open up quite a few door. Here is a quick demo I hacked together of how compile time dimensionality checking can be implemented: http://www.csc.kth.se/~ol/physical.d /OskarNice. I'll have to play with the improved IFTI support.Hm. I missed this new feature. What does it include? There's not even a link to a conversation, and I don't remember any threads about this.
Aug 31 2006
BCS wrote:Oskar Linde wrote:Certainly not. Feel free to go ahead. :) But as I said, this is just a quick hack. Some improvements would be a generic Quantity supporting an arbitrary number of dimensions and rational exponents. /OskarJarrett Billingsley wrote:Hot, Dog!!! This is a project I was hoping to get to a LONG time ago. (The d code side, not the getting-D-to-do-this side) Best I came up with was a Runtime version. http://www.webpages.uidaho.edu/~shro8822/unit.d Mind if I try to graft in a "few" ;) more units and some unittest?"Kirk McDonald" <kirklin.mcdonald gmail.com> wrote in message news:ed7ddg$6r2$1 digitaldaemon.com...It is really just a small patch that enables implicit function template instantiation for member function and operator templates. It should work identically to how IFTI works for free functions. It should open up quite a few door. Here is a quick demo I hacked together of how compile time dimensionality checking can be implemented: http://www.csc.kth.se/~ol/physical.d /OskarNice. I'll have to play with the improved IFTI support.Hm. I missed this new feature. What does it include? There's not even a link to a conversation, and I don't remember any threads about this.
Sep 02 2006
Oskar Linde wrote:BCS wrote:I think 7d is actually more than is needed (But I'm no expert). Mine only used 5d (mole is unit less and candle is power/area). Also I can't ever remember ending up with non integer powers on a dimension. As it stands, the template provides a lot of functionality. I think that the next thing to be added should be a set of function (sqrt, pow, etc). Any thought on how to get them to work without having them be wrappers?Hot, Dog!!! This is a project I was hoping to get to a LONG time ago. (The d code side, not the getting-D-to-do-this side) Best I came up with was a Runtime version. http://www.webpages.uidaho.edu/~shro8822/unit.d Mind if I try to graft in a "few" ;) more units and some unittest?Certainly not. Feel free to go ahead. :) But as I said, this is just a quick hack. Some improvements would be a generic Quantity supporting an arbitrary number of dimensions and rational exponents. /Oskar
Sep 02 2006
On Fri, 01 Sep 2006 00:50:48 +0200, Oskar Linde wrote:Jarrett Billingsley wrote:In your example code you have ... // One wishes the .toString was unnecessary... writefln("A current of ",i.toString); writefln("through a voltage of ",v.toString); writefln("requires a resistance of ",r.toString); writefln("and produces ",w.toString," of heat."); writefln("Total energy used in ",ti.toString," is ",e.toString); but could you not also use ... writefln("A current of %s",i); writefln("through a voltage of %s",v); writefln("requires a resistance of %s",r); writefln("and produces %s of heat.",w); writefln("Total energy used in %s is %s",ti,e); -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocrity!" 1/09/2006 12:02:44 PM"Kirk McDonald" <kirklin.mcdonald gmail.com> wrote in message news:ed7ddg$6r2$1 digitaldaemon.com...It is really just a small patch that enables implicit function template instantiation for member function and operator templates. It should work identically to how IFTI works for free functions. It should open up quite a few door. Here is a quick demo I hacked together of how compile time dimensionality checking can be implemented: http://www.csc.kth.se/~ol/physical.d /OskarNice. I'll have to play with the improved IFTI support.Hm. I missed this new feature. What does it include? There's not even a link to a conversation, and I don't remember any threads about this.
Aug 31 2006
Derek Parnell wrote:On Fri, 01 Sep 2006 00:50:48 +0200, Oskar Linde wrote:Nope, since it only works for classes, and his SiQuantity is a structJarrett Billingsley wrote:In your example code you have ... // One wishes the .toString was unnecessary... writefln("A current of ",i.toString); writefln("through a voltage of ",v.toString); writefln("requires a resistance of ",r.toString); writefln("and produces ",w.toString," of heat."); writefln("Total energy used in ",ti.toString," is ",e.toString); but could you not also use ... writefln("A current of %s",i); writefln("through a voltage of %s",v); writefln("requires a resistance of %s",r); writefln("and produces %s of heat.",w); writefln("Total energy used in %s is %s",ti,e);"Kirk McDonald" <kirklin.mcdonald gmail.com> wrote in message news:ed7ddg$6r2$1 digitaldaemon.com...It is really just a small patch that enables implicit function template instantiation for member function and operator templates. It should work identically to how IFTI works for free functions. It should open up quite a few door. Here is a quick demo I hacked together of how compile time dimensionality checking can be implemented: http://www.csc.kth.se/~ol/physical.d /OskarNice. I'll have to play with the improved IFTI support.Hm. I missed this new feature. What does it include? There's not even a link to a conversation, and I don't remember any threads about this.
Aug 31 2006
On Fri, 01 Sep 2006 04:08:28 +0100, Tom S wrote:Derek Parnell wrote:Damn! I didn't know that. What's the rationale for such a seemingly arbitrary restriction? -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocrity!" 1/09/2006 1:17:19 PMOn Fri, 01 Sep 2006 00:50:48 +0200, Oskar Linde wrote:Nope, since it only works for classes, and his SiQuantity is a structJarrett Billingsley wrote:In your example code you have ... // One wishes the .toString was unnecessary... writefln("A current of ",i.toString); writefln("through a voltage of ",v.toString); writefln("requires a resistance of ",r.toString); writefln("and produces ",w.toString," of heat."); writefln("Total energy used in ",ti.toString," is ",e.toString); but could you not also use ... writefln("A current of %s",i); writefln("through a voltage of %s",v); writefln("requires a resistance of %s",r); writefln("and produces %s of heat.",w); writefln("Total energy used in %s is %s",ti,e);"Kirk McDonald" <kirklin.mcdonald gmail.com> wrote in message news:ed7ddg$6r2$1 digitaldaemon.com...It is really just a small patch that enables implicit function template instantiation for member function and operator templates. It should work identically to how IFTI works for free functions. It should open up quite a few door. Here is a quick demo I hacked together of how compile time dimensionality checking can be implemented: http://www.csc.kth.se/~ol/physical.d /OskarNice. I'll have to play with the improved IFTI support.Hm. I missed this new feature. What does it include? There's not even a link to a conversation, and I don't remember any threads about this.
Aug 31 2006
Derek Parnell wrote:Damn! I didn't know that. What's the rationale for such a seemingly arbitrary restriction?No virtual functions for structs!
Aug 31 2006
On Thu, 31 Aug 2006 20:32:01 -0700, Walter Bright wrote:Derek Parnell wrote:Ok, that meant nothing to me until I translated it from the OO jargon. Here is my attempt at converting Walter's answer into human speech ;-) The 'format' function examines each parameter supplied to it in order to convert it into some form of string. When it comes to a class object, it casts the object instance to 'Object' and then calls Object.toString(), which through the magic of 'virtual functions' actually gets around to calling the parameter's own toString() method if it exists. 'virtual functions' is the mechanism in which derived classes can have their methods called via reference to their parent class. Now structs are not derived from anything and thus there cannot be a generic toString() method in a struct parent. So the 'format' function doesn't know which struct toString() to call and it throws the exception instead. I guess that when D eventually gets runtime reflection we will be able to improve 'format' to check if the struct parameter passed to it has a toString method and thus call it. -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocrity!" 1/09/2006 2:29:34 PMDamn! I didn't know that. What's the rationale for such a seemingly arbitrary restriction?No virtual functions for structs!
Aug 31 2006
Derek Parnell wrote:I guess that when D eventually gets runtime reflection we will be able to improve 'format' to check if the struct parameter passed to it has a toString method and thus call it.It could also be done with variadic templates. -- Kirk McDonald Pyd: Wrapping Python with D http://pyd.dsource.org
Aug 31 2006
Derek Parnell wrote:On Thu, 31 Aug 2006 20:32:01 -0700, Walter Bright wrote:Another alternative is a syntax using the concatenation operator: writefln("through a voltage of" ~ v); This can be done already with overloading of opCat_r and opCat, but it's way less than ideal since it has to be done for every new type. Or D could be changed so that '~' itself would try to call toString() if it existed. Yet another alternative is for any type that has a toString() member function to be implicitly castable to string (aka "char[]"). Then writefln would be declared as a typesafe variadic function of (string[] strs ...). It would also be necessary for implicit casting to work with typesafe variadic function calls, which seems it doesn't (I wonder if that's by design?). And it would be necessary for primitives to have toString "member functions" (it's unusual, but I don't see any problem with that. Primitives already have properties for example). Usage would be: writeln("X is ", 1.2345 ); Note we would lose the formatting capabilities(no "f"). To do formatting we could do for example: writeln("X is ", (1.2345).toString("%1.2d") ); Just some wacky ideas. :P -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#DDerek Parnell wrote:Ok, that meant nothing to me until I translated it from the OO jargon. Here is my attempt at converting Walter's answer into human speech ;-) The 'format' function examines each parameter supplied to it in order to convert it into some form of string. When it comes to a class object, it casts the object instance to 'Object' and then calls Object.toString(), which through the magic of 'virtual functions' actually gets around to calling the parameter's own toString() method if it exists. 'virtual functions' is the mechanism in which derived classes can have their methods called via reference to their parent class. Now structs are not derived from anything and thus there cannot be a generic toString() method in a struct parent. So the 'format' function doesn't know which struct toString() to call and it throws the exception instead. I guess that when D eventually gets runtime reflection we will be able to improve 'format' to check if the struct parameter passed to it has a toString method and thus call it.Damn! I didn't know that. What's the rationale for such a seemingly arbitrary restriction?No virtual functions for structs!
Sep 01 2006
Walter Bright wrote:Derek Parnell wrote:If one considered toString() important enough it could be added to the TypeInfo for structs, just like toHash, opEquals and opCmp are today. It would make certain sense to support all the methods of Object in this way. /OskarDamn! I didn't know that. What's the rationale for such a seemingly arbitrary restriction?No virtual functions for structs!
Sep 02 2006
Oskar Linde wrote:Walter Bright wrote:That makes sense.Derek Parnell wrote:If one considered toString() important enough it could be added to the TypeInfo for structs, just like toHash, opEquals and opCmp are today. It would make certain sense to support all the methods of Object in this way.Damn! I didn't know that. What's the rationale for such a seemingly arbitrary restriction?No virtual functions for structs!
Sep 02 2006
Jarrett Billingsley wrote:"Kirk McDonald" <kirklin.mcdonald gmail.com> wrote in message news:ed7ddg$6r2$1 digitaldaemon.com...Oskar had emailed me the patches.Nice. I'll have to play with the improved IFTI support.Hm. I missed this new feature. What does it include? There's not even a link to a conversation, and I don't remember any threads about this.
Aug 31 2006
Walter Bright wrote:The implicit conversion to delegate just broke too much. Instead, I'm trying out Tom S.'s suggestion of using a 'lazy' parameter storage class. http://www.digitalmars.com/d/changelog.htmlHmm, I am afraid I have to admit I'm a little bit puzzled by this lazy thing. Let's say we have: void dotimes(int count, lazy void exp) { for (int i = 0; i < count; i++) { exp(); } } and I can call it like this: int x; dotimes(5, x++); And it works as expected and x end up being 5. But shouldn't I also be allowed to pass in a delegate of the appropriate type dotimes(5, {writefln(x); x++;}); A funny thing happens: nothing. The loop in dotimes does get executed 5 times but delegate passed in isn't called?
Sep 01 2006
Ivan Senji wrote:Walter Bright wrote:This is because anonymous delegates are themselves expressions, and so your 'exp()' just evaluates to the delegate itself -- it does not invoke it. However, to achieve what you were trying to do, just make use of parentheses and the comma operator. Also, you may provide an overload that takes a lazy delegate. Here is my own test program, which worked without issue: -- Chris Nicholson-SaulsThe implicit conversion to delegate just broke too much. Instead, I'm trying out Tom S.'s suggestion of using a 'lazy' parameter storage class. http://www.digitalmars.com/d/changelog.htmlHmm, I am afraid I have to admit I'm a little bit puzzled by this lazy thing. Let's say we have: void dotimes(int count, lazy void exp) { for (int i = 0; i < count; i++) { exp(); } } and I can call it like this: int x; dotimes(5, x++); And it works as expected and x end up being 5. But shouldn't I also be allowed to pass in a delegate of the appropriate type dotimes(5, {writefln(x); x++;}); A funny thing happens: nothing. The loop in dotimes does get executed 5 times but delegate passed in isn't called?
Sep 01 2006
Chris Nicholson-Sauls wrote:Ivan Senji wrote:Hmm, there is something about this lazy stuff that is troubling me and I'm not exactly sure what it is and if I can explain it: so it is x++ vs {writefln(x); x++;} The first one is an expression that looks like it is executed at call site but it isn't because that parameter is declared to be lazy. It is executed inside dotimes. That is ok. The second is a block of statements, actually it is a void delegate. It isn't executed at call site so it also will not be executed in dotimes. To make it be executed in dotimes I have to make it into something that looks like it is being executed: for example: {writefln(x); x++;}() And this is when thing begin to suck (unless I am missing something?). So if I had dotimes(5, x++); and now if I want it to do 5 times somethin a bit more than just x++ i cannot just write: dotimes(5, {writefln(); x++;}); And now a completly different function is called (one taking void delegate() as argument), to get it to call the lazy function I have to change to type from void delegate() to void by pretending to be calling the delegate. So is there a point to having lazy, I could only have written dotimes that takes void delegate() an write this: dotimes(5, {x++;}); and dotimes(5, {writefln(); x++;} ); vs dotimes(5, x++); and dotimes(5, {writefln(); x++;}() ); And now (while writing) I finally figure out what was troubling me: each of these approaches has a pretty case and an ugly case, the two pretty cases being: dotimes(5, x++); and dotimes(5, {writefln(); x++;} ); But to get that to work 2 different methods are needed. Don't feel the need to reply to this incoherent post :D , it is just some of my thoughts about lazy. Although now I understand what is happening and why, this is still troubling me.Walter Bright wrote:This is because anonymous delegates are themselves expressions, and so your 'exp()' just evaluates to the delegate itself -- it does not invoke it. However, to achieve what you were trying to do, just make use of parentheses and the comma operator. Also, you may provide an overload that takes a lazy delegate. Here is my own test program, which worked without issue:The implicit conversion to delegate just broke too much. Instead, I'm trying out Tom S.'s suggestion of using a 'lazy' parameter storage class. http://www.digitalmars.com/d/changelog.htmlHmm, I am afraid I have to admit I'm a little bit puzzled by this lazy thing. Let's say we have: void dotimes(int count, lazy void exp) { for (int i = 0; i < count; i++) { exp(); } } and I can call it like this: int x; dotimes(5, x++); And it works as expected and x end up being 5. But shouldn't I also be allowed to pass in a delegate of the appropriate type dotimes(5, {writefln(x); x++;}); A funny thing happens: nothing. The loop in dotimes does get executed 5 times but delegate passed in isn't called?
Sep 01 2006
Ivan Senji wrote:Chris Nicholson-Sauls wrote:Actually I just figured out i can have both pretty cases :) Hooray, just need to change dotimes to: void dotimes(int count, void delegate()[] exp...) { for (int i = 0; i < count; i++) { foreach(dg; exp) dg(); } } With the added benefit of being able to do the craziest things: dotimes(5, f++, writefln(f), f*=2); being equal to: dotimes(5, {f++; writefln(f); f*=2;}); This isn't bad afterall, but I've lost lazy on the way. (Note to self: figure out where to use lazy)Ivan Senji wrote:Hmm, there is something about this lazy stuff that is troubling me and I'm not exactly sure what it is and if I can explain it: so it is x++ vs {writefln(x); x++;} The first one is an expression that looks like it is executed at call site but it isn't because that parameter is declared to be lazy. It is executed inside dotimes. That is ok. The second is a block of statements, actually it is a void delegate. It isn't executed at call site so it also will not be executed in dotimes. To make it be executed in dotimes I have to make it into something that looks like it is being executed: for example: {writefln(x); x++;}() And this is when thing begin to suck (unless I am missing something?). So if I had dotimes(5, x++); and now if I want it to do 5 times somethin a bit more than just x++ i cannot just write: dotimes(5, {writefln(); x++;}); And now a completly different function is called (one taking void delegate() as argument), to get it to call the lazy function I have to change to type from void delegate() to void by pretending to be calling the delegate. So is there a point to having lazy, I could only have written dotimes that takes void delegate() an write this: dotimes(5, {x++;}); and dotimes(5, {writefln(); x++;} ); vs dotimes(5, x++); and dotimes(5, {writefln(); x++;}() ); And now (while writing) I finally figure out what was troubling me: each of these approaches has a pretty case and an ugly case, the two pretty cases being: dotimes(5, x++); and dotimes(5, {writefln(); x++;} );Walter Bright wrote:This is because anonymous delegates are themselves expressions, and so your 'exp()' just evaluates to the delegate itself -- it does not invoke it. However, to achieve what you were trying to do, just make use of parentheses and the comma operator. Also, you may provide an overload that takes a lazy delegate. Here is my own test program, which worked without issue:The implicit conversion to delegate just broke too much. Instead, I'm trying out Tom S.'s suggestion of using a 'lazy' parameter storage class. http://www.digitalmars.com/d/changelog.htmlHmm, I am afraid I have to admit I'm a little bit puzzled by this lazy thing. Let's say we have: void dotimes(int count, lazy void exp) { for (int i = 0; i < count; i++) { exp(); } } and I can call it like this: int x; dotimes(5, x++); And it works as expected and x end up being 5. But shouldn't I also be allowed to pass in a delegate of the appropriate type dotimes(5, {writefln(x); x++;}); A funny thing happens: nothing. The loop in dotimes does get executed 5 times but delegate passed in isn't called?
Sep 01 2006
Ivan Senji wrote:Chris Nicholson-Sauls wrote:It may be that delegates should be implicitly convertible to lazy expressions with the same signature. Thus: void fn( lazy int x ); Should accept both: fn( i++ ); and fn( { return i++; } ); Currently, they only accept the former. SeanIvan Senji wrote:Hmm, there is something about this lazy stuff that is troubling me and I'm not exactly sure what it is and if I can explain it: so it is x++ vs {writefln(x); x++;} The first one is an expression that looks like it is executed at call site but it isn't because that parameter is declared to be lazy. It is executed inside dotimes. That is ok. The second is a block of statements, actually it is a void delegate. It isn't executed at call site so it also will not be executed in dotimes. To make it be executed in dotimes I have to make it into something that looks like it is being executed: for example: {writefln(x); x++;}() And this is when thing begin to suck (unless I am missing something?). So if I had dotimes(5, x++); and now if I want it to do 5 times somethin a bit more than just x++ i cannot just write: dotimes(5, {writefln(); x++;}); And now a completly different function is called (one taking void delegate() as argument), to get it to call the lazy function I have to change to type from void delegate() to void by pretending to be calling the delegate. So is there a point to having lazy, I could only have written dotimes that takes void delegate() an write this: dotimes(5, {x++;}); and dotimes(5, {writefln(); x++;} ); vs dotimes(5, x++); and dotimes(5, {writefln(); x++;}() ); And now (while writing) I finally figure out what was troubling me: each of these approaches has a pretty case and an ugly case, the two pretty cases being: dotimes(5, x++); and dotimes(5, {writefln(); x++;} ); But to get that to work 2 different methods are needed.Walter Bright wrote:This is because anonymous delegates are themselves expressions, and so your 'exp()' just evaluates to the delegate itself -- it does not invoke it. However, to achieve what you were trying to do, just make use of parentheses and the comma operator. Also, you may provide an overload that takes a lazy delegate. Here is my own test program, which worked without issue:The implicit conversion to delegate just broke too much. Instead, I'm trying out Tom S.'s suggestion of using a 'lazy' parameter storage class. http://www.digitalmars.com/d/changelog.htmlHmm, I am afraid I have to admit I'm a little bit puzzled by this lazy thing. Let's say we have: void dotimes(int count, lazy void exp) { for (int i = 0; i < count; i++) { exp(); } } and I can call it like this: int x; dotimes(5, x++); And it works as expected and x end up being 5. But shouldn't I also be allowed to pass in a delegate of the appropriate type dotimes(5, {writefln(x); x++;}); A funny thing happens: nothing. The loop in dotimes does get executed 5 times but delegate passed in isn't called?
Sep 01 2006
Sean Kelly wrote:Ivan Senji wrote:Maybe, that is what I expected it would do in the first place (it's too late to think now :))Chris Nicholson-Sauls wrote:It may be that delegates should be implicitly convertible to lazy expressions with the same signature. Thus:Ivan Senji wrote:Hmm, there is something about this lazy stuff that is troubling me and I'm not exactly sure what it is and if I can explain it: so it is x++ vs {writefln(x); x++;} The first one is an expression that looks like it is executed at call site but it isn't because that parameter is declared to be lazy. It is executed inside dotimes. That is ok. The second is a block of statements, actually it is a void delegate. It isn't executed at call site so it also will not be executed in dotimes. To make it be executed in dotimes I have to make it into something that looks like it is being executed: for example: {writefln(x); x++;}() And this is when thing begin to suck (unless I am missing something?). So if I had dotimes(5, x++); and now if I want it to do 5 times somethin a bit more than just x++ i cannot just write: dotimes(5, {writefln(); x++;}); And now a completly different function is called (one taking void delegate() as argument), to get it to call the lazy function I have to change to type from void delegate() to void by pretending to be calling the delegate. So is there a point to having lazy, I could only have written dotimes that takes void delegate() an write this: dotimes(5, {x++;}); and dotimes(5, {writefln(); x++;} ); vs dotimes(5, x++); and dotimes(5, {writefln(); x++;}() ); And now (while writing) I finally figure out what was troubling me: each of these approaches has a pretty case and an ugly case, the two pretty cases being: dotimes(5, x++); and dotimes(5, {writefln(); x++;} ); But to get that to work 2 different methods are needed.Walter Bright wrote:This is because anonymous delegates are themselves expressions, and so your 'exp()' just evaluates to the delegate itself -- it does not invoke it. However, to achieve what you were trying to do, just make use of parentheses and the comma operator. Also, you may provide an overload that takes a lazy delegate. Here is my own test program, which worked without issue:The implicit conversion to delegate just broke too much. Instead, I'm trying out Tom S.'s suggestion of using a 'lazy' parameter storage class. http://www.digitalmars.com/d/changelog.htmlHmm, I am afraid I have to admit I'm a little bit puzzled by this lazy thing. Let's say we have: void dotimes(int count, lazy void exp) { for (int i = 0; i < count; i++) { exp(); } } and I can call it like this: int x; dotimes(5, x++); And it works as expected and x end up being 5. But shouldn't I also be allowed to pass in a delegate of the appropriate type dotimes(5, {writefln(x); x++;}); A funny thing happens: nothing. The loop in dotimes does get executed 5 times but delegate passed in isn't called?void fn( lazy int x ); Should accept both: fn( i++ ); and fn( { return i++; } ); Currently, they only accept the former.Except in a strange (but documented) feature that variadic arguments are implicitly converted to delegates (used in my reply to myself).
Sep 01 2006
Ivan Senji wrote:Chris Nicholson-Sauls wrote:Or... just put parentheses around it instead of braces, and use commas instead of semicolons, like I did. That works without having to do any extra work at all. (Although your typesafe variadic delegate parameter trick is pretty interesting, too.) dotimes(5, x++); dotimes(5, (writefln(x), x++)); -- Chris Nicholson-SaulsIvan Senji wrote:Hmm, there is something about this lazy stuff that is troubling me and I'm not exactly sure what it is and if I can explain it: so it is x++ vs {writefln(x); x++;} The first one is an expression that looks like it is executed at call site but it isn't because that parameter is declared to be lazy. It is executed inside dotimes. That is ok. The second is a block of statements, actually it is a void delegate. It isn't executed at call site so it also will not be executed in dotimes. To make it be executed in dotimes I have to make it into something that looks like it is being executed: for example: {writefln(x); x++;}() And this is when thing begin to suck (unless I am missing something?). So if I had dotimes(5, x++); and now if I want it to do 5 times somethin a bit more than just x++ i cannot just write: dotimes(5, {writefln(); x++;}); And now a completly different function is called (one taking void delegate() as argument), to get it to call the lazy function I have to change to type from void delegate() to void by pretending to be calling the delegate. So is there a point to having lazy, I could only have written dotimes that takes void delegate() an write this: dotimes(5, {x++;}); and dotimes(5, {writefln(); x++;} ); vs dotimes(5, x++); and dotimes(5, {writefln(); x++;}() ); And now (while writing) I finally figure out what was troubling me: each of these approaches has a pretty case and an ugly case, the two pretty cases being: dotimes(5, x++); and dotimes(5, {writefln(); x++;} ); But to get that to work 2 different methods are needed. Don't feel the need to reply to this incoherent post :D , it is just some of my thoughts about lazy. Although now I understand what is happening and why, this is still troubling me.Walter Bright wrote:This is because anonymous delegates are themselves expressions, and so your 'exp()' just evaluates to the delegate itself -- it does not invoke it. However, to achieve what you were trying to do, just make use of parentheses and the comma operator. Also, you may provide an overload that takes a lazy delegate. Here is my own test program, which worked without issue:The implicit conversion to delegate just broke too much. Instead, I'm trying out Tom S.'s suggestion of using a 'lazy' parameter storage class. http://www.digitalmars.com/d/changelog.htmlHmm, I am afraid I have to admit I'm a little bit puzzled by this lazy thing. Let's say we have: void dotimes(int count, lazy void exp) { for (int i = 0; i < count; i++) { exp(); } } and I can call it like this: int x; dotimes(5, x++); And it works as expected and x end up being 5. But shouldn't I also be allowed to pass in a delegate of the appropriate type dotimes(5, {writefln(x); x++;}); A funny thing happens: nothing. The loop in dotimes does get executed 5 times but delegate passed in isn't called?
Sep 02 2006
So there is IFTI for member functions functions now...I'm a little late, but thank you and Oskar Linde!! This is amazing. Also the lazy thing, it's great. Walter Bright wrote:The implicit conversion to delegate just broke too much. Instead, I'm trying out Tom S.'s suggestion of using a 'lazy' parameter storage class. http://www.digitalmars.com/d/changelog.html
Sep 03 2006